From e88e8b56c6804eca88a558478696af97dcf83ad8 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 8 Aug 2023 12:49:25 -0500 Subject: [PATCH] mobs only toggle combat mode when changing combat target --- src/engine/mobileAI/MobAI.java | 47 +---------------------- src/engine/objects/AbstractCharacter.java | 19 +++++++++ 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 6be7f853..cfa0b840 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -235,7 +235,7 @@ public class MobAI { CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false)); mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); if (target.combatTarget == null) { - target.combatTarget = mob; + target.setCombatTarget(mob); } } } catch (Exception e) { @@ -249,13 +249,6 @@ public class MobAI { //make sure mob is out of combat stance - if (mob.isCombat() && mob.getCombatTarget() == null) { - mob.setCombat(false); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(mob); - DispatchMessage.sendToAllInRange(mob, rwss); - } - int patrolDelay = ThreadLocalRandom.current().nextInt((int) (MobAIThread.AI_PATROL_DIVISOR * 0.5f), MobAIThread.AI_PATROL_DIVISOR) + MobAIThread.AI_PATROL_DIVISOR; //early exit while waiting to patrol again @@ -289,12 +282,6 @@ public class MobAI { //make sure mob is out of combat stance if (minion.getKey().despawned == false) { - if (minion.getKey().isCombat() && minion.getKey().getCombatTarget() == null) { - minion.getKey().setCombat(false); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(minion.getKey()); - DispatchMessage.sendToAllInRange(minion.getKey(), rwss); - } if (MovementUtilities.canMove(minion.getKey())) { Vector3f minionOffset = Formation.getOffset(2, minion.getValue() + 3); minion.getKey().updateLocation(); @@ -655,14 +642,6 @@ public class MobAI { mob.setCombatTarget(null); return; } - - if (mob.isCombat() && mob.getCombatTarget() == null) { - mob.setCombat(false); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(mob); - DispatchMessage.sendToAllInRange(mob, rwss); - } - if (mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) CheckToSendMobHome(mob); @@ -912,23 +891,8 @@ public class MobAI { if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) == false && mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) { mob.setCombatTarget(null); - - if (mob.isCombat()) { - mob.setCombat(false); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(mob); - DispatchMessage.sendToAllInRange(mob, rwss); - } return; } - - if (!mob.isCombat()) { - mob.setCombat(true); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(mob); - DispatchMessage.sendToAllInRange(mob, rwss); - } - if (System.currentTimeMillis() > mob.getLastAttackTime()) AttackTarget(mob, mob.getCombatTarget()); @@ -1072,7 +1036,7 @@ public class MobAI { public static void GuardMinionLogic(Mob mob) { try { - if (!mob.npcOwner.isAlive() && mob.getCombatTarget() == null) { + if (!mob.npcOwner.isAlive()) { if(mob.getCombatTarget() == null) { CheckForPlayerGuardAggro(mob); }else { @@ -1343,13 +1307,6 @@ public class MobAI { //make sure mob is out of combat stance if (minion.getKey().despawned == false) { - if (minion.getKey().isCombat() && minion.getKey().getCombatTarget() == null) { - minion.getKey().setCombat(false); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(minion.getKey()); - DispatchMessage.sendToAllInRange(minion.getKey(), rwss); - } - if (MovementUtilities.canMove(minion.getKey())) { Vector3f minionOffset = Formation.getOffset(2, minion.getValue() + 3); minion.getKey().updateLocation(); diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 5728617b..3b8615d2 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -28,6 +28,8 @@ import engine.math.AtomicFloat; import engine.math.Bounds; import engine.math.Vector3fImmutable; import engine.net.ByteBufferWriter; +import engine.net.DispatchMessage; +import engine.net.client.msg.UpdateStateMsg; import engine.powers.EffectsBase; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -1160,6 +1162,23 @@ public abstract class AbstractCharacter extends AbstractWorldObject { } public final void setCombatTarget(final AbstractWorldObject value) { + if(value.getObjectTypeMask() == MBServerStatics.MASK_MOB) { + if (value == null) { + if (this.isCombat()) { + this.setCombat(false); + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(this); + DispatchMessage.sendToAllInRange(this, rwss); + } else { + if (!this.isCombat()) { + this.setCombat(true); + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(this); + DispatchMessage.sendToAllInRange(this, rwss); + } + } + } + } this.combatTarget = value; }