Browse Source

mines thread

lakebane-master
fatboy 7 months ago
parent
commit
5d0973c2bc
  1. 7
      src/engine/devcmd/cmds/MineActiveCmd.java
  2. 50
      src/engine/gameManager/SimulationManager.java
  3. 11
      src/engine/server/world/WorldServer.java
  4. 144
      src/engine/workthreads/HourlyJobThread.java
  5. 140
      src/engine/workthreads/MineThread.java

7
src/engine/devcmd/cmds/MineActiveCmd.java

@ -12,11 +12,12 @@ package engine.devcmd.cmds;
import engine.devcmd.AbstractDevCmd; import engine.devcmd.AbstractDevCmd;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.SimulationManager;
import engine.objects.AbstractGameObject; import engine.objects.AbstractGameObject;
import engine.objects.Building; import engine.objects.Building;
import engine.objects.Mine; import engine.objects.Mine;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.workthreads.HourlyJobThread; import engine.workthreads.MineThread;
/** /**
* *
@ -41,10 +42,10 @@ public class MineActiveCmd extends AbstractDevCmd {
String trigger = args[0]; String trigger = args[0];
switch (trigger) { switch (trigger) {
case "true": case "true":
HourlyJobThread.mineWindowOpen(mine); MineThread.mineWindowOpen(mine);
break; break;
case "false": case "false":
HourlyJobThread.mineWindowClose(mine); MineThread.mineWindowClose(mine);
break; break;
default: default:
this.sendUsage(pcSender); this.sendUsage(pcSender);

50
src/engine/gameManager/SimulationManager.java

@ -10,6 +10,11 @@ package engine.gameManager;
import engine.Enum; import engine.Enum;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.net.DispatchMessage;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*; import engine.objects.*;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -22,9 +27,6 @@ import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import static engine.workthreads.HourlyJobThread.mineWindowClose;
import static engine.workthreads.HourlyJobThread.mineWindowOpen;
/* /*
* This class contains all methods necessary to drive periodic * This class contains all methods necessary to drive periodic
* updates of the game simulation from the main _exec loop. * updates of the game simulation from the main _exec loop.
@ -71,6 +73,8 @@ public enum SimulationManager {
return popString; return popString;
} }
/* /*
* Update the simulation. *** Important: Whatever you do in here, do it damn * Update the simulation. *** Important: Whatever you do in here, do it damn
* quick! * quick!
@ -231,44 +235,4 @@ public enum SimulationManager {
_runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE; _runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE;
} }
private void pulseMines(){
// if(LocalDateTime.now().getMinute() != 30 && LocalDateTime.now().getMinute() != 0)
// return;
for(Mine mine : Mine.getMines()) {
Building mineTower = BuildingManager.getBuilding(mine.getBuildingID());
if(mineTower == null)
continue;
///if (LocalDateTime.now().getHour() == 1) {
// mine.wasClaimed = false;
// mine.hasProduced = false;
//}
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);
//current time is after start time and before close time, open mine window
if (!mine.isActive && LocalDateTime.now().isAfter(openTime) && LocalDateTime.now().isBefore(closeTime)) {
mineWindowOpen(mine);
continue;
}
if(mine.isActive) {
if (LocalDateTime.now().isAfter(closeTime.plusSeconds(10)) && mineTower.getRank() == 0 && mine.lastClaimer == null)
closeTime = closeTime.plusMinutes(30); // mine was knocked down and has no claimer, roll over
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
}
}
_minePulseTime = System.currentTimeMillis() + CITY_PULSE;
}
} }

11
src/engine/server/world/WorldServer.java

@ -41,10 +41,7 @@ import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*; import engine.objects.*;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.util.ThreadUtils; import engine.util.ThreadUtils;
import engine.workthreads.DisconnectTrashTask; import engine.workthreads.*;
import engine.workthreads.HourlyJobThread;
import engine.workthreads.PurgeOprhans;
import engine.workthreads.WarehousePushThread;
import org.pmw.tinylog.Configurator; import org.pmw.tinylog.Configurator;
import org.pmw.tinylog.Level; import org.pmw.tinylog.Level;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -529,6 +526,12 @@ public class WorldServer {
Logger.info("Running garbage collection..."); Logger.info("Running garbage collection...");
System.gc(); System.gc();
Logger.info("Starting Mine Thread...");
Thread mineThread = new Thread(new MineThread());
mineThread.setName("hourlyJob");
mineThread.start();
return true; return true;
} }

144
src/engine/workthreads/HourlyJobThread.java

@ -10,18 +10,12 @@
package engine.workthreads; package engine.workthreads;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.*; import engine.gameManager.*;
import engine.net.DispatchMessage;
import engine.net.MessageDispatcher; import engine.net.MessageDispatcher;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*; import engine.objects.*;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -74,144 +68,6 @@ public class HourlyJobThread implements Runnable {
} }
} }
public static void processMineWindow() {
try {
ArrayList<Mine> mines = Mine.getMines();
for (Mine mine : mines) {
if (LocalDateTime.now().getHour() == 1) {
mine.wasClaimed = false;
mine.hasProduced = false;
}
try {
// Open Errant Mines
//if (mine.getOwningGuild().isEmptyGuild()) {
// HourlyJobThread.mineWindowOpen(mine);
// continue;
//}
if (mine.liveTime == LocalDateTime.now().getHour() && mine.wasClaimed == false) {
if(mine.firstThirty == true && LocalDateTime.now().isAfter(LocalDateTime.now().withHour(mine.liveTime).withMinute(0).withSecond(0)) && LocalDateTime.now().isBefore(LocalDateTime.now().withHour(mine.liveTime).withMinute(30).withSecond(0))){
if(mine.isActive == false) {
mineWindowOpen(mine);
}
continue;
}
if(mine.firstThirty == false && LocalDateTime.now().isAfter(LocalDateTime.now().withHour(mine.liveTime).withMinute(30).withSecond(0)) && LocalDateTime.now().isBefore(LocalDateTime.now().withHour(mine.liveTime).withMinute(0).withSecond(0).plusHours(1))){
if(mine.isActive == false) {
mineWindowOpen(mine);
}
continue;
}
}
// Open Mines owned by nations having their WOO
// set to the current mine window.
//if (mine.liveTime == LocalDateTime.now().getHour() && mine.wasClaimed == false) {
/// if (mine.fullHour == true) {
// HourlyJobThread.mineWindowOpen(mine);
// continue;
// }
// else if(LocalDateTime.now().isBefore(LocalDateTime.now().withMinute(29).withSecond(59))) {
// mineWindowOpen(mine);
// continue;
// }
//}
// Close the mine if it reaches this far
mineWindowClose(mine);
} catch (Exception e) {
Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
}
}
} catch (Exception e) {
Logger.error(e.toString());
}
}
public static void mineWindowOpen(Mine mine) {
mine.setActive(true);
ChatManager.chatSystemChannel(mine.getParentZone().getName() + "'s Mine is now Active!");
Logger.info(mine.getParentZone().getName() + "'s Mine is now Active!");
}
public static boolean mineWindowClose(Mine mine) {
// No need to end the window of a mine which never opened.
if (mine.isActive == false)
return false;
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
if (mineBuilding == null) {
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
return false;
}
for(Integer id : mine._playerMemory ){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
for(Integer id : mine._recentMemory.keySet()){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
// Mine building still stands; nothing to do.
// We can early exit here.
if (mineBuilding.getRank() > 0) {
mine.setActive(false);
mine.lastClaimer = null;
return true;
}
// This mine does not have a valid claimer
// we will therefore set it to errant
// and keep the window open.
if (!Mine.validateClaimer(mine.lastClaimer)) {
mine.lastClaimer = null;
mine.updateGuildOwner(null);
mine.setActive(true);
return false;
}
//Update ownership to map
mine.guildName = mine.getOwningGuild().getName();
mine.guildTag = mine.getOwningGuild().getGuildTag();
Guild nation = mine.getOwningGuild().getNation();
mine.nationName = nation.getName();
mine.nationTag = nation.getGuildTag();
mineBuilding.rebuildMine(mine.capSize * 5000);
WorldGrid.updateObject(mineBuilding);
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mine.lastClaimer.getName() + " has claimed the mine in " + mine.getParentZone().getName() + " for " + mine.getOwningGuild().getName() + ". The mine is no longer active.");
chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg);
// Warehouse this claim event
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
DataWarehouse.pushToWarehouse(mineRecord);
mineBuilding.setRank(mineBuilding.getRank());
mine.lastClaimer = null;
mine.setActive(false);
mine.wasClaimed = true;
return true;
}
public void run() { public void run() {
// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG // *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG

140
src/engine/workthreads/MineThread.java

@ -0,0 +1,140 @@
package engine.workthreads;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.net.DispatchMessage;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.Building;
import engine.objects.Guild;
import engine.objects.Mine;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
public class MineThread implements Runnable {
public MineThread(){
}
@Override
public void run() {
LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0);
while (true){
if(LocalDateTime.now().isAfter(nextPulse)) {
for (Mine mine : Mine.getMines()) {
if(nextPulse.getHour() == 2 && nextPulse.getMinute() == 0){
mine.wasClaimed = false;
mine.hasProduced = false;
}
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(30);
//current time is after start time and before close time, open mine window
if (LocalDateTime.now().isAfter(openTime.minusMinutes(1)) && !mine.wasClaimed) {
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 = LocalDateTime.now().plusMinutes(30);
}
}
}
public static void mineWindowOpen(Mine mine) {
mine.setActive(true);
ChatManager.chatSystemChannel(mine.getParentZone().getName() + "'s Mine is now Active!");
Logger.info(mine.getParentZone().getName() + "'s Mine is now Active!");
}
public static boolean mineWindowClose(Mine mine) {
// No need to end the window of a mine which never opened.
if (mine.isActive == false)
return false;
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
if (mineBuilding == null) {
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
return false;
}
for(Integer id : mine._playerMemory ){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
for(Integer id : mine._recentMemory.keySet()){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
// Mine building still stands; nothing to do.
// We can early exit here.
if (mineBuilding.getRank() > 0) {
mine.setActive(false);
mine.lastClaimer = null;
return true;
}
// This mine does not have a valid claimer
// we will therefore set it to errant
// and keep the window open.
if (!Mine.validateClaimer(mine.lastClaimer)) {
mine.lastClaimer = null;
mine.updateGuildOwner(null);
mine.setActive(true);
return false;
}
//Update ownership to map
mine.guildName = mine.getOwningGuild().getName();
mine.guildTag = mine.getOwningGuild().getGuildTag();
Guild nation = mine.getOwningGuild().getNation();
mine.nationName = nation.getName();
mine.nationTag = nation.getGuildTag();
mineBuilding.rebuildMine(mine.capSize * 5000);
WorldGrid.updateObject(mineBuilding);
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mine.lastClaimer.getName() + " has claimed the mine in " + mine.getParentZone().getName() + " for " + mine.getOwningGuild().getName() + ". The mine is no longer active.");
chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg);
// Warehouse this claim event
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
DataWarehouse.pushToWarehouse(mineRecord);
mineBuilding.setRank(mineBuilding.getRank());
mine.lastClaimer = null;
mine.setActive(false);
mine.wasClaimed = true;
return true;
}
}
Loading…
Cancel
Save