Browse Source

mines will start again

lakebane-master
FatBoy-DOTC 6 months ago
parent
commit
f1e8384af0
  1. 39
      src/engine/workthreads/MineThread.java

39
src/engine/workthreads/MineThread.java

@ -24,44 +24,37 @@ public class MineThread implements Runnable {
public void run() { public void run() {
LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
while (true){ while (true){
LocalDateTime now = LocalDateTime.now(); if(LocalDateTime.now().isAfter(nextPulse)) {
if (now.isAfter(nextPulse)) {
for (Mine mine : Mine.getMines()) { for (Mine mine : Mine.getMines()) {
// Reset mine at 4:00 AM
if (nextPulse.getHour() == 4 && nextPulse.getMinute() == 0) {
mine.wasClaimed = false;
mine.hasProduced = false;
}
Building mineTower = BuildingManager.getBuilding(mine.getBuildingID()); Building mineTower = BuildingManager.getBuilding(mine.getBuildingID());
if (mineTower == null) {
if (mineTower == null)
continue; continue;
}
int minute = mine.firstThirty ? 0 : 30; int minute = 0;
LocalDateTime openTime = now.withHour(mine.liveTime).withMinute(minute).withSecond(0).withNano(0); if (mine.firstThirty == false)
minute = 30;
LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0);
LocalDateTime closeTime = openTime.plusMinutes(29); LocalDateTime closeTime = openTime.plusMinutes(29);
if (!mine.wasClaimed && !mine.wasOpened && now.isAfter(openTime.minusMinutes(1))) { //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); mineWindowOpen(mine);
continue; continue;
} }
if (mine.isActive) {
if (mine.isActive && now.isAfter(closeTime)) { if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() > 0)
if (mineTower.getRank() > 0 || (mineTower.getRank() < 1 && mine.lastClaimer != null)) { mineWindowClose(mine); //mine was never knocked down, close window
mineWindowClose(mine);
} 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); nextPulse = nextPulse.plusMinutes(30);
} }
try {
Thread.sleep(1000); // Avoid busy-waiting
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} }
} }

Loading…
Cancel
Save