|
|
@ -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 (_playerMemory.contains(player.getObjectUUID())) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
if(this.presentPlayers.containsKey(nation)) { |
|
|
|
// Add player to our city's memory
|
|
|
|
if (this.presentPlayers.get(nation).contains(player) == false) |
|
|
|
|
|
|
|
{ |
|
|
|
_playerMemory.add(player.getObjectUUID()); |
|
|
|
this.presentPlayers.get(nation).add(player); |
|
|
|
updated = true; |
|
|
|
added = 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{ |
|
|
|
} else{ |
|
|
|
ArrayList<PlayerCharacter> present = new ArrayList<>(); |
|
|
|
entry = Guild.getErrantGuild(); |
|
|
|
present.add(player); |
|
|
|
|
|
|
|
this.presentPlayers.put(nation, present); |
|
|
|
|
|
|
|
added = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(added) |
|
|
|
if(this.dividedPlayers.containsKey(entry)){ |
|
|
|
for(Guild guild : this.presentPlayers.keySet()) { |
|
|
|
this.dividedPlayers.get(entry).add(playerID); |
|
|
|
ChatManager.chatSystemInfo(player, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size()); |
|
|
|
}else{ |
|
|
|
|
|
|
|
ArrayList<Integer> newEntry = new ArrayList<>(); |
|
|
|
|
|
|
|
newEntry.add(playerID); |
|
|
|
|
|
|
|
this.dividedPlayers.put(entry,newEntry); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
if(updated == true){ |
|
|
|
onExit(this.presentPlayers); |
|
|
|
for(Integer playerID : this._playerMemory){ |
|
|
|
} catch (Exception e) { |
|
|
|
player = PlayerCharacter.getFromCache(playerID); |
|
|
|
Logger.error(e.getMessage()); |
|
|
|
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; |
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player = PlayerCharacter.getFromCache(playerUUID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPlayers.contains(player)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toRemove.add(playerUUID); |
|
|
|
} |
|
|
|
} |
|
|
|
if(updated) |
|
|
|
|
|
|
|
for (Guild guild : this.presentPlayers.keySet()) { |
|
|
|
// Remove players from mine memory
|
|
|
|
ChatManager.chatSystemInfo(playerObject, "Guild: " + guild.getName() + " COUNT: " + presentPlayers.get(guild).size()); |
|
|
|
|
|
|
|
} |
|
|
|
_playerMemory.removeAll(toRemove); |
|
|
|
|
|
|
|
if(toRemove.isEmpty()){ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|