48public class CombatTarget {
51 private static final int AGGRESSION_TIMEOUT = 20;
52 private final Mob mob;
56 CombatTarget(
Mob mob) {
58 this.distance = Integer.MAX_VALUE;
62 void checkAggression(
Position spawn) {
68 if (distance == Integer.MAX_VALUE)
72 if (
Utility.getDistance(mob, spawn) >
Region.VIEW_DISTANCE && !
Area.inFightCaves(mob) && !
Area.inGodwarsChambers(mob)) {
73 if (mob.getCombat().isUnderAttack()) {
75 distance = Integer.MAX_VALUE;
77 if (mob.isNpc() && mob.getNpc().boundaries.length > 0) {
80 mob.walkExactlyTo(pos, () -> {
86 mob.getCombat().reset();
93 int dist =
Utility.getDistance(target, mob);
94 int aggressionRadius = mob.width() + 3;
96 if (
Area.inGodwarsChambers(mob)) {
97 aggressionRadius =
Region.SIZE;
101 if (dist > aggressionRadius)
105 if (mob.getCombat().isAttacking(target))
108 if (!mob.getCombat().attack(target)) {
109 mob.getCombat().reset();
120 void compare(
Mob other,
int level,
Position spawn) {
121 int dist =
Utility.getDistance(mob, other);
128 if (dist >
Region.VIEW_DISTANCE)
131 if (spawn !=
null && !(mob instanceof
Player && mob.activity !=
null) && !
Area.inFightCaves(mob) && !
Area.inGodwars(mob) &&
Utility.getDistance(other, spawn) >
Region.VIEW_DISTANCE)
144 public static void checkAggression(
Player player) {
145 if (!player.isVisible())
155 if (npc ==
null || !npc.isValid())
158 if (!npc.definition.isAttackable() || !npc.definition.isAggressive())
161 if (npc.isDead() || !npc.isVisible() || npc.forceWalking)
164 if (npc.locking.locked())
167 if (player.aggressionTimer.elapsed(AGGRESSION_TIMEOUT, TimeUnit.MINUTES)
168 && !
Area.inGodwars(npc)
169 && player.activity ==
null) {
170 if (npc.getCombat().isAttacking(player) && !player.
getCombat().isAttacking(npc))
171 npc.getCombat().reset();
177 if (
Area.inGodwars(npc) && !
Area.inGodwarsChambers(npc)) {
178 if (npc.npcAssistant.isArmadyl()) {
179 boolean found =
false;
180 for (
Npc npc1 : npc.getRegion().
getNpcs(npc.getHeight())) {
181 if (
Utility.getDistance(npc, npc1.getPosition()) < 5 && !npc1.npcAssistant.isArmadyl()) {
183 npc.getCombat().attack(npc1);
192 if (player.equipment.hasArmadyl()) {
195 }
else if (npc.npcAssistant.isBandos()) {
196 boolean found =
false;
197 for (
Npc npc1 : npc.getRegion().
getNpcs(npc.getHeight())) {
198 if (
Utility.getDistance(npc, npc1.getPosition()) < 5 && !npc1.npcAssistant.isBandos()) {
200 npc.getCombat().attack(npc1);
209 if (player.equipment.hasBandos()) {
212 }
else if (npc.npcAssistant.isSaradomin()) {
213 boolean found =
false;
214 for (
Npc npc1 : npc.getRegion().
getNpcs(npc.getHeight())) {
215 if (
Utility.getDistance(npc, npc1.getPosition()) < 5 && !npc1.npcAssistant.isSaradomin()) {
217 npc.getCombat().attack(npc1);
226 if (player.equipment.hasSaradomin()) {
229 }
else if (npc.npcAssistant.isZamorak()) {
230 boolean found =
false;
231 for (
Npc npc1 : npc.getRegion().
getNpcs(npc.getHeight())) {
232 if (
Utility.getDistance(npc, npc1.getPosition()) < 5 && !npc1.npcAssistant.isZamorak()) {
234 npc.getCombat().attack(npc1);
243 if (player.equipment.hasZamorak()) {
249 npc.getCombat().compare(player, npc.definition.getCombatLevel(), npc.spawnPosition);
255 distance = Integer.MAX_VALUE;
258 public void setTarget(
Mob target) {
259 this.target = target;
260 distance =
Utility.getDistance(mob, target);
263 boolean isTarget(
Mob mob) {
264 return mob.equals(target);
267 public Mob getTarget() {