diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index ccdcb007..fe7ec7e6 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -10,10 +10,7 @@ package engine.gameManager; import engine.Enum; import engine.Enum.GameObjectType; -import engine.objects.AbstractGameObject; -import engine.objects.City; -import engine.objects.PlayerCharacter; -import engine.objects.Runegate; +import engine.objects.*; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -33,7 +30,7 @@ public enum SimulationManager { SERVERHEARTBEAT; private static final long CITY_PULSE = 2000; - private static final long RUNEGATE_PULSE = 3000; + private static final long RUNEGATE_PULSE = 1000; private static final long UPDATE_PULSE = 1000; private static final long FlIGHT_PULSE = 100; public static Duration executionTime = Duration.ofNanos(1); @@ -203,8 +200,12 @@ public enum SimulationManager { city = (City) cityObject; city.onEnter(); } - + for(Mine mine : Mine.getMines()){ + if(mine != null) + mine.onEnter(); + } _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; + } /* diff --git a/src/engine/gameManager/ZergManager.java b/src/engine/gameManager/ZergManager.java new file mode 100644 index 00000000..9afc2eb7 --- /dev/null +++ b/src/engine/gameManager/ZergManager.java @@ -0,0 +1,92 @@ +package engine.gameManager; +import engine.objects.Guild; +public class ZergManager { + + public static float getCurrentMultiplier(int count, int maxCount){ + switch(maxCount) { + case 3: + return getMultiplier3Man(count); + case 5: + return getMultiplier5Man(count); + case 10: + return getMultiplier10Man(count); + default: + return getMultiplier20Man(count); + } + } + public static float getMultiplier3Man(int count) { + if(count < 4) + return 1.0f; + + if(count > 6) + return 0.0f; + + switch(count){ + case 4: + return 0.75f; + case 5: + return 0.60f; + case 6: + return 0.37f; + + } + return 1.0f; + } + public static float getMultiplier5Man(int count) { + if(count < 6) + return 1.0f; + + if(count > 10) + return 0.0f; + + switch(count){ + case 6: + return 0.75f; + case 7: + return 0.67f; + case 8: + return 0.56f; + case 9: + return 0.43f; + case 10: + return 0.25f; + + } + return 1.0f; + } + public static float getMultiplier10Man(int count) { + if(count < 11) + return 1.0f; + + if(count > 20) + return 0.0f; + + switch(count){ + case 11: + return 0.75f; + case 12: + return 0.71f; + case 13: + return 0.67f; + case 14: + return 0.62f; + case 15: + return 0.56f; + case 16: + return 0.50f; + case 17: + return 0.43f; + case 18: + return 0.35f; + case 19: + return 0.25f; + case 20: + return 0.14f; + + } + return 1.0f; + } + public static float getMultiplier20Man(int count) { + return getMultiplier10Man(count * 2); + } +} diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index e600e476..e94baf2f 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -11,10 +11,7 @@ package engine.objects; import engine.Enum; import engine.InterestManagement.WorldGrid; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.ZoneManager; +import engine.gameManager.*; import engine.net.ByteBufferWriter; import engine.net.client.msg.ErrorPopupMsg; import engine.server.MBServerStatics; @@ -25,6 +22,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import static engine.gameManager.DbManager.MineQueries; @@ -55,6 +55,8 @@ public class Mine extends AbstractGameObject { public int openMinute; public int capSize; public LocalDateTime liveTime; + public final HashSet _playerMemory = new HashSet<>(); + public ArrayList affectedPlayers = new ArrayList<>(); /** * ResultSet Constructor @@ -570,5 +572,75 @@ public class Mine extends AbstractGameObject { } return (int) totalModded; } + public void onEnter() { + Building tower = BuildingManager.getBuildingFromCache(this.buildingID); + if(tower == null) + return; + + // Gather current list of players within the zone bounds + + HashSet currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents, MBServerStatics.MASK_PLAYER); + HashMap> charactersByNation = new HashMap<>(); + ArrayList updatedNations = new ArrayList<>(); + for (AbstractWorldObject playerObject : currentPlayers) { + + if (playerObject == null) + continue; + + PlayerCharacter player = (PlayerCharacter) playerObject; + if(!this._playerMemory.contains(player.getObjectUUID())){ + this._playerMemory.add(player.getObjectUUID()); + } + Guild nation = player.guild.getNation(); + if(charactersByNation.containsKey(nation)){ + if(!charactersByNation.get(nation).contains(player)) { + charactersByNation.get(nation).add(player); + if(!updatedNations.contains(nation)){ + updatedNations.add(nation); + } + } + }else{ + ArrayList players = new ArrayList<>(); + players.add(player); + charactersByNation.put(nation,players); + if(!updatedNations.contains(nation)){ + updatedNations.add(nation); + } + } + } + for(Guild nation : updatedNations){ + float multiplier = ZergManager.getCurrentMultiplier(charactersByNation.get(nation).size(),this.capSize); + for(PlayerCharacter player : charactersByNation.get(nation)){ + player.ZergMultiplier = multiplier; + } + } + try + { + this.onExit(this._playerMemory); + } + catch(Exception ignored){ + + } + } + + private void onExit(HashSet currentMemory) { + + Building tower = BuildingManager.getBuildingFromCache(this.buildingID); + if(tower == null) + return; + ArrayListtoRemove = new ArrayList<>(); + HashSet currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents, MBServerStatics.MASK_PLAYER); + for(Integer id : currentMemory){ + PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(id); + if(currentPlayers.contains(pc) == false){ + toRemove.add(id); + pc.ZergMultiplier = 1.0f; + } + } + + // Remove players from city memory + + _playerMemory.removeAll(toRemove); + } } diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 35dd8c5a..c2bda26b 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -175,6 +175,8 @@ public class PlayerCharacter extends AbstractCharacter { private boolean dirtyLoad = true; private final ReadWriteLock dirtyLock = new ReentrantReadWriteLock(true); + public float ZergMultiplier = 1.0f; + /** * No Id Constructor */