Browse Source

Mine optimization

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

40
src/engine/workthreads/MineThread.java

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

Loading…
Cancel
Save