Browse Source

mob AI aggro cleanup

lakebane-master
FatBoy-DOTC 6 months ago
parent
commit
bb28d38735
  1. 53
      src/engine/mobileAI/MobAI.java

53
src/engine/mobileAI/MobAI.java

@ -394,21 +394,7 @@ public class MobAI {
} }
//no players loaded, no need to proceed //no players loaded, no need to proceed
if (mob.playerAgroMap.isEmpty()) { if (mob.playerAgroMap.isEmpty()) {
//attempt to reload agro map
HashSet<AbstractWorldObject> 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; return;
} }
@ -441,6 +427,7 @@ public class MobAI {
if (mob.isMoving()) { if (mob.isMoving()) {
mob.updateLocation(); mob.updateLocation();
} }
boolean combatState = mob.isCombat(); boolean combatState = mob.isCombat();
mob.setCombat(mob.combatTarget != null); mob.setCombat(mob.combatTarget != null);
if(combatState != mob.isCombat()){ if(combatState != mob.isCombat()){
@ -449,6 +436,7 @@ public class MobAI {
rwss.setPlayer(mob); rwss.setPlayer(mob);
DispatchMessage.sendToAllInRange(mob, rwss); DispatchMessage.sendToAllInRange(mob, rwss);
} }
boolean walking = mob.isWalk(); boolean walking = mob.isWalk();
mob.setWalkMode(mob.combatTarget == null); mob.setWalkMode(mob.combatTarget == null);
if(walking != mob.isWalk()){ if(walking != mob.isWalk()){
@ -490,34 +478,28 @@ public class MobAI {
if (!aiAgent.isAlive()) if (!aiAgent.isAlive())
return; return;
if(!pets) { if(!pets) {
ConcurrentHashMap<Integer, Float> loadedPlayers = aiAgent.playerAgroMap; ConcurrentHashMap<Integer, Float> loadedPlayers = aiAgent.playerAgroMap;
for (Integer playerEntry : loadedPlayers.keySet()) { for (Integer playerEntry : loadedPlayers.keySet()) {
PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerEntry); PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerEntry);
//Player is null, let's remove them from the list. //Player is null, let's remove them from the list.
if (loadedPlayer == null) { if (loadedPlayer == null) {
loadedPlayers.remove(playerEntry); loadedPlayers.remove(playerEntry);
continue; continue;
} }
//Player is Dead, Mob no longer needs to attempt to aggro. Remove them from aggro map. //Player is Dead, Mob no longer needs to attempt to aggro. Remove them from aggro map.
if (!loadedPlayer.isAlive() || loadedPlayer.getHidden() > 0) { if (!loadedPlayer.isAlive() || loadedPlayer.getHidden() > 0) {
loadedPlayers.remove(playerEntry); loadedPlayers.remove(playerEntry);
continue; continue;
} }
//Can't see target, skip aggro. //Can't see target, skip aggro.
if (!aiAgent.canSee(loadedPlayer)) if (!aiAgent.canSee(loadedPlayer))
continue; continue;
// No aggro for this race type // No aggro for this race type
if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType())) if (aiAgent.notEnemy.size() > 0 && aiAgent.notEnemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()))
continue; continue;
@ -536,7 +518,7 @@ public class MobAI {
//look for pets to aggro if no players found to aggro //look for pets to aggro if no players found to aggro
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(aiAgent, MobAIThread.AI_BASE_AGGRO_RANGE, MBServerStatics.MASK_PET); HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(aiAgent, MobAIThread.AI_BASE_AGGRO_RANGE, MBServerStatics.MASK_MOB);
for (AbstractWorldObject awoMob : awoList) { for (AbstractWorldObject awoMob : awoList) {
@ -545,6 +527,9 @@ public class MobAI {
if (aiAgent.equals(awoMob)) if (aiAgent.equals(awoMob))
continue; continue;
if(!((Mob)awoMob).isPet())
continue;
Mob aggroMob = (Mob) awoMob; Mob aggroMob = (Mob) awoMob;
aiAgent.setCombatTarget(aggroMob); aiAgent.setCombatTarget(aggroMob);
return; return;
@ -921,24 +906,16 @@ public class MobAI {
} }
if (mob.behaviourType.isAgressive) { if (mob.behaviourType.isAgressive) {
if (mob.getCombatTarget() == null) {
//AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob); if (mob.behaviourType == Enum.MobBehaviourType.HamletGuard) {
SafeGuardAggro(mob); //safehold guard
//if (newTarget != null) } else {
// mob.setCombatTarget(newTarget); CheckForAggro(mob, false); //normal aggro
//else { 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 //check if mob can move for patrol or moving to target

Loading…
Cancel
Save