Browse Source

yet another attempt at mines

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

38
src/engine/workthreads/MineThread.java

@ -16,16 +16,16 @@ import org.pmw.tinylog.Logger;
import java.time.LocalDateTime; import java.time.LocalDateTime;
public class MineThread implements Runnable { public class MineThread implements Runnable {
public static LocalDateTime nextPulse;
public MineThread(){ public MineThread(){
} }
@Override @Override
public void run() { public void run() {
LocalDateTime nextPulse = LocalDateTime.now().withMinute(59).minusHours(1); nextPulse = LocalDateTime.now().withMinute(0);
while (true) { while (true) {
if(LocalDateTime.now().isAfter(nextPulse)) { if(LocalDateTime.now().isAfter(nextPulse)) {
processMineWindows(); processMineWindows();
nextPulse = nextPulse.plusMinutes(30);
} }
} }
} }
@ -108,21 +108,35 @@ public class MineThread implements Runnable {
public static void processMineWindows(){ public static void processMineWindows(){
for (Mine mine : Mine.getMines()) { for (Mine mine : Mine.getMines()) {
Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID()); Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID());
//if the tower comes back null, skip this mine
if(tower == null) if(tower == null)
continue; continue;
LocalDateTime liveTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute).minusMinutes(1);
if(!mine.isActive && !mine.wasOpened) { //log the current time right now
if (LocalDateTime.now().isAfter(liveTime)) { LocalDateTime currentTime = LocalDateTime.now().plusMinutes(1);
mineWindowOpen(mine);
// mine has not opened today yet, and it is now after the time it should have, open the mine //check if this mine needs to open
} LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute).withSecond(0).withNano(0);
if(currentTime.isAfter(openTime) && !mine.wasOpened){
mineWindowOpen(mine); //hour and minute match, time to open the window
continue;
} }
//mine is active right now
if (LocalDateTime.now().isBefore(liveTime.plusMinutes(30)))
continue; // window is not over yet
if(tower.getRank() == 1 || mine.lastClaimer != null) //check to see if the window shoul dbe closing now
if(currentTime.isAfter(openTime.plusMinutes(29))) {
//check to see if the tower was destoryed
boolean towerDestroyed = tower.getRank() < 1;
if(towerDestroyed){
//check if a valid claimer exists to close the window and claim the mine since the tower was destroyed
if(mine.lastClaimer != null)
mineWindowClose(mine); mineWindowClose(mine);
}else{
//tower was not destroyed, mine window closes
mineWindowClose(mine);
}
} }
} }
nextPulse = nextPulse.plusMinutes(30);
}
} }

Loading…
Cancel
Save