Browse Source

new mines system

lakebane-master
FatBoy-DOTC 6 months ago
parent
commit
3aac2410b0
  1. 142
      src/engine/objects/Mine.java
  2. 130
      src/engine/workthreads/MineThread.java

142
src/engine/objects/Mine.java

@ -16,17 +16,14 @@ import engine.net.ByteBufferWriter; @@ -16,17 +16,14 @@ import engine.net.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg;
import engine.server.MBServerStatics;
import engine.workthreads.ZergMechanicThread;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import static engine.gameManager.DbManager.MineQueries;
import static engine.gameManager.DbManager.getObject;
@ -60,7 +57,8 @@ public class Mine extends AbstractGameObject { @@ -60,7 +57,8 @@ public class Mine extends AbstractGameObject {
public boolean hasProduced = false;
public int liveTime;
public int liveHour;
public int liveMinute;
public Boolean firstThirty = true;
public static ArrayList<Mine> ChinaMines = new ArrayList<>();
@ -115,57 +113,12 @@ public class Mine extends AbstractGameObject { @@ -115,57 +113,12 @@ public class Mine extends AbstractGameObject {
this.production = Resource.valueOf(rs.getString("mine_resource"));
this.lastClaimer = null;
this.liveHour = rs.getInt("mineLiveHour");
this.liveMinute = rs.getInt("mineLiveMinute");
}
}
public static void SetTimes(){
try {
EuroMines.get(0).liveTime = 19;
EuroMines.get(1).liveTime = 19;
EuroMines.get(2).liveTime = 20;
EuroMines.get(3).liveTime = 20;
EuroMines.get(4).liveTime = 21;
EuroMines.get(5).liveTime = 21;
EuroMines.get(6).liveTime = 22;
}catch(Exception e){
}
try{
ChinaMines.get(0).liveTime = 11;
ChinaMines.get(1).liveTime = 11;
ChinaMines.get(2).liveTime = 11;
ChinaMines.get(3).liveTime = 12;
ChinaMines.get(4).liveTime = 12;
ChinaMines.get(5).liveTime = 12;
ChinaMines.get(6).liveTime = 12;
ChinaMines.get(7).liveTime = 12;
ChinaMines.get(8).liveTime = 12;
ChinaMines.get(9).liveTime = 12;
ChinaMines.get(10).liveTime = 13;
ChinaMines.get(11).liveTime = 13;
ChinaMines.get(12).liveTime = 13;
ChinaMines.get(13).liveTime = 13;
}catch(Exception e){
}
try{
AmericaMines.get(0).liveTime = 1;
AmericaMines.get(1).liveTime = 2;
AmericaMines.get(2).liveTime = 2;
AmericaMines.get(3).liveTime = 3;
AmericaMines.get(4).liveTime = 3;
AmericaMines.get(5).liveTime = 3;
AmericaMines.get(6).liveTime = 3;
AmericaMines.get(7).liveTime = 3;
AmericaMines.get(8).liveTime = 3;
AmericaMines.get(9).liveTime = 3;
AmericaMines.get(10).liveTime = 4;
AmericaMines.get(11).liveTime = 4;
AmericaMines.get(12).liveTime = 4;
AmericaMines.get(13).liveTime = 5;
}catch(Exception e){
}
int count = 1;
for(Mine mine : EuroMines){
@ -306,89 +259,8 @@ public class Mine extends AbstractGameObject { @@ -306,89 +259,8 @@ public class Mine extends AbstractGameObject {
//mine.mineType = MineProduction.LUMBER;
}
try {
ChinaMines.add(serverMines.get(0));
ChinaMines.add(serverMines.get(3));
ChinaMines.add(serverMines.get(6));
ChinaMines.add(serverMines.get(9));
ChinaMines.add(serverMines.get(12));
ChinaMines.add(serverMines.get(15));
ChinaMines.add(serverMines.get(18));
ChinaMines.add(serverMines.get(21));
ChinaMines.add(serverMines.get(23));
ChinaMines.add(serverMines.get(25));
ChinaMines.add(serverMines.get(27));
ChinaMines.add(serverMines.get(29));
ChinaMines.add(serverMines.get(31));
ChinaMines.add(serverMines.get(33));
}catch(Exception e){
}
try{
AmericaMines.add(serverMines.get(1));
AmericaMines.add(serverMines.get(4));
AmericaMines.add(serverMines.get(7));
AmericaMines.add(serverMines.get(10));
AmericaMines.add(serverMines.get(13));
AmericaMines.add(serverMines.get(16));
AmericaMines.add(serverMines.get(19));
AmericaMines.add(serverMines.get(22));
AmericaMines.add(serverMines.get(24));
AmericaMines.add(serverMines.get(26));
AmericaMines.add(serverMines.get(28));
AmericaMines.add(serverMines.get(30));
AmericaMines.add(serverMines.get(32));
AmericaMines.add(serverMines.get(34));
}catch(Exception e){
}
try{
EuroMines.add(serverMines.get(2));
EuroMines.add(serverMines.get(5));
EuroMines.add(serverMines.get(8));
EuroMines.add(serverMines.get(11));
EuroMines.add(serverMines.get(14));
EuroMines.add(serverMines.get(17));
EuroMines.add(serverMines.get(20));
}catch(Exception e){
}
SetTimes();
for(Mine mine : EuroMines){
if(EuroMines.indexOf(mine) %2 == 0 ){
mine.firstThirty = true;
} else{
mine.firstThirty = false;
}
}
for(Mine mine : AmericaMines){
if(AmericaMines.indexOf(mine) %2 == 0 ){
mine.firstThirty = true;
} else{
mine.firstThirty = false;
}
}
for(Mine mine : ChinaMines){
if(ChinaMines.indexOf(mine) %2 == 0 ){
mine.firstThirty = true;
} else{
mine.firstThirty = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}catch(Exception e) {
for(Mine mine : Mine.getMines()){
int minute = 0;
if (mine.firstThirty == false)
minute = 30;
LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0);
LocalDateTime closeTime = openTime.plusMinutes(30);
if(LocalDateTime.now().isAfter(closeTime))
mine.wasOpened = true;
}
}
@ -423,10 +295,10 @@ public class Mine extends AbstractGameObject { @@ -423,10 +295,10 @@ public class Mine extends AbstractGameObject {
LocalDateTime mineOpenTime;// = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
if(mine.firstThirty == true){
mineOpenTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(0).withSecond(0).withNano(0);
mineOpenTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(0).withSecond(0).withNano(0);
}
else{
mineOpenTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(30).withSecond(0).withNano(0);
mineOpenTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(30).withSecond(0).withNano(0);
}
LocalDateTime mineCloseTime = mineOpenTime.plusMinutes(30);

130
src/engine/workthreads/MineThread.java

@ -15,6 +15,8 @@ import engine.objects.PlayerCharacter; @@ -15,6 +15,8 @@ import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class MineThread implements Runnable {
public MineThread(){
@ -22,89 +24,12 @@ public class MineThread implements Runnable { @@ -22,89 +24,12 @@ public class MineThread implements Runnable {
}
@Override
public void run() {
LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
LocalDateTime nextPulse = LocalDateTime.now().withMinute(59).minusHours(1);
while (true) {
LocalDateTime now = LocalDateTime.now();
if(now.isBefore(nextPulse))
break;
nextPulse = nextPulse.plusMinutes(1);
for (Mine mine : Mine.getMines()) {
if(mine.wasClaimed)
continue;
int minute = 0;
if (!mine.firstThirty)
minute = 30;
LocalDateTime openTime = now.withHour(mine.liveTime).withMinute(minute).withSecond(0);
LocalDateTime closeTime = openTime.plusMinutes(30);
if (now.isAfter(openTime) && !mine.isActive) {
mineWindowOpen(mine);
continue; // mine has not opened today yet, and it is now after the time it should have, open the mine
}
if(now.isAfter(closeTime) && BuildingManager.getBuilding(mine.getBuildingID()).getRank() == 1 && mine.isActive) {
mineWindowClose(mine);
continue; // mine was never knocked down, close it
}
if(now.isAfter(closeTime) && mine.lastClaimer == null && mine.isActive){
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
}
mineWindowClose(mine); // finished checking parameters, close the mine
}
if(LocalDateTime.now().isAfter(nextPulse));
processMineWindows();
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) {
@ -181,4 +106,47 @@ public class MineThread implements Runnable { @@ -181,4 +106,47 @@ public class MineThread implements Runnable {
mine.wasClaimed = true;
return true;
}
public static void processMineWindows(){
for (Mine mine : Mine.getMines()) {
Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID());
if(tower == null)
continue;
LocalDateTime liveTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute).minusMinutes(1);
ZonedDateTime localizedTime = convertCSTToLocalTime(liveTime);
if(!mine.isActive) {
if (ZonedDateTime.now().isAfter(localizedTime)) {
mineWindowOpen(mine);
// mine has not opened today yet, and it is now after the time it should have, open the mine
}
}else{
//mine is active right now
if (ZonedDateTime.now().isBefore(localizedTime.plusMinutes(30))){
continue; // window is not over yet
}
if(tower.getRank() == 1){
//mine was not knocked down, close the window
mineWindowClose(mine);
}else{
if(mine.lastClaimer != null)
mineWindowClose(mine); //has a claimer, close the window
}
}
}
}
public static ZonedDateTime convertCSTToLocalTime(LocalDateTime cstDateTime) {
// Define the CST time zone (Central Standard Time)
ZoneId cstZoneId = ZoneId.of("America/Chicago"); // CST is represented by America/Chicago
// Define the system's default time zone
ZoneId localZoneId = ZoneId.systemDefault();
// Create a ZonedDateTime object for CST
ZonedDateTime cstZonedDateTime = ZonedDateTime.of(cstDateTime, cstZoneId);
// Convert CST to the local time zone
ZonedDateTime localZonedDateTime = cstZonedDateTime.withZoneSameInstant(localZoneId);
return localZonedDateTime;
}
}

Loading…
Cancel
Save