Browse Source

players removed when leaving mines

lakebane-master
FatBoy-DOTC 9 months ago
parent
commit
6b4eff4d4c
  1. 122
      src/engine/objects/Mine.java

122
src/engine/objects/Mine.java

@ -54,8 +54,9 @@ public class Mine extends AbstractGameObject { @@ -54,8 +54,9 @@ public class Mine extends AbstractGameObject {
public int capSize;
public HashMap<Guild,ArrayList<PlayerCharacter>> presentPlayers = new HashMap<>();
public Integer totalPLayers;
public final HashSet<Integer> _playerMemory = new HashSet<>();
HashMap<Guild,ArrayList<Integer>> dividedPlayers;
public Integer totalPlayers;
/**
* ResultSet Constructor
@ -593,79 +594,98 @@ public class Mine extends AbstractGameObject { @@ -593,79 +594,98 @@ public class Mine extends AbstractGameObject {
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();
boolean added = false;
Building tower = BuildingManager.getBuildingFromCache(this.buildingID);
currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents, MBServerStatics.MASK_PLAYER);
boolean updated = false;
for (AbstractWorldObject playerObject : currentPlayers) {
if (playerObject == null)
continue;
player = (PlayerCharacter) playerObject;
Guild nation = player.getGuild().getNation();
if(nation == null)
return;
// Player is already in our memory
if (_playerMemory.contains(player.getObjectUUID()))
continue;
if(this.presentPlayers.containsKey(nation)) {
if (this.presentPlayers.get(nation).contains(player) == false)
{
this.presentPlayers.get(nation).add(player);
added = true;
// Add player to our city's memory
_playerMemory.add(player.getObjectUUID());
updated = true;
// ***For debugging
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
}
this.totalPlayers = this._playerMemory.size();
try {
if(onExit(currentPlayers)){
updated = true;
}
} catch (Exception e) {
Logger.error(e.getMessage());
}
this.dividedPlayers = new HashMap<>();
for(Integer playerID : this._playerMemory){
player = PlayerCharacter.getFromCache(playerID);
Guild guild = player.getGuild();
Guild nation = guild.getNation();
Guild entry;
if(nation.equals(Guild.getErrantGuild())){
entry = nation;
}else if(guild.equals(Guild.getErrantGuild())){
entry = guild;
} else{
ArrayList<PlayerCharacter> present = new ArrayList<>();
present.add(player);
this.presentPlayers.put(nation, present);
added = true;
entry = Guild.getErrantGuild();
}
if(added)
for(Guild guild : this.presentPlayers.keySet()) {
ChatManager.chatSystemInfo(player, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size());
if(this.dividedPlayers.containsKey(entry)){
this.dividedPlayers.get(entry).add(playerID);
}else{
ArrayList<Integer> newEntry = new ArrayList<>();
newEntry.add(playerID);
this.dividedPlayers.put(entry,newEntry);
}
}
try {
onExit(this.presentPlayers);
} catch (Exception e) {
Logger.error(e.getMessage());
if(updated == true){
for(Integer playerID : this._playerMemory){
player = PlayerCharacter.getFromCache(playerID);
for(Guild present : this.dividedPlayers.keySet()) {
ChatManager.chatSystemInfo(player,present.getName() + "COUNT: " + this.dividedPlayers.get(present).size() + " (" + (this.dividedPlayers.get(present).size()/this.totalPlayers * 100) + "%)");
}
}
}
private void onExit(HashMap<Guild,ArrayList<PlayerCharacter>> checkList) {
ArrayList<PlayerCharacter> allPlayers = new ArrayList<>();
for(ArrayList<PlayerCharacter> players: presentPlayers.values()){
allPlayers.addAll(players);
}
boolean updated = false;
private Boolean onExit(HashSet<AbstractWorldObject> currentPlayers) {
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 (PlayerCharacter playerObject : allPlayers) {
if (currentPlayers.contains(playerObject) == false) {
Guild nation = playerObject.getGuild().getNation();
if (this.presentPlayers.containsKey(nation)) {
if (this.presentPlayers.get(nation).contains(playerObject) == true) {
this.presentPlayers.get(nation).remove(playerObject);
updated = true;
ChatManager.chatSystemInfo(playerObject,"Leaving Mine Vicinity");
}
}
int playerUUID = 0;
HashSet<Integer> toRemove = new HashSet<>();
Iterator<Integer> iter = _playerMemory.iterator();
while (iter.hasNext()) {
playerUUID = iter.next();
player = PlayerCharacter.getFromCache(playerUUID);
if (currentPlayers.contains(player))
continue;
toRemove.add(playerUUID);
}
if(updated)
for (Guild guild : this.presentPlayers.keySet()) {
ChatManager.chatSystemInfo(playerObject, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size());
}
// Remove players from mine memory
_playerMemory.removeAll(toRemove);
if(toRemove.isEmpty()){
return false;
}else{
return true;
}
}
}

Loading…
Cancel
Save