| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -5,171 +5,206 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
 | 
					 | 
					 | 
					 | 
					// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//      Magicbane Emulator Project © 2013 - 2022
 | 
					 | 
					 | 
					 | 
					//      Magicbane Emulator Project © 2013 - 2022
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//                www.magicbane.com
 | 
					 | 
					 | 
					 | 
					//                www.magicbane.com
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					package engine.gameManager; | 
					 | 
					 | 
					 | 
					package engine.gameManager; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// Defines static methods which comprise the magicbane
 | 
					 | 
					 | 
					 | 
					// Defines static methods which comprise the magicbane
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// building maintenance system.
 | 
					 | 
					 | 
					 | 
					// building maintenance system.
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import engine.Enum; | 
					 | 
					 | 
					 | 
					import engine.Enum; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import engine.objects.*; | 
					 | 
					 | 
					 | 
					import engine.objects.*; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import org.pmw.tinylog.Logger; | 
					 | 
					 | 
					 | 
					import org.pmw.tinylog.Logger; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.time.LocalDateTime; | 
					 | 
					 | 
					 | 
					import java.time.LocalDateTime; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.ArrayList; | 
					 | 
					 | 
					 | 
					import java.util.ArrayList; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.HashMap; | 
					 | 
					 | 
					 | 
					import java.util.HashMap; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.concurrent.ConcurrentHashMap; | 
					 | 
					 | 
					 | 
					import java.util.concurrent.ConcurrentHashMap; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					public enum MaintenanceManager { | 
					 | 
					 | 
					 | 
					public enum MaintenanceManager { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    MAINTENANCEMANAGER; | 
					 | 
					 | 
					 | 
					    MAINTENANCEMANAGER; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void setMaintDateTime(Building building, LocalDateTime maintDate) { | 
					 | 
					 | 
					 | 
					    public static void setMaintDateTime(Building building, LocalDateTime maintDate) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        building.maintDateTime = maintDate; | 
					 | 
					 | 
					 | 
					        building.maintDateTime = maintDate; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        DbManager.BuildingQueries.updateMaintDate(building); | 
					 | 
					 | 
					 | 
					        DbManager.BuildingQueries.updateMaintDate(building); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void dailyMaintenance() { | 
					 | 
					 | 
					 | 
					    public static void dailyMaintenance() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Logger.info("Maintenance has started"); | 
					 | 
					 | 
					 | 
					        Logger.info("Maintenance has started"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // Run maintenance on player buildings
 | 
					 | 
					 | 
					 | 
					        // Run maintenance on player buildings
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (ConfigManager.MB_WORLD_MAINTENANCE.getValue().equalsIgnoreCase("true")) | 
					 | 
					 | 
					 | 
					        if (ConfigManager.MB_WORLD_MAINTENANCE.getValue().equalsIgnoreCase("true")) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            processMaintenance(); | 
					 | 
					 | 
					 | 
					            processMaintenance(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        else | 
					 | 
					 | 
					 | 
					        else | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            Logger.info("Maintenance Costings: DISABLED"); | 
					 | 
					 | 
					 | 
					            Logger.info("Maintenance Costings: DISABLED"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Logger.info("Maintenance has completed!"); | 
					 | 
					 | 
					 | 
					        Logger.info("Maintenance has completed!"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void processMaintenance() { | 
					 | 
					 | 
					 | 
					    public static void processMaintenance() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //create list of all cities
 | 
					 | 
					 | 
					 | 
					        //create list of all cities
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        ConcurrentHashMap<Integer, AbstractGameObject> worldCities = DbManager.getMap(Enum.GameObjectType.City); | 
					 | 
					 | 
					 | 
					        ConcurrentHashMap<Integer, AbstractGameObject> worldCities = DbManager.getMap(Enum.GameObjectType.City); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //loop all cities
 | 
					 | 
					 | 
					 | 
					        //loop all cities
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for (AbstractGameObject ago : worldCities.values()) { | 
					 | 
					 | 
					 | 
					        for (AbstractGameObject ago : worldCities.values()) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (ago.getObjectType().equals(Enum.GameObjectType.City)) { | 
					 | 
					 | 
					 | 
					            if (ago.getObjectType().equals(Enum.GameObjectType.City)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                City city = (City) ago; | 
					 | 
					 | 
					 | 
					                City city = (City) ago; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if(city == null || city.getIsNpcOwned() == 1) | 
					 | 
					 | 
					 | 
					                if(city == null || !city.getParent().isPlayerCity()) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    continue; | 
					 | 
					 | 
					 | 
					                    continue; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                Building tol = city.getTOL(); | 
					 | 
					 | 
					 | 
					                Building tol = city.getTOL(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if(tol == null) | 
					 | 
					 | 
					 | 
					                if(tol == null) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    continue; | 
					 | 
					 | 
					 | 
					                    continue; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					                LocalDateTime maintenanceDueDate = tol.maintDateTime.withHour(1).withMinute(0).withSecond(0); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if(tol.maintDateTime.toLocalDate().equals(LocalDateTime.now().toLocalDate()) || LocalDateTime.now().toLocalDate().isAfter(tol.maintDateTime.toLocalDate())){ | 
					 | 
					 | 
					 | 
					                LocalDateTime now = LocalDateTime.now(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    // today is maintenance day
 | 
					 | 
					 | 
					 | 
					                if(now.isAfter(maintenanceDueDate)) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    processTolMaintenance(tol, city.getWarehouse()); | 
					 | 
					 | 
					 | 
					                    processTolMaintenance(tol, city.getWarehouse()); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void processTolMaintenance(Building tol, Warehouse warehouse){ | 
					 | 
					 | 
					 | 
					    public static void processTolMaintenance(Building tol, Warehouse warehouse){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //create the required resource maintenance list
 | 
					 | 
					 | 
					 | 
					        if(tol == null) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        HashMap<Integer,Integer> maintCosts = new HashMap<>(); | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        maintCosts.put(7,3000000); | 
					 | 
					 | 
					 | 
					        if(tol.getRank() == 8) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if(tol.getRank() == 8){ | 
					 | 
					 | 
					 | 
					            handleR8(tol,warehouse); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            maintCosts.put(1580000,3000);//stone
 | 
					 | 
					 | 
					 | 
					        else | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            maintCosts.put(1580004,3000);//lumber
 | 
					 | 
					 | 
					 | 
					            handleNormal(tol,warehouse); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            maintCosts.put(1580017,5);//galvor
 | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            maintCosts.put(1580018,5);//wormwood
 | 
					 | 
					 | 
					 | 
					    public static void handleNormal(Building tol, Warehouse warehouse){ | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }else { | 
					 | 
					 | 
					 | 
					        //handle r7 and lower ToL maintenance
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            //not r8, only need to process gold value and we're done
 | 
					 | 
					 | 
					 | 
					        int goldDue = 3000000; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            int maintenanceDue = maintCosts.get(7); | 
					 | 
					 | 
					 | 
					        //enough on strongbox alone to pay
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            int strongboxGold = tol.getStrongboxValue(); | 
					 | 
					 | 
					 | 
					        if (tol.getStrongboxValue() >= goldDue) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (strongboxGold > 0) { | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(7); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if (strongboxGold > maintenanceDue) { | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    //enough gold in strongbox to cover all of maintenance
 | 
					 | 
					 | 
					 | 
					                tol.setStrongboxValue(tol.getStrongboxValue() - goldDue); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    maintenanceDue = 0; | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    strongboxGold -= maintenanceDue; | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    tol.setStrongboxValue(strongboxGold); //update strongbox value
 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    setMaintDateTime(tol, LocalDateTime.now().plusDays(7)); //maintenance paid, set next maintenance date for 1 week from today
 | 
					 | 
					 | 
					 | 
					        int newStrongboxValue = tol.getStrongboxValue(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    return; //maintenance is paid, all done
 | 
					 | 
					 | 
					 | 
					        int newWarehouseGold = 0; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                } else { | 
					 | 
					 | 
					 | 
					        if(warehouse != null && warehouse.getResources().get(ItemBase.getItemBase(7)) != null) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    maintenanceDue -= strongboxGold; | 
					 | 
					 | 
					 | 
					            newWarehouseGold = warehouse.getResources().get(ItemBase.getItemBase(7)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    strongboxGold = 0; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            //now we need to take the remaining maintenance from the warehouse
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            int warehouseGold = 0; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (warehouse != null) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                warehouseGold = warehouse.getResources().get(ItemBase.getItemBase(7)); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (warehouseGold >= maintenanceDue) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                //we have enough gold to process maintenance
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                tol.setStrongboxValue(strongboxGold); //update the strongbox now that we are sure maintenance is being paid
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                warehouseGold -= maintenanceDue; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                warehouse.getResources().put(ItemBase.getItemBase(7),warehouseGold); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                DbManager.WarehouseQueries.updateGold(warehouse, warehouseGold); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                setMaintDateTime(tol, LocalDateTime.now().plusDays(7)); //maintenance paid, set next maintenance date for 1 week from today
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                //maintenance is paid, all done
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else{ | 
					 | 
					 | 
					 | 
					        } else{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                //failed maintenance, derank asset
 | 
					 | 
					 | 
					 | 
					            //wasnt enough on strongbox and gold in warehouse is empty
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                HandleMaintenanceDerank(tol); //handle derank or potential destruction of the city
 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            return; | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					        //some on strongbox to pay
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //handle r8 ToL maintenance here after the fact
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        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() > 0) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if(tol.getStrongboxValue() > maintenanceGoldRequired){ | 
					 | 
					 | 
					 | 
					            newStrongboxValue = 0; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                strongboxGold -= maintenanceGoldRequired; | 
					 | 
					 | 
					 | 
					            goldDue -= tol.getStrongboxValue(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                maintCosts.put(7,0); | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(newWarehouseGold < goldDue){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            //not enough gold to pay, you miss maintenance
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        newWarehouseGold -= goldDue; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        tol.maintDateTime = LocalDateTime.now().plusDays(7); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(DbManager.BuildingQueries.updateMaintDate(tol) && DbManager.WarehouseQueries.updateGold(warehouse,newWarehouseGold)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            warehouse.getResources().put(ItemBase.getItemBase(7), newWarehouseGold); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.setStrongboxValue(newStrongboxValue); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    public static void handleR8(Building tol, Warehouse warehouse){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        //handle r8 ToL maintenance
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        //cannot pay r8 maintenance without a warehouse
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(warehouse == null && DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        //handle resource processing
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int goldDue = 3000000; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int galvorDue = 5; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int wormwoodDue = 5; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int stoneDue = 5000; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int lumberDue = 5000; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int goldStrongBox = tol.getStrongboxValue(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int goldWarehouse = 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int galvorWarehouse; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int wormwoodWarehouse; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int stoneWarehouse; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        int lumberWarehouse; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(warehouse.getResources().get(Warehouse.galvorIB) != null) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            galvorWarehouse = warehouse.getResources().get(Warehouse.galvorIB); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        }else { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(warehouse.getResources().get(Warehouse.stoneIB) != null) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            stoneWarehouse = warehouse.getResources().get(Warehouse.stoneIB); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }else { | 
					 | 
					 | 
					 | 
					        }else { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                maintCosts.put(7,maintCosts.get(7) - strongboxGold); | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                strongboxGold = 0; | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for(Integer ibId : maintCosts.keySet()){ | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (warehouse != null) { | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if(warehouse.getResources().get(ItemBase.getItemBase(ibId)) == null) | 
					 | 
					 | 
					 | 
					        if(warehouse.getResources().get(Warehouse.wormwoodIB) != null) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    success = false; //this resource is not in the warehouse, failed to pay maintenance
 | 
					 | 
					 | 
					 | 
					            wormwoodWarehouse = warehouse.getResources().get(Warehouse.wormwoodIB); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                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 { | 
					 | 
					 | 
					 | 
					        }else { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                success = false; //warehouse is null, cannot pay resource maintenance
 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if(success == true){ | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            //determined there is enough of each resourceType to withdraw maintenance
 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            tol.setStrongboxValue(strongboxGold); | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            int goldLeft = warehouse.getResources().get(ItemBase.getItemBase(7)) - maintCosts.get(7); | 
					 | 
					 | 
					 | 
					        if(warehouse.getResources().get(Warehouse.lumberIB) != null) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            int galvorLeft = warehouse.getResources().get(ItemBase.getItemBase(1580017)) - maintCosts.get(1580017); | 
					 | 
					 | 
					 | 
					            lumberWarehouse = warehouse.getResources().get(Warehouse.lumberIB); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            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, LocalDateTime.now().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
 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        boolean canPay = true; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(goldStrongBox >= goldDue){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            goldStrongBox -= goldDue; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            goldDue = 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if (tol.getStrongboxValue() > 0) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            goldStrongBox = 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            goldDue -= tol.getStrongboxValue(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(warehouse.getResources().get(Warehouse.goldIB) != null) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            goldWarehouse = warehouse.getResources().get(Warehouse.goldIB); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        }else if(goldDue > 0){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					        if(wormwoodDue > wormwoodWarehouse) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void HandleMaintenanceDerank(Building tol){ | 
					 | 
					 | 
					 | 
					            canPay = false; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        setMaintDateTime(tol, LocalDateTime.now().plusDays(1)); //failed to pay maintenance, set next date for tomorrow
 | 
					 | 
					 | 
					 | 
					        if(galvorDue > galvorWarehouse) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            canPay = false; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(lumberDue > lumberWarehouse) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            canPay = false; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(stoneDue > stoneWarehouse) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            canPay = false; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(goldDue > goldWarehouse) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            canPay = false; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(!canPay){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
					 | 
					 | 
					 | 
					                tol.destroyOrDerank(null); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        tol.setStrongboxValue(goldStrongBox); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if(DbManager.WarehouseQueries.updateGold(warehouse,goldWarehouse - goldDue)){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if(DbManager.WarehouseQueries.updateStone(warehouse,stoneWarehouse - stoneDue)){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                if(DbManager.WarehouseQueries.updateLumber(warehouse,lumberWarehouse - lumberDue)){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    if(DbManager.WarehouseQueries.updateGalvor(warehouse,galvorWarehouse - galvorDue)){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                        if(DbManager.WarehouseQueries.updateWormwood(warehouse,wormwoodWarehouse - wormwoodDue)){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                            tol.maintDateTime = LocalDateTime.now().plusDays(1); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                            if(DbManager.BuildingQueries.updateMaintDate(tol)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                                return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} |