From f98f54139a8036af44c93655c847c093c7d3634a Mon Sep 17 00:00:00 2001 From: fatboy Date: Wed, 17 Apr 2024 20:46:59 -0500 Subject: [PATCH] Threads for Zerg Mechanics --- src/engine/gameManager/CombatManager.java | 2 +- src/engine/gameManager/ZergManager.java | 281 ++++-------------- src/engine/objects/Bane.java | 19 +- src/engine/objects/City.java | 137 +-------- .../effectmodifiers/HealthEffectModifier.java | 4 +- .../effectmodifiers/ManaEffectModifier.java | 4 +- .../StaminaEffectModifier.java | 4 +- .../workthreads/ZergMechanicThread.java | 50 +++- 8 files changed, 122 insertions(+), 379 deletions(-) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 06dfff7e..7f9fd45f 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -845,7 +845,7 @@ public enum CombatManager { mobTarget.handleDirectAggro(ac); } if(ac.getObjectType().equals(GameObjectType.PlayerCharacter) && tarAc.getObjectType().equals(GameObjectType.PlayerCharacter) && tarAc.equals(ac) == false){ - damage *= ZergManager.getReducedZergMultiplier(ac,tarAc); + damage *= ((PlayerCharacter)ac).ZergMultiplier; } if (tarAc.getHealth() > 0) d = tarAc.modifyHealth(-damage, ac, false); diff --git a/src/engine/gameManager/ZergManager.java b/src/engine/gameManager/ZergManager.java index 069f8175..4c45300d 100644 --- a/src/engine/gameManager/ZergManager.java +++ b/src/engine/gameManager/ZergManager.java @@ -1,273 +1,108 @@ package engine.gameManager; -import engine.Enum; -import engine.objects.*; - public class ZergManager { - public static float getMultiplier5Man(int count, PlayerCharacter pc){ + + public static float getMultiplier3Man(int count){ float multiplier = 1.0f; + + if(count <= 3) + return 1.0f; + + if(count > 6) + return 0.2f; + switch(count){ - case 1: - multiplier += 0.80f; - break; - case 2: - multiplier += 0.80f; - break; - case 3: - multiplier += 0.50f; - break; case 4: - multiplier += 0.20f; + multiplier -= 0.37f; break; case 5: - multiplier += 0.0f; - break; - case 6: - multiplier -= 0.20f; - break; - case 7: - multiplier -= 0.40f; - break; - case 8: multiplier -= 0.60f; break; - default: - multiplier -= 0.80f; + case 6: + multiplier -= 0.75f; break; } - if(multiplier == 0.0f) - return 1.0f; - else - return multiplier; + return multiplier; } - public static float getMultiplier10Man(int count, PlayerCharacter pc){ + + public static float getMultiplier5Man(int count){ float multiplier = 1.0f; - if(count <=4) - return 0.0f; + + if(count <= 5) + return 1.0f; + + if(count > 10) + return 0.2f; + switch(count){ - case 5: - multiplier += 0.5f; - break; case 6: - multiplier += 0.4f; + multiplier -= 0.25f; break; case 7: - multiplier += 0.3f; + multiplier -= 0.43f; break; case 8: - multiplier += 0.2f; + multiplier -= 0.56f; break; case 9: - multiplier += 0.1f; + multiplier -= 0.67f; break; case 10: - multiplier += 0.0f; + multiplier -= 0.75f; break; + } + return multiplier; + } + + public static float getMultiplier10Man(int count){ + float multiplier = 1.0f; + + if(count <= 10) + return 1.0f; + + if(count > 20) + return 0.2f; + + switch(count){ case 11: - multiplier -= 0.1f; + multiplier -= 0.14f; break; case 12: - multiplier -= 0.2f; + multiplier -= 0.25f; break; case 13: - multiplier -= 0.3f; + multiplier -= 0.35f; break; case 14: - multiplier -= 0.4f; + multiplier -= 0.43f; break; case 15: - multiplier -= 0.5f; + multiplier -= 0.50f; break; case 16: - multiplier -= 0.65f; + multiplier -= 0.56f; break; case 17: - multiplier -= 0.75f; + multiplier -= 0.62f; break; case 18: - multiplier -= 0.85f; + multiplier -= 0.67f; break; - default: - multiplier -= 1.0f; + case 19: + multiplier -= 0.71f; break; - } - ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier); - if(multiplier == 0.0f) - return 1.0f; - else - return multiplier; - } - public static float getMultiplier20Man(int count, PlayerCharacter pc){ - float multiplier = 1.0f; - if(count < 10){ - multiplier += 1.25f; - }else { - switch (count) { - case 10: - multiplier += 0.8f; - break; - case 11: - multiplier += 0.65f; - break; - case 12: - multiplier += 0.54f; - break; - case 13: - multiplier += 0.46f; - break; - case 14: - multiplier += 0.36f; - break; - case 15: - multiplier += 0.28f; - break; - case 16: - multiplier += 0.21f; - break; - case 17: - multiplier += 0.15f; - break; - case 18: - multiplier += 0.09f; - break; - case 19: - multiplier += 0.04f; - break; - case 20: - multiplier += 0.00f; - break; - case 21: - multiplier -= 0.04f; - break; - case 22: - multiplier -= 0.09f; - break; - case 23: - multiplier -= 0.15f; - break; - case 24: - multiplier -= 0.21f; - break; - case 25: - multiplier -= 0.28f; - break; - case 26: - multiplier -= 0.36f; - break; - case 27: - multiplier -= 0.46f; - break; - case 28: - multiplier -= 0.54f; - break; - case 29: - multiplier -= 0.65f; - break; - default: - multiplier -= 0.75f; - break; - } - } - ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier); - if(multiplier == 0.0f) - return 1.0f; - else - return multiplier; - } - public static int getBaneCapSize(Guild defender){ - int treesInNation = defender.getNation().getSubGuildList().size() + 1; - int capSize; - switch(treesInNation){ - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - capSize = 20; - break; - case 7: - case 8: - case 9: - case 10: - capSize = 30; - break; - case 11: - case 12: - case 13: - case 14: - capSize = 40; + case 20: + multiplier -= 0.75f; break; - default: capSize = 9999999; } - return capSize; - } - public static float getMultiplier30Man(int count, PlayerCharacter pc){ - float multiplier = 1.0f; - - ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier); - if(multiplier == 0.0f) - return 1.0f; - else - return multiplier; - } - public static float getMultiplier40Man(int count, PlayerCharacter pc){ - float multiplier = 1.0f; - - ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier); - if(multiplier == 0.0f) - return 1.0f; - else - return multiplier; + return multiplier; } - public static float getMultiplierUnlimited(int count, PlayerCharacter pc){ - float multiplier = 1.0f; - ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier); - if(multiplier == 0.0f) - return 1.0f; - else - return multiplier; + public static float getMultiplier20Man(int count){ + return getMultiplier10Man(((int)(count * 0.5f))); } - public static float getReducedZergMultiplier(AbstractCharacter sourceABS, AbstractCharacter targetABS){ - if(sourceABS.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) == false || targetABS.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) == false) - return 1.0f; - - PlayerCharacter source = (PlayerCharacter) sourceABS; - PlayerCharacter target = (PlayerCharacter) targetABS; - - if(source.ZergMultiplier == 0.0f) { - if(Mine.getMine(source.mineAppliedID) != null && Mine.getMine(source.mineAppliedID)._playerMemory.contains(source.getObjectUUID()) == false ){ - source.ZergMultiplier = 1.0f; - } - } - if(target.ZergMultiplier == 0.0f) { - if(Mine.getMine(target.mineAppliedID) != null && Mine.getMine(target.mineAppliedID)._playerMemory.contains(target.getObjectUUID()) == false){ - target.ZergMultiplier = 1.0f; - } - } - if(source.ZergMultiplier == target.ZergMultiplier){ - return 1.0f; - } - float returnMultiplier = 1.0f; - if(source.ZergMultiplier > 0 && target.ZergMultiplier > 0){ - if(source.ZergMultiplier > target.ZergMultiplier) { - returnMultiplier = 1 + (source.ZergMultiplier - target.ZergMultiplier); - } else{ - returnMultiplier = 1.0f; - } - }else if(source.ZergMultiplier < 0 && target.ZergMultiplier > 0){ - returnMultiplier = source.ZergMultiplier; - } else if(source.ZergMultiplier < 0 && target.ZergMultiplier < 0){ - returnMultiplier = source.ZergMultiplier; - } else if(source.ZergMultiplier > 0 && target.ZergMultiplier < 0){ - returnMultiplier = source.ZergMultiplier; - } - if(returnMultiplier == 0.0f) - return 1.0f; - else{ - return returnMultiplier; - } + public static float getMultiplier40Man(int count){ + return getMultiplier10Man(((int)(count * 0.25f))); } } diff --git a/src/engine/objects/Bane.java b/src/engine/objects/Bane.java index b074647b..058073ce 100644 --- a/src/engine/objects/Bane.java +++ b/src/engine/objects/Bane.java @@ -106,7 +106,11 @@ public final class Bane { if (this.liveDate == null) setDefaultTime(); - this.capSize = ZergManager.getBaneCapSize(this.getCity().getGuild()); + if(this.getCity().getTOL().getRank() == 8) + this.capSize = 40; + else + this.capSize = 20; + this.getCity().setSiegesWithstood(this.capSize); } @@ -268,7 +272,11 @@ public final class Bane { BaneRecord baneRecord = BaneRecord.borrow(bane, Enum.RecordEventType.PENDING); DataWarehouse.pushToWarehouse(baneRecord); - bane.capSize = ZergManager.getBaneCapSize(bane.getCity().getGuild()); + if(bane.getCity().getTOL().getRank() == 8) + bane.capSize = 40; + else + bane.capSize = 20; + bane.getCity().setSiegesWithstood(bane.capSize); return true; } @@ -345,7 +353,12 @@ public final class Bane { } newBane = DbManager.BaneQueries.LOAD_BANE(city.getObjectUUID()); - newBane.capSize = ZergManager.getBaneCapSize(newBane.getCity().getGuild()); + + if(newBane.getCity().getTOL().getRank() == 8) + newBane.capSize = 40; + else + newBane.capSize = 20; + newBane.getCity().setSiegesWithstood(newBane.capSize); return newBane; } diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 455508dc..1a92017a 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -326,7 +326,10 @@ public class City extends AbstractWorldObject { if(city.getBane() != null) { writer.putInt(city.siegesWithstood); } else{ - writer.putInt(ZergManager.getBaneCapSize(city.getGuild())); + if(city.getTOL().getRank() == 8) + writer.putInt(40); + else + writer.putInt(20); } writer.put((byte) 1); writer.put((byte) 0); @@ -989,8 +992,6 @@ public class City extends AbstractWorldObject { public void onEnter() { - this.onEnterZerg(); - for (Integer id : this._playerMemory) { PlayerCharacter player = PlayerCharacter.getFromCache(id); @@ -1385,134 +1386,4 @@ public class City extends AbstractWorldObject { return true; } - public void onEnterZerg() { - - if(this.getBane() == null || this.getBane().getLiveDate().dayOfWeek() != DateTime.now().dayOfWeek() || this.getBane().getLiveDate().hourOfDay().get() < DateTime.now().hourOfDay().get() - 1) - return; - HashSet currentPlayers; - PlayerCharacter player; - - // Gather current list of players within the zone bounds - Building tower = this.getTOL(); - currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents * 2, MBServerStatics.MASK_PLAYER); - boolean updated = false; - - for (AbstractWorldObject playerObject : currentPlayers) { - - if (playerObject == null) - continue; - - player = (PlayerCharacter) playerObject; - - // Player is already in our memory - if (_recentMemory.containsKey(player.getObjectUUID())) - _recentMemory.remove(player.getObjectUUID()); - - 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 { - if(onExitZerg(currentPlayers)){ - updated = true; - } - } catch (Exception e) { - Logger.error(e.getMessage()); - } - this.dividedPlayers = new HashMap<>(); - for(Integer playerID : this._playerMemory){ - player = PlayerCharacter.getFromCache(playerID); - Guild nation = player.getGuild().getNation(); Guild entry; - if(this.dividedPlayers.containsKey(nation)){ - this.dividedPlayers.get(nation).add(playerID); - }else{ - ArrayList newEntry = new ArrayList<>(); - newEntry.add(playerID); - this.dividedPlayers.put(nation,newEntry); - } - } - if(updated == true){ - for(Integer playerID : this._playerMemory){ - player = PlayerCharacter.getFromCache(playerID); - if(this.dividedPlayers.containsKey(player.getGuild().getNation())){ - int count = this.dividedPlayers.get(player.getGuild().getNation()).size(); - switch(this.getBane().capSize){ - case 5: - player.ZergMultiplier = ZergManager.getMultiplier5Man(count,player); - break; - case 10: - player.ZergMultiplier = ZergManager.getMultiplier10Man(count,player); - break; - case 20: - player.ZergMultiplier = ZergManager.getMultiplier20Man(count,player); - break; - case 30: - player.ZergMultiplier = ZergManager.getMultiplier30Man(count,player); - break; - case 40: - player.ZergMultiplier = ZergManager.getMultiplier40Man(count,player); - break; - case 9999999: - player.ZergMultiplier = ZergManager.getMultiplierUnlimited(count,player); - break; - } - } else{ - player.ZergMultiplier = 1.0f; //something went wrong reset to default until next cycle - } - } - } - } - - private Boolean onExitZerg(HashSet currentPlayers) { - - PlayerCharacter player; - int playerUUID = 0; - HashSet toRemove = new HashSet<>(); - Iterator iter = _playerMemory.iterator(); - while (iter.hasNext()) { - - playerUUID = iter.next(); - - - player = PlayerCharacter.getFromCache(playerUUID); - - if (currentPlayers.contains(player)) - continue; - - toRemove.add(playerUUID); - if(_recentMemory.containsKey(playerUUID) == false) { - _recentMemory.put(playerUUID, System.currentTimeMillis()); - } - player.ZergMultiplier = 1.0f; // reset damage modifier to 1.0 - this.removeAllCityEffects(player, false); - if (this.cityOutlaws.contains(playerUUID)) - this.cityOutlaws.remove(playerUUID); - } - - // Remove players from mine memory - - //_playerMemory.removeAll(toRemove); - HashSet purge = new HashSet<>(); - for(Integer id : _recentMemory.keySet()){ - if(System.currentTimeMillis() > _recentMemory.get(playerUUID) + 60000){ - purge.add(id); - } - } - for(Integer id : purge){ - _recentMemory.remove(id); - } - if(toRemove.isEmpty()){ - return false; - }else{ - return true; - } - } } diff --git a/src/engine/powers/effectmodifiers/HealthEffectModifier.java b/src/engine/powers/effectmodifiers/HealthEffectModifier.java index 6d5a9bf7..e2096a1a 100644 --- a/src/engine/powers/effectmodifiers/HealthEffectModifier.java +++ b/src/engine/powers/effectmodifiers/HealthEffectModifier.java @@ -318,8 +318,8 @@ public class HealthEffectModifier extends AbstractEffectModifier { AbstractCharacter ac = (AbstractCharacter) awo; if (ac.isSit()) damage *= 2.5f; // increase damage if sitting - if(ac.getObjectType().equals(GameObjectType.PlayerCharacter) && source.equals(ac) == false && ZergManager.getReducedZergMultiplier(source,ac) != 0.0f){ - damage *= ZergManager.getReducedZergMultiplier(source,ac); + if(ac.getObjectType().equals(GameObjectType.PlayerCharacter) && source.equals(ac) == false){ + damage *= ((PlayerCharacter)source).ZergMultiplier; } } diff --git a/src/engine/powers/effectmodifiers/ManaEffectModifier.java b/src/engine/powers/effectmodifiers/ManaEffectModifier.java index 9f539b56..ab9b63fd 100644 --- a/src/engine/powers/effectmodifiers/ManaEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ManaEffectModifier.java @@ -207,8 +207,8 @@ public class ManaEffectModifier extends AbstractEffectModifier { AbstractCharacter ac = (AbstractCharacter) awo; if (ac.isSit()) damage *= 2.5f; // increase damage if sitting - if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && source.equals(ac) == false && ZergManager.getReducedZergMultiplier(source,ac) != 0.0f){ - damage *= ZergManager.getReducedZergMultiplier(source,ac); + if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && !source.equals(ac)){ + damage *= ((PlayerCharacter)source).ZergMultiplier; } } diff --git a/src/engine/powers/effectmodifiers/StaminaEffectModifier.java b/src/engine/powers/effectmodifiers/StaminaEffectModifier.java index 91e64bcf..1f33822e 100644 --- a/src/engine/powers/effectmodifiers/StaminaEffectModifier.java +++ b/src/engine/powers/effectmodifiers/StaminaEffectModifier.java @@ -205,8 +205,8 @@ public class StaminaEffectModifier extends AbstractEffectModifier { AbstractCharacter ac = (AbstractCharacter) awo; if (ac.isSit()) damage *= 2.5f; // increase damage if sitting - if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && source.equals(ac) == false && ZergManager.getReducedZergMultiplier(source,ac) != 0.0f){ - damage *= ZergManager.getReducedZergMultiplier(source,ac); + if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && !source.equals(ac)){ + damage *= ((PlayerCharacter)source).ZergMultiplier; } } diff --git a/src/engine/workthreads/ZergMechanicThread.java b/src/engine/workthreads/ZergMechanicThread.java index 07f99b89..fba864a9 100644 --- a/src/engine/workthreads/ZergMechanicThread.java +++ b/src/engine/workthreads/ZergMechanicThread.java @@ -47,12 +47,10 @@ public boolean isMine = false; @Override public void run() { - if(mine != null) - while(mine.isActive) + while(mine != null && mine.isActive) RunMineMechanic(); - if(bane != null) - while(bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) + while(bane != null && bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) RunBaneMechanic(); } @@ -103,42 +101,68 @@ public boolean isMine = false; if(mine.dividedPlayers.containsKey(player.getGuild().getNation())){ int count = mine.dividedPlayers.get(player.getGuild().getNation()).size(); switch(mine.capSize){ + case 3: + player.ZergMultiplier = ZergManager.getMultiplier3Man(count); + break; case 5: - player.ZergMultiplier = ZergManager.getMultiplier5Man(count,player); + player.ZergMultiplier = ZergManager.getMultiplier5Man(count); break; case 10: - player.ZergMultiplier = ZergManager.getMultiplier10Man(count,player); + player.ZergMultiplier = ZergManager.getMultiplier10Man(count); break; case 20: - player.ZergMultiplier = ZergManager.getMultiplier20Man(count,player); + player.ZergMultiplier = ZergManager.getMultiplier20Man(count); break; } player.mineAppliedID = mine.getObjectUUID(); } else{ player.ZergMultiplier = 1.0f; + player.mineAppliedID = 0; } } } public void RunBaneMechanic(){ HashSet currentPlayers; - PlayerCharacter player; currentPlayers = WorldGrid.getObjectsInRangePartial(bane.getCity().loc, Enum.CityBoundsType.GRID.extents * 2.0f, MBServerStatics.MASK_PLAYER); + Guild attacker = bane.getStone().getGuild().getNation(); Guild defender = bane.getCity().getGuild().getNation(); - int attackers = 0; - int defenders = 0; + + ArrayList attackers = new ArrayList<>(); + ArrayList defenders = new ArrayList<>(); + for(AbstractWorldObject awo : currentPlayers){ PlayerCharacter pc = (PlayerCharacter) awo; - if(pc.getGuild().getNation().equals(attacker) == false && pc.getGuild().getNation().equals(defender) == false) + if(!pc.getGuild().getNation().equals(attacker) && !pc.getGuild().getNation().equals(defender)) { pc.teleport(pc.bindLoc); + pc.ZergMultiplier = 1.0f; + } if(pc.getGuild().getNation().equals(attacker)) - attackers++; + attackers.add(pc); if(pc.getGuild().getNation().equals(defender)) - defenders++; + defenders.add(pc); + } + + int treeRank = bane.getCity().getTOL().getRank(); + + for(PlayerCharacter pc : attackers){ + if(treeRank == 8){ + pc.ZergMultiplier = ZergManager.getMultiplier40Man(attackers.size()); + }else{ + pc.ZergMultiplier = ZergManager.getMultiplier20Man(attackers.size()); + } + } + + for(PlayerCharacter pc : defenders){ + if(treeRank == 8){ + pc.ZergMultiplier = ZergManager.getMultiplier40Man(defenders.size()); + }else{ + pc.ZergMultiplier = ZergManager.getMultiplier20Man(defenders.size()); + } } }