diff --git a/src/engine/gameManager/BaneManager.java b/src/engine/gameManager/BaneManager.java new file mode 100644 index 00000000..809afdf5 --- /dev/null +++ b/src/engine/gameManager/BaneManager.java @@ -0,0 +1,45 @@ +package engine.gameManager; + +import engine.Enum; +import engine.objects.Bane; +import org.joda.time.DateTime; + +public class BaneManager { + + public static void default_check(){ + for(Bane bane : Bane.banes.values()){ + if(!bane.daySet || !bane.timeSet || !bane.capSet){ + DateTime placementDate = bane.getPlacementDate(); + if(DateTime.now().isAfter(placementDate.plusHours(48))){ + //set bane for default time + if(!bane.daySet){ + bane.daySet = true; + DbManager.BaneQueries.SET_BANE_DAY_NEW(3,bane.getCityUUID()); + } + + if(!bane.timeSet){ + bane.timeSet = true; + DbManager.BaneQueries.SET_BANE_TIME_NEW(9,bane.getCityUUID()); + } + + if(!bane.capSet){ + bane.capSet = true; + bane.capSize = 20; + DbManager.BaneQueries.SET_BANE_CAP_NEW(20,bane.getCityUUID()); + } + bane.setLiveDate(DbManager.BaneQueries.getLiveDate(bane.getCityUUID())); + } + } + } + } + + public static void pulse_banes(){ + //used to pulse the anti-zerg mechanic of active banes + for(Bane bane : Bane.banes.values()){ + if(bane.getSiegePhase().equals(Enum.SiegePhase.WAR)){ + // bane is live, handle bane anti-zerg mechanic stuff + bane.applyZergBuffs(); + } + } + } +} diff --git a/src/engine/workthreads/BaneThread.java b/src/engine/workthreads/BaneThread.java index fe0c0fca..84a57d71 100644 --- a/src/engine/workthreads/BaneThread.java +++ b/src/engine/workthreads/BaneThread.java @@ -13,6 +13,7 @@ import engine.Enum; import engine.InterestManagement.WorldGrid; import engine.db.archive.DataWarehouse; import engine.db.archive.MineRecord; +import engine.gameManager.BaneManager; import engine.gameManager.BuildingManager; import engine.gameManager.ChatManager; import engine.gameManager.StrongholdManager; @@ -27,44 +28,21 @@ import java.util.ArrayList; public class BaneThread implements Runnable { - private volatile Long lastRun; public static final Long instancedelay = 1000L; public BaneThread() { Logger.info(" BaneThread thread has started!"); } - public void processBanesWindow() { - - try { - synchronized (Bane.banes) { - for (int baneId : Bane.banes.keySet()) { - Bane bane = Bane.banes.get(baneId); - if (bane != null && bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) { - bane.applyZergBuffs(); - } - } - } - } catch (Exception e) { - Logger.error("BANE ERROR",e); - } - - - } - public void run() { - lastRun = System.currentTimeMillis(); while (true) { - if (System.currentTimeMillis() >= lastRun + instancedelay) { // Correct condition - this.processBanesWindow(); - lastRun = System.currentTimeMillis(); // Update lastRun after processing - }else { - try { - Thread.sleep(100); // Pause for 100ms to reduce CPU usage - } catch (InterruptedException e) { - Logger.error("Thread interrupted", e); - Thread.currentThread().interrupt(); - } + //this.processBanesWindow(); + BaneManager.pulse_banes(); + try { + Thread.sleep(100); // Pause for 100ms to reduce CPU usage + } catch (InterruptedException e) { + Logger.error("Thread interrupted", e); + Thread.currentThread().interrupt(); } } } diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 93751791..06132df7 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -92,11 +92,11 @@ public class HourlyJobThread implements Runnable { Logger.info(MessageDispatcher.getNetstatString()); Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); - for (Bane bane : Bane.banes.values()){ - if(bane.getSiegePhase().equals(Enum.SiegePhase.CHALLENGE)){ - bane.setDefaultTime(); - } - } + //for (Bane bane : Bane.banes.values()){ + // if(bane.getSiegePhase().equals(Enum.SiegePhase.CHALLENGE)){ + // bane.setDefaultTime(); + // } + //} try{ Logger.info("Trashing Multibox Cheaters"); @@ -119,5 +119,7 @@ public class HourlyJobThread implements Runnable { }catch(Exception e){ Logger.error("Failed To Run Ban Multibox Abusers"); } + + BaneManager.default_check(); } }