From 6b4eff4d4c27f9511bda5b7aac13c93e18665f53 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 12 Feb 2024 19:09:21 -0600 Subject: [PATCH] players removed when leaving mines --- src/engine/objects/Mine.java | 128 ++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 54 deletions(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index 04d1596f..9437fed1 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -54,8 +54,9 @@ public class Mine extends AbstractGameObject { public int capSize; - public HashMap> presentPlayers = new HashMap<>(); - public Integer totalPLayers; + public final HashSet _playerMemory = new HashSet<>(); + HashMap> dividedPlayers; + public Integer totalPlayers; /** * ResultSet Constructor @@ -593,79 +594,98 @@ public class Mine extends AbstractGameObject { public void onEnter() { HashSet currentPlayers; - HashSet 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 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> checkList) { - ArrayList allPlayers = new ArrayList<>(); - for(ArrayList 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 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 currentPlayers) { - HashSet 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 toRemove = new HashSet<>(); + Iterator 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; } } }