|
|
|
@ -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(this.presentPlayers.containsKey(nation)) { |
|
|
|
|
if (this.presentPlayers.get(nation).contains(player) == false) |
|
|
|
|
{ |
|
|
|
|
this.presentPlayers.get(nation).add(player); |
|
|
|
|
added = true; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
ArrayList<PlayerCharacter> present = new ArrayList<>(); |
|
|
|
|
present.add(player); |
|
|
|
|
this.presentPlayers.put(nation, present); |
|
|
|
|
added = true; |
|
|
|
|
} |
|
|
|
|
if(added) |
|
|
|
|
for(Guild guild : this.presentPlayers.keySet()) { |
|
|
|
|
ChatManager.chatSystemInfo(player, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size()); |
|
|
|
|
} |
|
|
|
|
if (_playerMemory.contains(player.getObjectUUID())) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
// 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 { |
|
|
|
|
onExit(this.presentPlayers); |
|
|
|
|
if(onExit(currentPlayers)){ |
|
|
|
|
updated = true; |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
Logger.error(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onExit(HashMap<Guild,ArrayList<PlayerCharacter>> checkList) { |
|
|
|
|
ArrayList<PlayerCharacter> allPlayers = new ArrayList<>(); |
|
|
|
|
for(ArrayList<PlayerCharacter> players: presentPlayers.values()){ |
|
|
|
|
allPlayers.addAll(players); |
|
|
|
|
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{ |
|
|
|
|
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; |
|
|
|
|
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()) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if(updated) |
|
|
|
|
for (Guild guild : this.presentPlayers.keySet()) { |
|
|
|
|
ChatManager.chatSystemInfo(playerObject, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size()); |
|
|
|
|
} |
|
|
|
|
playerUUID = iter.next(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|