diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index ccdcb007..3b683ca8 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -10,10 +10,7 @@ package engine.gameManager; import engine.Enum; import engine.Enum.GameObjectType; -import engine.objects.AbstractGameObject; -import engine.objects.City; -import engine.objects.PlayerCharacter; -import engine.objects.Runegate; +import engine.objects.*; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -40,6 +37,7 @@ public enum SimulationManager { public static Duration executionMax = Duration.ofNanos(1); private static SimulationManager instance = null; private long _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; + private long _minePulseTime = System.currentTimeMillis() + CITY_PULSE; private long _runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE; private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE; @@ -126,7 +124,17 @@ public enum SimulationManager { e.printStackTrace(); } + try { + if ((_minePulseTime != 0) + && (System.currentTimeMillis() > _minePulseTime)) + pulseMines(); + } catch (Exception e) { + Logger.error( + "Fatal error in Mine Pulse: DISABLED. Error Message : " + + e.getMessage()); + e.printStackTrace(); + } SimulationManager.executionTime = Duration.between(startTime, Instant.now()); if (executionTime.compareTo(executionMax) > 0) @@ -203,7 +211,6 @@ public enum SimulationManager { city = (City) cityObject; city.onEnter(); } - _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; } @@ -220,4 +227,20 @@ public enum SimulationManager { _runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE; } + private void pulseMines(){ + Mine mine; + Collection mineList = DbManager.getList(Enum.GameObjectType.Mine); + + if (mineList == null) { + Logger.info("Mine List null"); + return; + } + + for (AbstractGameObject mineObject : mineList) { + mine = (Mine) mineObject; + mine.onEnter(); + } + + _minePulseTime = System.currentTimeMillis() + CITY_PULSE; + } } diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index ec7d8a5a..a4c4a1eb 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -24,7 +24,7 @@ import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; -import java.util.ArrayList; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -54,6 +54,9 @@ public class Mine extends AbstractGameObject { public int capSize; + public HashMap> presentPlayers = new HashMap<>(); + public Integer totalPLayers; + /** * ResultSet Constructor */ @@ -587,5 +590,66 @@ public class Mine extends AbstractGameObject { } return (int) totalModded; } + public void onEnter() { + + HashSet currentPlayers; + HashSet currentMemory; + PlayerCharacter player; + + // Gather current list of players within the zone bounds + Building building = BuildingManager.getBuilding(this.buildingID); + currentPlayers = WorldGrid.getObjectsInRangePartial(building.loc, Enum.CityBoundsType.ZONE.extents, MBServerStatics.MASK_PLAYER); + this.totalPLayers = currentPlayers.size(); + for (AbstractWorldObject playerObject : currentPlayers) { + + if (playerObject == null) + continue; + + player = (PlayerCharacter) playerObject; + Guild nation = player.getGuild().getNation(); + if(this.presentPlayers.containsKey(nation)) { + if (this.presentPlayers.get(nation).contains(player) == false) + { + this.presentPlayers.get(nation).add(player); + } + } else { + ArrayList present = new ArrayList<>(); + present.add(player); + this.presentPlayers.put(nation, present); + } + for(Guild guild : this.presentPlayers.keySet()) { + ChatManager.chatSystemInfo(player, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size()); + } + } + try { + onExit(); + } catch (Exception e) { + Logger.error(e.getMessage()); + } + } + + private void onExit() { + HashSet currentPlayers; + PlayerCharacter player; + Building building = BuildingManager.getBuilding(this.buildingID); + currentPlayers = WorldGrid.getObjectsInRangePartial(building.loc, Enum.CityBoundsType.ZONE.extents, MBServerStatics.MASK_PLAYER); + this.totalPLayers = currentPlayers.size(); + for (AbstractWorldObject playerObject : currentPlayers) { + + if (playerObject == null) + continue; + player = (PlayerCharacter) playerObject; + Guild nation = player.getGuild().getNation(); + if(this.presentPlayers.containsKey(nation)) { + if (this.presentPlayers.get(nation).contains(player) == false) + { + this.presentPlayers.get(nation).remove(player); + } + } + for(Guild guild : this.presentPlayers.keySet()) { + ChatManager.chatSystemInfo(player, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size()); + } + } + } }