Browse Source

collection of players for cities and mines

lakebane-master
FatBoy-DOTC 9 months ago
parent
commit
5287b993fa
  1. 8
      src/engine/gameManager/PowersManager.java
  2. 38
      src/engine/gameManager/SimulationManager.java
  3. 5
      src/engine/objects/City.java
  4. 70
      src/engine/objects/Mine.java

8
src/engine/gameManager/PowersManager.java

@ -56,6 +56,9 @@ public enum PowersManager { @@ -56,6 +56,9 @@ public enum PowersManager {
public static HashMap<Integer, ArrayList<MobPowerEntry>> AllMobPowers;
private static JobScheduler js;
public static String[] siegeBuffs = new String[]{"ART-004A","ARM-112A"};
public static String[] siegeDeBuffs = new String[]{"ACM-003A","WRT-003A"};
private PowersManager() {
}
@ -2707,7 +2710,12 @@ public enum PowersManager { @@ -2707,7 +2710,12 @@ public enum PowersManager {
}
}
}
public static void applyZergBuff(AbstractGameObject obj){
}
public static void removeZergBuff(HashSet<Integer> playersIDs){
}
}

38
src/engine/gameManager/SimulationManager.java

@ -10,10 +10,7 @@ package engine.gameManager; @@ -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;
@ -33,6 +30,7 @@ public enum SimulationManager { @@ -33,6 +30,7 @@ public enum SimulationManager {
SERVERHEARTBEAT;
private static final long CITY_PULSE = 2000;
private static final long MINE_PULSE = 2000;
private static final long RUNEGATE_PULSE = 3000;
private static final long UPDATE_PULSE = 1000;
private static final long FlIGHT_PULSE = 100;
@ -40,6 +38,7 @@ public enum SimulationManager { @@ -40,6 +38,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() + MINE_PULSE;
private long _runegatePulseTime = System.currentTimeMillis()
+ RUNEGATE_PULSE;
private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE;
@ -126,7 +125,17 @@ public enum SimulationManager { @@ -126,7 +125,17 @@ public enum SimulationManager {
e.printStackTrace();
}
try {
if ((_minePulseTime != 0)
&& (System.currentTimeMillis() > _minePulseTime))
pulseMines();
} catch (Exception e) {
Logger.error(
"Fatal error in City Pulse: DISABLED. Error Message : "
+ e.getMessage());
e.printStackTrace();
}
SimulationManager.executionTime = Duration.between(startTime, Instant.now());
if (executionTime.compareTo(executionMax) > 0)
@ -206,7 +215,28 @@ public enum SimulationManager { @@ -206,7 +215,28 @@ public enum SimulationManager {
_cityPulseTime = System.currentTimeMillis() + CITY_PULSE;
}
private void pulseMines() {
Mine mine;
// *** Refactor: Need a list cached somewhere as it doesn't change very
// often at all. Have a cityListIsDirty boolean that gets set if it
// needs an update. Will speed up this method a great deal.
Collection<AbstractGameObject> mineList = DbManager.getList(Enum.GameObjectType.Mine);
if (mineList == null) {
Logger.info("City List null");
return;
}
for (AbstractGameObject mineObject : mineList) {
mine = (Mine) mineObject;
mine.onEnter();
}
_minePulseTime = System.currentTimeMillis() + MINE_PULSE;
}
/*
* Method runs proximity collision detection for all active portals on the
* game's Runegates

5
src/engine/objects/City.java

@ -986,7 +986,7 @@ public class City extends AbstractWorldObject { @@ -986,7 +986,7 @@ public class City extends AbstractWorldObject {
// Gather current list of players within the zone bounds
currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, CityBoundsType.ZONE.extents, MBServerStatics.MASK_PLAYER);
currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, CityBoundsType.ZONE.extents * 2, MBServerStatics.MASK_PLAYER);
currentMemory = new HashSet<>();
for (AbstractWorldObject playerObject : currentPlayers) {
@ -1025,7 +1025,7 @@ public class City extends AbstractWorldObject { @@ -1025,7 +1025,7 @@ public class City extends AbstractWorldObject {
} catch (Exception e) {
Logger.error(e.getMessage());
}
PowersManager.applyZergBuff(this);
}
private void onExit(HashSet<Integer> currentMemory) {
@ -1069,6 +1069,7 @@ public class City extends AbstractWorldObject { @@ -1069,6 +1069,7 @@ public class City extends AbstractWorldObject {
if (this.cityOutlaws.contains(removalUUID))
this.cityOutlaws.remove(removalUUID);
}
PowersManager.removeZergBuff(toRemove);
}
public int getWarehouseBuildingID() {

70
src/engine/objects/Mine.java

@ -11,10 +11,7 @@ package engine.objects; @@ -11,10 +11,7 @@ package engine.objects;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.gameManager.*;
import engine.net.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg;
import engine.server.MBServerStatics;
@ -25,6 +22,8 @@ import java.sql.ResultSet; @@ -25,6 +22,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import static engine.gameManager.DbManager.MineQueries;
@ -33,6 +32,7 @@ import static engine.math.FastMath.sqr; @@ -33,6 +32,7 @@ import static engine.math.FastMath.sqr;
public class Mine extends AbstractGameObject {
public final HashSet<Integer> _playerMemory = new HashSet<>();
public static ConcurrentHashMap<Mine, Integer> mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public static ConcurrentHashMap<Integer, Mine> towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
private final String zoneName;
@ -574,5 +574,67 @@ public class Mine extends AbstractGameObject { @@ -574,5 +574,67 @@ public class Mine extends AbstractGameObject {
}
return (int) totalModded;
}
public void onEnter() {
HashSet<AbstractWorldObject> currentPlayers;
HashSet<Integer> currentMemory;
PlayerCharacter player;
// Gather current list of players within the zone bounds
currentPlayers = WorldGrid.getObjectsInRangePartial(BuildingManager.getBuildingFromCache(this.buildingID).loc, Enum.CityBoundsType.ZONE.extents, MBServerStatics.MASK_PLAYER);
currentMemory = new HashSet<>();
for (AbstractWorldObject playerObject : currentPlayers) {
if (playerObject == null)
continue;
player = (PlayerCharacter) playerObject;
currentMemory.add(player.getObjectUUID());
// Player is already in our memory
if (_playerMemory.contains(player.getObjectUUID()))
continue;
// Add player to our city's memory
_playerMemory.add(player.getObjectUUID());
// ***For debugging
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
}
try {
onExit(currentMemory);
} catch (Exception e) {
Logger.error(e.getMessage());
}
PowersManager.applyZergBuff(this);
}
private void onExit(HashSet<Integer> currentMemory) {
PlayerCharacter player;
int playerUUID = 0;
HashSet<Integer> toRemove = new HashSet<>();
Iterator<Integer> iter = _playerMemory.iterator();
HashSet<AbstractWorldObject> inRange = WorldGrid.getObjectsInRangePartial(BuildingManager.getBuildingFromCache(this.buildingID).loc,Enum.CityBoundsType.ZONE.extents * 0.5f,MBServerStatics.MASK_PLAYER);
while (iter.hasNext()) {
playerUUID = iter.next();
player = PlayerCharacter.getFromCache(playerUUID);
if (inRange.contains(player))
continue;
toRemove.add(playerUUID);
}
// Remove players from mine memory
_playerMemory.removeAll(toRemove);
PowersManager.removeZergBuff(toRemove);
}
}

Loading…
Cancel
Save