Browse Source

system to open and close mines

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

78
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()) {
Building mineTower = BuildingManager.getBuilding(mine.getBuildingID()); if(mine.wasClaimed)
if (mineTower == null)
continue; continue;
LocalDateTime now = LocalDateTime.now();
int minute = 0; int minute = 0;
if (mine.firstThirty == false) if (!mine.firstThirty)
minute = 30; minute = 30;
LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0); LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0);
LocalDateTime closeTime = openTime.plusMinutes(29); LocalDateTime closeTime = openTime.plusMinutes(30);
//current time is after start time and before close time, open mine window if (now.isAfter(openTime)) {
if (LocalDateTime.now().isAfter(openTime.minusMinutes(1)) && !mine.wasClaimed && !mine.wasOpened) {
mineWindowOpen(mine); mineWindowOpen(mine);
continue; continue; // mine has not opened today yet, and it is now after the time it should have, open the mine
} }
if (mine.isActive) {
if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() > 0) if(now.isAfter(closeTime) && BuildingManager.getBuilding(mine.getBuildingID()).getRank() == 1) {
mineWindowClose(mine); //mine was never knocked down, close window mineWindowClose(mine);
continue; // mine was never knocked down, close it
}
if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() < 1 && mine.lastClaimer != null) if(now.isAfter(closeTime) && mine.lastClaimer == null){
mineWindowClose(mine); //mine was knocked down and was claimed, close window 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
} }
nextPulse = nextPulse.plusMinutes(30);
mineWindowClose(mine); // finished checking parameters, close the mine
} }
} }
// 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