Browse Source

system to open and close mines

lakebane-master
FatBoy-DOTC 6 months ago
parent
commit
47503de748
  1. 98
      src/engine/workthreads/MineThread.java

98
src/engine/workthreads/MineThread.java

@ -22,40 +22,84 @@ 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) {
if(LocalDateTime.now().isAfter(nextPulse)) { for (Mine mine : Mine.getMines()) {
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) if(now.isAfter(closeTime) && mine.lastClaimer == null){
continue; 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; mineWindowClose(mine); // finished checking parameters, close the mine
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);
} // 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) { public static void mineWindowOpen(Mine mine) {

Loading…
Cancel
Save