Browse Source

new maintenance completed

lakebane-master
FatBoy-DOTC 7 months ago
parent
commit
7fb5ccf4f1
  1. 55
      src/engine/gameManager/MaintenanceManager.java

55
src/engine/gameManager/MaintenanceManager.java

@ -116,20 +116,52 @@ public enum MaintenanceManager {
} }
//handle r8 ToL maintenance here after the fact //handle r8 ToL maintenance here after the fact
HashMap<Integer,Integer> updatedValues = new HashMap<>(); boolean success = true;
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{
maintCosts.put(7,maintCosts.get(7) - strongboxGold);
strongboxGold = 0;
}
}
for(Integer ibId : maintCosts.keySet()){ for(Integer ibId : maintCosts.keySet()){
if (warehouse != null) { 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)); int resourceCount = warehouse.getResources().get(ItemBase.getItemBase(ibId));
if(resourceCount < maintCosts.get(ibId)) if(resourceCount < maintCosts.get(ibId))
success = false; success = false; //not enough of this type to pay maintenance, maintenance failed to pay
}else{ }else{
success = false; success = false; //warehouse is null, cannot pay resource maintenance
} }
} }
if(success = true){ if(success == true){
//determined there is enough of each resourceType to withdraw maintenance //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{ }else{
HandleMaintenanceDerank(tol);//handle derank or potential destruction of the city HandleMaintenanceDerank(tol);//handle derank or potential destruction of the city
} }
@ -138,6 +170,17 @@ public enum MaintenanceManager {
public static void HandleMaintenanceDerank(Building tol){ public static void HandleMaintenanceDerank(Building tol){
setMaintDateTime(tol, tol.maintDateTime.plusDays(1)); //failed to pay maintenance, set next date for tomorrow 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();
} }
} }

Loading…
Cancel
Save