forked from MagicBane/Server
new maintenance completed
This commit is contained in:
@@ -116,20 +116,52 @@ public enum MaintenanceManager {
|
||||
}
|
||||
|
||||
//handle r8 ToL maintenance here after the fact
|
||||
HashMap<Integer,Integer> updatedValues = new HashMap<>();
|
||||
Boolean success = true;
|
||||
for(Integer ibId : maintCosts.keySet()){
|
||||
if (warehouse != null) {
|
||||
int resourceCount = warehouse.getResources().get(ItemBase.getItemBase(ibId));
|
||||
if(resourceCount < maintCosts.get(ibId))
|
||||
success = false;
|
||||
boolean success = true;
|
||||
|
||||
int strongboxGold = tol.getStrongboxValue();
|
||||
int maintenanceGoldRequired = maintCosts.get(7);
|
||||
|
||||
//remove any gold from strongbox to start paying maintenance
|
||||
if(tol.getStrongboxValue() > 0){
|
||||
if(tol.getStrongboxValue() > maintenanceGoldRequired){
|
||||
strongboxGold -= maintenanceGoldRequired;
|
||||
maintCosts.put(7,0);
|
||||
}else{
|
||||
success = false;
|
||||
maintCosts.put(7,maintCosts.get(7) - strongboxGold);
|
||||
strongboxGold = 0;
|
||||
}
|
||||
}
|
||||
if(success = true){
|
||||
//determined there is enough of each resourceType to withdraw maintenance
|
||||
for(Integer ibId : maintCosts.keySet()){
|
||||
if (warehouse != null) {
|
||||
if(warehouse.getResources().get(ItemBase.getItemBase(ibId)) == null)
|
||||
success = false; //this resource is not in the warehouse, failed to pay maintenance
|
||||
|
||||
int resourceCount = warehouse.getResources().get(ItemBase.getItemBase(ibId));
|
||||
if(resourceCount < maintCosts.get(ibId))
|
||||
success = false; //not enough of this type to pay maintenance, maintenance failed to pay
|
||||
}else{
|
||||
success = false; //warehouse is null, cannot pay resource maintenance
|
||||
}
|
||||
}
|
||||
if(success == true){
|
||||
//determined there is enough of each resourceType to withdraw maintenance
|
||||
tol.setStrongboxValue(strongboxGold);
|
||||
int goldLeft = warehouse.getResources().get(ItemBase.getItemBase(7)) - maintCosts.get(7);
|
||||
int galvorLeft = warehouse.getResources().get(ItemBase.getItemBase(1580017)) - maintCosts.get(1580017);
|
||||
int lumberLeft = warehouse.getResources().get(ItemBase.getItemBase(1580004)) - maintCosts.get(1580004);
|
||||
int stoneLeft = warehouse.getResources().get(ItemBase.getItemBase(1580000)) - maintCosts.get(1580000);
|
||||
int wormwoodLeft = warehouse.getResources().get(ItemBase.getItemBase(1580018)) - maintCosts.get(1580018);
|
||||
DbManager.WarehouseQueries.updateGold(warehouse, goldLeft);
|
||||
DbManager.WarehouseQueries.updateStone(warehouse, stoneLeft);
|
||||
DbManager.WarehouseQueries.updateLumber(warehouse, lumberLeft);
|
||||
DbManager.WarehouseQueries.updateGalvor(warehouse, galvorLeft);
|
||||
DbManager.WarehouseQueries.updateWormwood(warehouse, wormwoodLeft);
|
||||
warehouse.getResources().put(ItemBase.getItemBase(7), goldLeft);
|
||||
warehouse.getResources().put(ItemBase.getItemBase(1580017), galvorLeft);
|
||||
warehouse.getResources().put(ItemBase.getItemBase(1580004), lumberLeft);
|
||||
warehouse.getResources().put(ItemBase.getItemBase(1580000), stoneLeft);
|
||||
warehouse.getResources().put(ItemBase.getItemBase(1580018), wormwoodLeft);
|
||||
setMaintDateTime(tol, tol.maintDateTime.plusDays(7)); //maintenance paid, set next maintenance date for 1 week from today
|
||||
}else{
|
||||
HandleMaintenanceDerank(tol);//handle derank or potential destruction of the city
|
||||
}
|
||||
@@ -138,6 +170,17 @@ public enum MaintenanceManager {
|
||||
|
||||
public static void HandleMaintenanceDerank(Building tol){
|
||||
setMaintDateTime(tol, tol.maintDateTime.plusDays(1)); //failed to pay maintenance, set next date for tomorrow
|
||||
if(tol.getRank() == 1)
|
||||
destroyAllCityAssets(tol.getCity());
|
||||
|
||||
tol.destroyOrDerank(null);
|
||||
}
|
||||
public static void destroyAllCityAssets(City city){
|
||||
if(city == null)
|
||||
Logger.error("Maintenance Failed To Find City To Destroy");
|
||||
for(Building building : city.getParent().zoneBuildingSet){
|
||||
building.setRank(-1);
|
||||
}
|
||||
city.getParent().zoneBuildingSet.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user