From dcac0634a8a3739c4c1057e88301b2244916414f Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 14 Mar 2023 13:32:41 -0500 Subject: [PATCH 1/5] added Chase to mob ai state enum --- src/engine/ai/MobileFSM.java | 38 ++++++++++++++------ src/engine/ai/utilities/CombatUtilities.java | 2 +- src/engine/objects/AbstractCharacter.java | 6 ++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 731369e8..e5c7f95a 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -53,7 +53,8 @@ public class MobileFSM { Home, Dead, Recalling, - Retaliate + Retaliate, + Chase } public static void run(Mob mob) { @@ -116,7 +117,6 @@ public class MobileFSM { rwss.setPlayer(mob); DispatchMessage.sendToAllInRange(mob, rwss); } - if (mob.isPlayerGuard()) guardAttack(mob); else if (mob.isPet() || mob.isSiege()) @@ -144,6 +144,9 @@ public class MobileFSM { case Retaliate: retaliate(mob); break; + case Chase: + handleMobChase(mob); + break; } } @@ -339,8 +342,8 @@ public class MobileFSM { if (!MovementUtilities.canMove(aiAgent)) return; - - if (CombatUtilities.inRangeToAttack2D(aiAgent, mob)) + double WeaponRange = aiAgent.getEquip().get(0).getItemBase().getRange(); + if (CombatUtilities.inRange2D(aiAgent, mob, WeaponRange)) return; @@ -465,11 +468,18 @@ public class MobileFSM { aiAgent.setState(STATE.Patrol); return; } + aiAgent.setCombatTarget(aggroTarget); + double AttackRange = 3; + if(aiAgent.getEquip().get(0) != null){ + AttackRange = aiAgent.getEquip().get(0).getItemBase().getRange(); + } else if(aiAgent.getEquip().get(1) != null){ + AttackRange = aiAgent.getEquip().get(1).getItemBase().getRange(); + } if (canCast(aiAgent) == true) { if (MobCast(aiAgent) == false) { attack(aiAgent, targetID); } - } else if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) { + } else if (CombatUtilities.inRange2D(aiAgent, aggroTarget, AttackRange)) { aiAgent.setState(STATE.Attack); attack(aiAgent, targetID); return; @@ -888,10 +898,8 @@ public class MobileFSM { //this stops mobs from attempting to move while they are underneath a player. if (CombatUtilities.inRangeToAttack2D(aiAgent, player)) return; - - aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, player); - MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); - + //move mob to within attack range again + aiAgent.setState(MobileFSM.STATE.Chase); } private static void handleMobAttackForPet(Mob aiAgent, Mob mob) { @@ -1678,7 +1686,7 @@ public class MobileFSM { powerToken = entry.getKey(); powerRank = entry.getValue(); PowersBase mobPower = PowersManager.getPowerByToken(powerToken); - if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { + if (CombatUtilities.inRange2D(mob, target, mobPower.getRange())) { PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank); PerformActionMsg msg = new PerformActionMsg(); if(mobPower.isHarmful() == false || mobPower.targetSelf == true){ @@ -1721,4 +1729,14 @@ public class MobileFSM { //wait 60 seconds to call for help again mob.nextCallForHelp = System.currentTimeMillis() + 60000; } + public static void handleMobChase(Mob mob){ + if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(),mob.getRange()) == true) { + MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); + mob.setState(STATE.Attack); + } + else{ + mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); + MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); + } + } } diff --git a/src/engine/ai/utilities/CombatUtilities.java b/src/engine/ai/utilities/CombatUtilities.java index 68a48a2f..519dcdeb 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -91,7 +91,7 @@ public class CombatUtilities { sum += x * x; double z = loc1.z - loc2.z; sum += z * z; - if(sqrt(sum) <= range){ + if((sum*sum) <= (range*range)){ return true; } else { return false; diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 32e9e6e7..643323b2 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -786,6 +786,12 @@ public abstract class AbstractCharacter extends AbstractWorldObject { if (mob.isSiege()) { return 300; } + float DefaultRange = 8; + if(((Mob) this).getEquip().get(0) != null){ + return ((Mob) this).getEquip().get(0).getItemBase().getRange(); + } else if(((Mob) this).getEquip().get(1) != null){ + return ((Mob) this).getEquip().get(1).getItemBase().getRange(); + } } if (this.rangeHandOne > this.rangeHandTwo) { return this.rangeHandOne; From 531cd52664053b680785322da56dd3062420c1b3 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 14 Mar 2023 18:39:59 -0500 Subject: [PATCH 2/5] mob ai Chase state work --- src/engine/ai/MobileFSM.java | 20 +++++++++++++++----- src/engine/ai/utilities/CombatUtilities.java | 14 ++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index e5c7f95a..1ca8e072 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -1730,13 +1730,23 @@ public class MobileFSM { mob.nextCallForHelp = System.currentTimeMillis() + 60000; } public static void handleMobChase(Mob mob){ - if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(),mob.getRange()) == true) { - MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); + if (!MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget())) { + mob.setAggroTargetID(0); + mob.setCombatTarget(null); + MovementUtilities.moveToLocation(mob, mob.getTrueBindLoc(), 0); + mob.setState(STATE.Awake); + return; + } + float range = mob.getRange(); + float distance = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc()); + boolean inRange = mob.getLoc().inRange2D(mob.getCombatTarget().getLoc(),range); + if(range > distance) { + mob.stopMovement(mob.getLoc()); mob.setState(STATE.Attack); } - else{ - mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); - MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); + else if(mob.isMoving() == true){ + mob.destination = mob.getCombatTarget().getLoc();//MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); + MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); } } } diff --git a/src/engine/ai/utilities/CombatUtilities.java b/src/engine/ai/utilities/CombatUtilities.java index 519dcdeb..28c8d5b9 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -16,6 +16,7 @@ import engine.ai.MobileFSM.STATE; import engine.gameManager.ChatManager; import engine.gameManager.CombatManager; import engine.gameManager.PowersManager; +import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.msg.PerformActionMsg; @@ -84,18 +85,7 @@ public class CombatUtilities { } public static boolean inRange2D(AbstractWorldObject entity1, AbstractWorldObject entity2, double range){ - Vector3fImmutable loc1 = entity1.getLoc(); - Vector3fImmutable loc2 = entity2.getLoc(); - double sum = 0; - double x = loc1.x - loc2.x; - sum += x * x; - double z = loc1.z - loc2.z; - sum += z * z; - if((sum*sum) <= (range*range)){ - return true; - } else { - return false; - } + return entity1.getLoc().distance2D(entity2.getLoc()) < range; } public static void swingIsBlock(Mob agent,AbstractWorldObject target, int animation) { From 8c919bcd2a8aca39d49a763c1ca3b4b890848432 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 14 Mar 2023 20:04:05 -0500 Subject: [PATCH 3/5] mob ai Chase state work --- src/engine/ai/MobileFSM.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 1ca8e072..de6e98de 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -899,6 +899,8 @@ public class MobileFSM { if (CombatUtilities.inRangeToAttack2D(aiAgent, player)) return; //move mob to within attack range again + aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, (AbstractCharacter) aiAgent.getCombatTarget()); + MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); aiAgent.setState(MobileFSM.STATE.Chase); } private static void handleMobAttackForPet(Mob aiAgent, Mob mob) { @@ -1730,23 +1732,8 @@ public class MobileFSM { mob.nextCallForHelp = System.currentTimeMillis() + 60000; } public static void handleMobChase(Mob mob){ - if (!MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget())) { - mob.setAggroTargetID(0); - mob.setCombatTarget(null); - MovementUtilities.moveToLocation(mob, mob.getTrueBindLoc(), 0); - mob.setState(STATE.Awake); - return; - } - float range = mob.getRange(); - float distance = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc()); - boolean inRange = mob.getLoc().inRange2D(mob.getCombatTarget().getLoc(),range); - if(range > distance) { - mob.stopMovement(mob.getLoc()); + if(CombatUtilities.inRangeToAttack(mob,mob.getCombatTarget()) == true) { mob.setState(STATE.Attack); } - else if(mob.isMoving() == true){ - mob.destination = mob.getCombatTarget().getLoc();//MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); - MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); - } } } From ce381f612c8dc7fd564fd9477868f1fd7ee98b78 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 14 Mar 2023 20:34:07 -0500 Subject: [PATCH 4/5] mob ai Chase state completion --- src/engine/ai/MobileFSM.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index de6e98de..8d845d87 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -834,18 +834,19 @@ public class MobileFSM { aiAgent.setState(STATE.Awake); return; } - if (CombatUtilities.inRangeToAttack(aiAgent, player)) { + if (CombatUtilities.inRange2D(aiAgent, player, aiAgent.getRange())) { //no weapons, defualt mob attack speed 3 seconds. if (System.currentTimeMillis() < aiAgent.getLastAttackTime()) return; - if (!CombatUtilities.RunAIRandom()) - return; + //if (!CombatUtilities.RunAIRandom()) + // return; // ranged mobs cant attack while running. skip until they finally stop. - if (aiAgent.getRange() >= 30 && aiAgent.isMoving()) + //if (aiAgent.getRange() >= 30 && aiAgent.isMoving()) + if(aiAgent.isMoving()) return; // add timer for last attack. @@ -898,9 +899,7 @@ public class MobileFSM { //this stops mobs from attempting to move while they are underneath a player. if (CombatUtilities.inRangeToAttack2D(aiAgent, player)) return; - //move mob to within attack range again - aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, (AbstractCharacter) aiAgent.getCombatTarget()); - MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); + //set mob to pursue target aiAgent.setState(MobileFSM.STATE.Chase); } private static void handleMobAttackForPet(Mob aiAgent, Mob mob) { @@ -1732,8 +1731,15 @@ public class MobileFSM { mob.nextCallForHelp = System.currentTimeMillis() + 60000; } public static void handleMobChase(Mob mob){ - if(CombatUtilities.inRangeToAttack(mob,mob.getCombatTarget()) == true) { + mob.updateMovementState(); + mob.updateLocation(); + if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(), mob.getRange()) == true) { + MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); mob.setState(STATE.Attack); } + else if (mob.isMoving() == false){ + mob.destination = mob.getCombatTarget().getLoc(); + MovementUtilities.moveToLocation(mob, mob.destination, 0); + } } } From 6fe690d592b443d88654860874adf7fea7a8a34f Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 14 Mar 2023 20:53:39 -0500 Subject: [PATCH 5/5] ranged mobs now stop when in proper attacking range --- src/engine/ai/MobileFSM.java | 36 +++++++++++------------ src/engine/objects/AbstractCharacter.java | 15 ++++++---- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 8d845d87..8d7bb536 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -17,7 +17,6 @@ import engine.InterestManagement.WorldGrid; import engine.ai.utilities.CombatUtilities; import engine.ai.utilities.MovementUtilities; import engine.gameManager.*; -import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.msg.PerformActionMsg; @@ -25,8 +24,6 @@ import engine.net.client.msg.PowerProjectileMsg; import engine.net.client.msg.UpdateStateMsg; import engine.objects.*; import engine.powers.ActionsBase; -import engine.powers.EffectsBase; -import engine.powers.PowerPrereq; import engine.powers.PowersBase; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -469,17 +466,11 @@ public class MobileFSM { return; } aiAgent.setCombatTarget(aggroTarget); - double AttackRange = 3; - if(aiAgent.getEquip().get(0) != null){ - AttackRange = aiAgent.getEquip().get(0).getItemBase().getRange(); - } else if(aiAgent.getEquip().get(1) != null){ - AttackRange = aiAgent.getEquip().get(1).getItemBase().getRange(); - } if (canCast(aiAgent) == true) { if (MobCast(aiAgent) == false) { attack(aiAgent, targetID); } - } else if (CombatUtilities.inRange2D(aiAgent, aggroTarget, AttackRange)) { + } else if (CombatUtilities.inRange2D(aiAgent, aggroTarget, aiAgent.getRange())) { aiAgent.setState(STATE.Attack); attack(aiAgent, targetID); return; @@ -1155,12 +1146,6 @@ public class MobileFSM { aiAgent.setCombatTarget(null); aiAgent.setState(STATE.Awake); } - private static void recall(Mob aiAgent) { - //recall home. - PowersBase recall = PowersManager.getPowerByToken(-1994153779); - PowersManager.useMobPower(aiAgent, aiAgent, recall, 40); - aiAgent.setState(MobileFSM.STATE.Recalling); - } private static void recalling(Mob aiAgent) { //recall home. if (aiAgent.getLoc() == aiAgent.getBindLoc()) @@ -1731,15 +1716,28 @@ public class MobileFSM { mob.nextCallForHelp = System.currentTimeMillis() + 60000; } public static void handleMobChase(Mob mob){ + if (!MovementUtilities.inRangeOfBindLocation(mob)) { + mob.setCombatTarget(null); + mob.setAggroTargetID(0); + mob.setWalkingHome(false); + mob.setState(STATE.Home); + return; + } mob.updateMovementState(); mob.updateLocation(); if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(), mob.getRange()) == true) { MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); mob.setState(STATE.Attack); } - else if (mob.isMoving() == false){ - mob.destination = mob.getCombatTarget().getLoc(); - MovementUtilities.moveToLocation(mob, mob.destination, 0); + else {//if (mob.isMoving() == false){ + if(mob.getRange() > 15) { + mob.destination = mob.getCombatTarget().getLoc(); + MovementUtilities.moveToLocation(mob, mob.destination, 0); + } else{ + mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); + MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); + } + } } } diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 643323b2..b2f3e5f2 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -781,17 +781,22 @@ public abstract class AbstractCharacter extends AbstractWorldObject { // Treb range does not appear to be set here // what gives? + if (this.getObjectType() == GameObjectType.Mob) { Mob mob = (Mob) this; if (mob.isSiege()) { return 300; } - float DefaultRange = 8; - if(((Mob) this).getEquip().get(0) != null){ - return ((Mob) this).getEquip().get(0).getItemBase().getRange(); - } else if(((Mob) this).getEquip().get(1) != null){ - return ((Mob) this).getEquip().get(1).getItemBase().getRange(); + float range = 8; + if(((Mob) this).getEquip().get(1) != null){ + range = ((Mob) this).getEquip().get(1).getItemBase().getRange(); + } else if(((Mob) this).getEquip().get(2) != null){ + range = ((Mob) this).getEquip().get(2).getItemBase().getRange(); + } + if(range > 80){ + range = 80; } + return range; } if (this.rangeHandOne > this.rangeHandTwo) { return this.rangeHandOne;