From 3f3fb53675469e543f0c8831af45c99c86c8c8da Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 5 May 2024 19:45:46 -0500 Subject: [PATCH] hamlet guard aggro --- src/engine/mobileAI/MobAI.java | 122 +++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 42 deletions(-) diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 623dd22a..86dcc870 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -30,6 +30,7 @@ import org.pmw.tinylog.Logger; import java.util.ArrayList; import java.util.HashSet; import java.util.Map.Entry; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -214,6 +215,7 @@ public class MobAI { } } + assert mob.patrolPoints != null; if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) mob.lastPatrolPointIndex = 0; @@ -233,6 +235,7 @@ public class MobAI { if (mob.agentType.equals(mbEnums.AIAgentType.GUARDCAPTAIN)) for (Integer minionUUID : mob.minions) { Mob minion = Mob.getMob(minionUUID); + assert minion != null; if (minion.isAlive() && minion.combatTarget == null) MobAI.patrol(minion); } @@ -654,49 +657,44 @@ public class MobAI { mob.updateLocation(); - switch (mob.behaviourType) { + if (mob.behaviourType == mbEnums.MobBehaviourType.Pet1) { + if (mob.guardCaptain == null) + return; - case Pet1: + //mob no longer has its owner loaded, translate pet to owner - if (mob.guardCaptain == null) - return; + if (!mob.playerAgroMap.containsKey(mob.guardCaptain.getObjectUUID())) { + MovementManager.translocate(mob, mob.guardCaptain.getLoc()); + return; + } + + if (mob.getCombatTarget() == null) { - //mob no longer has its owner loaded, translate pet to owner + //move back to owner - if (!mob.playerAgroMap.containsKey(mob.guardCaptain.getObjectUUID())) { - MovementManager.translocate(mob, mob.guardCaptain.getLoc()); + if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(mob.guardCaptain.loc)) return; - } - if (mob.getCombatTarget() == null) { + mob.destination = mob.guardCaptain.getLoc(); + MovementUtilities.moveToLocation(mob, mob.destination, 5, false); + } else + chaseTarget(mob); + } else { + if (mob.getCombatTarget() == null) { - //move back to owner + if (!mob.isMoving()) { - if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(mob.guardCaptain.loc)) - return; + // Minions only patrol on their own if captain is dead. - mob.destination = mob.guardCaptain.getLoc(); - MovementUtilities.moveToLocation(mob, mob.destination, 5, false); + if (!mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION)) + patrol(mob); + else if (!mob.guardCaptain.isAlive()) + patrol(mob); } else - chaseTarget(mob); - break; - default: - if (mob.getCombatTarget() == null) { - - if (!mob.isMoving()) { - - // Minions only patrol on their own if captain is dead. - - if (!mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION)) - patrol(mob); - else if (!mob.guardCaptain.isAlive()) - patrol(mob); - } else - mob.stopPatrolTime = System.currentTimeMillis(); - } else { - chaseTarget(mob); - } - break; + mob.stopPatrolTime = System.currentTimeMillis(); + } else { + chaseTarget(mob); + } } } catch (Exception e) { Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckMobMovement" + " " + e.getMessage()); @@ -795,6 +793,7 @@ public class MobAI { Mob minion = Mob.getMob(minionUUID); PowersManager.useMobPower(minion, minion, recall, 40); + assert minion != null; minion.setCombatTarget(null); } } @@ -949,19 +948,57 @@ public class MobAI { private static void hamletGuardLogic(Mob mob) { try { - //safehold guard - if (mob.getCombatTarget() == null) - safeGuardAggro(mob); - else if (!mob.getCombatTarget().isAlive()) - safeGuardAggro(mob); + if (ConfigManager.MB_RULESET.getValue().equals("LORE")) { + if (mob.getCombatTarget() == null) + hamletGuardAggro(mob); + else if (!mob.getCombatTarget().isAlive()) + hamletGuardAggro(mob); + } else { + //safehold guard + if (mob.getCombatTarget() == null) + safeGuardAggro(mob); + else if (!mob.getCombatTarget().isAlive()) + safeGuardAggro(mob); + } checkForAttack(mob); } catch (Exception e) { Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: HamletGuardLogic" + " " + e.getMessage()); } } + private static void hamletGuardAggro(Mob mob) { + ConcurrentHashMap loadedPlayers = mob.playerAgroMap; + + for (Entry playerEntry : loadedPlayers.entrySet()) { + + int playerID = playerEntry.getKey(); + PlayerCharacter loadedPlayer = PlayerCharacter.getPlayerCharacter(playerID); + + if (loadedPlayer == null) + continue; + + if (!loadedPlayer.isAlive()) + continue; + + //Can't see target, skip aggro. + + if (!mob.canSee(loadedPlayer)) + continue; + + // No aggro for this player + + if (!guardCanAggro(mob, loadedPlayer)) + continue; + + if (MovementUtilities.inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) { + mob.setCombatTarget(loadedPlayer); + return; + } + } + } + private static void defaultLogic(Mob mob) { try { @@ -1085,7 +1122,7 @@ public class MobAI { return false; } - if (mob.guardedCity.cityOutlaws.contains(target.getObjectUUID())) + if (mob.guardedCity != null && mob.guardedCity.cityOutlaws.contains(target.getObjectUUID())) return true; if (mob.getGuild().getNation().equals(target.getGuild().getNation())) @@ -1093,8 +1130,8 @@ public class MobAI { //first check condemn list for aggro allowed (allies button is checked) - if (ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().reverseKOS) { - for (Entry entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) { + if (Objects.requireNonNull(ZoneManager.getCityAtLocation(mob.getLoc())).getTOL().reverseKOS) { + for (Entry entry : Objects.requireNonNull(ZoneManager.getCityAtLocation(mob.getLoc())).getTOL().getCondemned().entrySet()) { //target is listed individually @@ -1116,7 +1153,7 @@ public class MobAI { //allies button is not checked - for (Entry entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) { + for (Entry entry : Objects.requireNonNull(ZoneManager.getCityAtLocation(mob.getLoc())).getTOL().getCondemned().entrySet()) { //target is listed individually @@ -1175,6 +1212,7 @@ public class MobAI { //make sure mob is out of combat stance + assert minion != null; if (!minion.despawned) { if (MovementUtilities.canMove(minion)) { Vector3f minionOffset = mbEnums.FormationType.getOffset(2, mob.minions.indexOf(minionUUID) + 3);