From b1b2912092ed90c5fc0089228f22ae1338f799c0 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 26 May 2024 16:36:40 -0500 Subject: [PATCH] yet another attempt at mines --- src/engine/workthreads/MineThread.java | 40 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/engine/workthreads/MineThread.java b/src/engine/workthreads/MineThread.java index 1cd254d0..d4d59ca9 100644 --- a/src/engine/workthreads/MineThread.java +++ b/src/engine/workthreads/MineThread.java @@ -16,16 +16,16 @@ import org.pmw.tinylog.Logger; import java.time.LocalDateTime; public class MineThread implements Runnable { + public static LocalDateTime nextPulse; public MineThread(){ } @Override public void run() { - LocalDateTime nextPulse = LocalDateTime.now().withMinute(59).minusHours(1); + nextPulse = LocalDateTime.now().withMinute(0); while (true) { if(LocalDateTime.now().isAfter(nextPulse)) { processMineWindows(); - nextPulse = nextPulse.plusMinutes(30); } } } @@ -108,21 +108,35 @@ public class MineThread implements Runnable { public static void processMineWindows(){ for (Mine mine : Mine.getMines()) { Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID()); + //if the tower comes back null, skip this mine if(tower == null) continue; - LocalDateTime liveTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute).minusMinutes(1); - if(!mine.isActive && !mine.wasOpened) { - if (LocalDateTime.now().isAfter(liveTime)) { - mineWindowOpen(mine); - // mine has not opened today yet, and it is now after the time it should have, open the mine - } + + //log the current time right now + LocalDateTime currentTime = LocalDateTime.now().plusMinutes(1); + + //check if this mine needs to open + LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute).withSecond(0).withNano(0); + if(currentTime.isAfter(openTime) && !mine.wasOpened){ + mineWindowOpen(mine); //hour and minute match, time to open the window + continue; } - //mine is active right now - if (LocalDateTime.now().isBefore(liveTime.plusMinutes(30))) - continue; // window is not over yet - if(tower.getRank() == 1 || mine.lastClaimer != null) - mineWindowClose(mine); + //check to see if the window shoul dbe closing now + if(currentTime.isAfter(openTime.plusMinutes(29))) { + //check to see if the tower was destoryed + boolean towerDestroyed = tower.getRank() < 1; + if(towerDestroyed){ + //check if a valid claimer exists to close the window and claim the mine since the tower was destroyed + if(mine.lastClaimer != null) + mineWindowClose(mine); + }else{ + //tower was not destroyed, mine window closes + mineWindowClose(mine); + } + + } } + nextPulse = nextPulse.plusMinutes(30); } }