Aggressive NPCs will no longer always attack the last player to enter the area

This commit is contained in:
troido
2025-02-01 14:04:03 +00:00
committed by Ryan
parent c3929cf06c
commit 0a26d5039a
@@ -72,9 +72,9 @@ public class AggressiveBehavior {
if (entity instanceof NPC && target instanceof Player) { if (entity instanceof NPC && target instanceof Player) {
NPC npc = (NPC) entity; NPC npc = (NPC) entity;
if (npc.getAggressiveHandler() != null && npc.getAggressiveHandler().isAllowTolerance() && !WildernessZone.isInZone(npc)) { if (npc.getAggressiveHandler() != null && npc.getAggressiveHandler().isAllowTolerance() && !WildernessZone.isInZone(npc)) {
if (RegionManager.forId(regionId).isTolerated(target.asPlayer())) { if (RegionManager.forId(regionId).isTolerated(target.asPlayer())) {
return false; return false;
} }
} }
} }
int level = target.getProperties().getCurrentCombatLevel(); int level = target.getProperties().getCurrentCombatLevel();
@@ -84,9 +84,9 @@ public class AggressiveBehavior {
return true; return true;
} }
public boolean ignoreCombatLevelDifference() { public boolean ignoreCombatLevelDifference() {
return false; return false;
} }
/** /**
* Gets the priority flag. * Gets the priority flag.
@@ -132,9 +132,9 @@ public class AggressiveBehavior {
*/ */
public Entity getLogicalTarget(Entity entity, List<Entity> possibleTargets) { public Entity getLogicalTarget(Entity entity, List<Entity> possibleTargets) {
Entity target = null; Entity target = null;
int comparingFlag = Integer.MAX_VALUE; double comparingFlag = Double.MAX_VALUE;
for (Entity e : possibleTargets) { for (Entity e : possibleTargets) {
int flag = getPriorityFlag(e); double flag = (double)getPriorityFlag(e) + Math.random();
if (flag <= comparingFlag) { if (flag <= comparingFlag) {
comparingFlag = flag; comparingFlag = flag;
target = e; target = e;