Browse Source

Mines calculate local players by guild

lakebane-master
FatBoy-DOTC 10 months ago
parent
commit
8f2847a527
  1. 33
      src/engine/gameManager/SimulationManager.java
  2. 66
      src/engine/objects/Mine.java

33
src/engine/gameManager/SimulationManager.java

@ -10,10 +10,7 @@ package engine.gameManager;
import engine.Enum; import engine.Enum;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.objects.AbstractGameObject; import engine.objects.*;
import engine.objects.City;
import engine.objects.PlayerCharacter;
import engine.objects.Runegate;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -40,6 +37,7 @@ public enum SimulationManager {
public static Duration executionMax = Duration.ofNanos(1); public static Duration executionMax = Duration.ofNanos(1);
private static SimulationManager instance = null; private static SimulationManager instance = null;
private long _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; private long _cityPulseTime = System.currentTimeMillis() + CITY_PULSE;
private long _minePulseTime = System.currentTimeMillis() + CITY_PULSE;
private long _runegatePulseTime = System.currentTimeMillis() private long _runegatePulseTime = System.currentTimeMillis()
+ RUNEGATE_PULSE; + RUNEGATE_PULSE;
private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE; private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE;
@ -126,7 +124,17 @@ public enum SimulationManager {
e.printStackTrace(); 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()); SimulationManager.executionTime = Duration.between(startTime, Instant.now());
if (executionTime.compareTo(executionMax) > 0) if (executionTime.compareTo(executionMax) > 0)
@ -203,7 +211,6 @@ public enum SimulationManager {
city = (City) cityObject; city = (City) cityObject;
city.onEnter(); city.onEnter();
} }
_cityPulseTime = System.currentTimeMillis() + CITY_PULSE; _cityPulseTime = System.currentTimeMillis() + CITY_PULSE;
} }
@ -220,4 +227,20 @@ public enum SimulationManager {
_runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE; _runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE;
} }
private void pulseMines(){
Mine mine;
Collection<AbstractGameObject> 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;
}
} }

66
src/engine/objects/Mine.java

@ -24,7 +24,7 @@ import java.net.UnknownHostException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -54,6 +54,9 @@ public class Mine extends AbstractGameObject {
public int capSize; public int capSize;
public HashMap<Guild,ArrayList<PlayerCharacter>> presentPlayers = new HashMap<>();
public Integer totalPLayers;
/** /**
* ResultSet Constructor * ResultSet Constructor
*/ */
@ -587,5 +590,66 @@ public class Mine extends AbstractGameObject {
} }
return (int) totalModded; return (int) totalModded;
} }
public void onEnter() {
HashSet<AbstractWorldObject> currentPlayers;
HashSet<Integer> 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<PlayerCharacter> 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<AbstractWorldObject> 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());
}
}
}
} }

Loading…
Cancel
Save