Browse Source

mines will start again

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

41
src/engine/workthreads/MineThread.java

@ -23,45 +23,38 @@ public class MineThread implements Runnable {
@Override @Override
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