From bb28d3873532418b97d70376fdb1b3260c0e2646 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 19 May 2024 07:19:32 -0500 Subject: [PATCH] mob AI aggro cleanup --- src/engine/mobileAI/MobAI.java | 53 ++++++++++------------------------ 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index a9c8b992..a44722a7 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -394,21 +394,7 @@ public class MobAI { } //no players loaded, no need to proceed - if (mob.playerAgroMap.isEmpty()) { - //attempt to reload agro map - HashSet players = WorldGrid.getObjectsInRangePartial(mob.loc, mob.getAggroRange(), MBServerStatics.MASK_PLAYER); - if(players.size() > 0){ - for(AbstractWorldObject player : players){ - if(!mob.playerAgroMap.containsKey(player.getObjectUUID())) { - PlayerCharacter pc = (PlayerCharacter) player; - mob.playerAgroMap.put(pc.getObjectUUID(), 0.0f); - } - } - } - - if(mob.getCombatTarget() != null) - mob.setCombatTarget(null); return; } @@ -441,6 +427,7 @@ public class MobAI { if (mob.isMoving()) { mob.updateLocation(); } + boolean combatState = mob.isCombat(); mob.setCombat(mob.combatTarget != null); if(combatState != mob.isCombat()){ @@ -449,6 +436,7 @@ public class MobAI { rwss.setPlayer(mob); DispatchMessage.sendToAllInRange(mob, rwss); } + boolean walking = mob.isWalk(); mob.setWalkMode(mob.combatTarget == null); if(walking != mob.isWalk()){ @@ -490,34 +478,28 @@ public class MobAI { if (!aiAgent.isAlive()) return; + if(!pets) { ConcurrentHashMap loadedPlayers = aiAgent.playerAgroMap; - for (Integer playerEntry : loadedPlayers.keySet()) { PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerEntry); - //Player is null, let's remove them from the list. - if (loadedPlayer == null) { loadedPlayers.remove(playerEntry); continue; } - //Player is Dead, Mob no longer needs to attempt to aggro. Remove them from aggro map. - if (!loadedPlayer.isAlive() || loadedPlayer.getHidden() > 0) { loadedPlayers.remove(playerEntry); continue; } //Can't see target, skip aggro. - if (!aiAgent.canSee(loadedPlayer)) continue; // No aggro for this race type - if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType())) continue; @@ -536,7 +518,7 @@ public class MobAI { //look for pets to aggro if no players found to aggro - HashSet awoList = WorldGrid.getObjectsInRangePartial(aiAgent, MobAIThread.AI_BASE_AGGRO_RANGE, MBServerStatics.MASK_PET); + HashSet awoList = WorldGrid.getObjectsInRangePartial(aiAgent, MobAIThread.AI_BASE_AGGRO_RANGE, MBServerStatics.MASK_MOB); for (AbstractWorldObject awoMob : awoList) { @@ -545,6 +527,9 @@ public class MobAI { if (aiAgent.equals(awoMob)) continue; + if(!((Mob)awoMob).isPet()) + continue; + Mob aggroMob = (Mob) awoMob; aiAgent.setCombatTarget(aggroMob); return; @@ -921,24 +906,16 @@ public class MobAI { } if (mob.behaviourType.isAgressive) { - - //AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob); - - //if (newTarget != null) - // mob.setCombatTarget(newTarget); - //else { - - if (mob.getCombatTarget() == null) { - if (mob.behaviourType == Enum.MobBehaviourType.HamletGuard) { - SafeGuardAggro(mob); //safehold guard - }else { - CheckForAggro(mob,false); //normal aggro - if(mob.combatTarget == null) - CheckForAggro(mob,true); // look for pets if no players to aggro - } + if (mob.getCombatTarget() == null) { + if (mob.behaviourType == Enum.MobBehaviourType.HamletGuard) { + SafeGuardAggro(mob); //safehold guard + } else { + CheckForAggro(mob, false); //normal aggro + if (mob.combatTarget == null) + CheckForAggro(mob, true); // look for pets if no players to aggro } } - //} + } //check if mob can move for patrol or moving to target