From 47503de7485913fd1e07395b0ae620100b2fa19d Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 22 May 2024 20:23:19 -0500 Subject: [PATCH] system to open and close mines --- src/engine/workthreads/MineThread.java | 98 +++++++++++++++++++------- 1 file changed, 71 insertions(+), 27 deletions(-) diff --git a/src/engine/workthreads/MineThread.java b/src/engine/workthreads/MineThread.java index 266fa1d7..f0d32e5d 100644 --- a/src/engine/workthreads/MineThread.java +++ b/src/engine/workthreads/MineThread.java @@ -22,40 +22,84 @@ public class MineThread implements Runnable { } @Override public void run() { - LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); - while (true){ - if(LocalDateTime.now().isAfter(nextPulse)) { - for (Mine mine : Mine.getMines()) { + //LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); + while (true) { + for (Mine mine : Mine.getMines()) { + + if(mine.wasClaimed) + continue; + LocalDateTime now = LocalDateTime.now(); + int minute = 0; + if (!mine.firstThirty) + minute = 30; + + LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0); + LocalDateTime closeTime = openTime.plusMinutes(30); + + if (now.isAfter(openTime)) { + mineWindowOpen(mine); + continue; // mine has not opened today yet, and it is now after the time it should have, open the mine + } - Building mineTower = BuildingManager.getBuilding(mine.getBuildingID()); + if(now.isAfter(closeTime) && BuildingManager.getBuilding(mine.getBuildingID()).getRank() == 1) { + mineWindowClose(mine); + continue; // mine was never knocked down, close it + } - if (mineTower == null) - continue; + if(now.isAfter(closeTime) && mine.lastClaimer == null){ + if(mine.firstThirty){ + mine.firstThirty = false; + }else{ + mine.firstThirty = true; + mine.liveTime += 1; + } + continue; // roll over to the next 30-minute window, mine was knocked down and not claimed + } - int minute = 0; - if (mine.firstThirty == false) - minute = 30; + mineWindowClose(mine); // finished checking parameters, close the mine + } + } - LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0); - LocalDateTime closeTime = openTime.plusMinutes(29); - //current time is after start time and before close time, open mine window - if (LocalDateTime.now().isAfter(openTime.minusMinutes(1)) && !mine.wasClaimed && !mine.wasOpened) { - mineWindowOpen(mine); - continue; - } - if (mine.isActive) { - if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() > 0) - mineWindowClose(mine); //mine was never knocked down, close window - if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() < 1 && mine.lastClaimer != null) - mineWindowClose(mine); //mine was knocked down and was claimed, close window - } - } - nextPulse = nextPulse.plusMinutes(30); - } - } + + + + + + // if(LocalDateTime.now().isAfter(nextPulse)) { + // for (Mine mine : Mine.getMines()) { + + // Building mineTower = BuildingManager.getBuilding(mine.getBuildingID()); + + // if (mineTower == null) + // continue; + + // int minute = 0; + // if (mine.firstThirty == false) + // minute = 30; + + // LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0); + // LocalDateTime closeTime = openTime.plusMinutes(29); + + //current time is after start time and before close time, open mine window + // if (LocalDateTime.now().isAfter(openTime.minusMinutes(1)) && !mine.wasClaimed && !mine.wasOpened) { + // mineWindowOpen(mine); + // continue; + // } + // if (mine.isActive) { +// + // if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() > 0) + // mineWindowClose(mine); //mine was never knocked down, close window +// + // if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() < 1 && mine.lastClaimer != null) + // mineWindowClose(mine); //mine was knocked down and was claimed, close window + // } + // } + // nextPulse = nextPulse.plusMinutes(30); + // } + //} } public static void mineWindowOpen(Mine mine) {