Browse Source

players removed when leaving mines

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

128
src/engine/objects/Mine.java

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

Loading…
Cancel
Save