From 11e373db6f540f76d4cec81c238febc04c68f5ac Mon Sep 17 00:00:00 2001
From: FatBoy-DOTC <justin.chucksinsulating@gmail.com>
Date: Sat, 27 May 2023 20:53:52 -0500
Subject: [PATCH] treb fix

---
 src/engine/ai/MobileFSM.java                  | 17 ++++++-------
 .../handlers/MinionTrainingMsgHandler.java    | 24 +++++++++++++------
 src/engine/objects/Mob.java                   |  5 ++--
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java
index cd57ba15..5d722371 100644
--- a/src/engine/ai/MobileFSM.java
+++ b/src/engine/ai/MobileFSM.java
@@ -69,7 +69,7 @@ public class MobileFSM {
             mob.setCombatTarget(null);
             return;
         }
-        if (CombatUtilities.inRange2D(mob, target, mob.getRange())) {
+        if (CombatUtilities.inRangeToAttack(mob,mob.getCombatTarget())) {
             //no weapons, default mob attack speed 3 seconds.
             if (System.currentTimeMillis() < mob.getLastAttackTime())
                 return;
@@ -171,6 +171,10 @@ public class MobileFSM {
         if(mob.stopPatrolTime == 0) {
             mob.stopPatrolTime = System.currentTimeMillis();
         }
+        if(mob.isMoving() == true){
+            mob.stopPatrolTime = System.currentTimeMillis();
+            return;
+        }
         if (mob.isCombat() && mob.getCombatTarget() == null) {
             mob.setCombat(false);
             UpdateStateMsg rwss = new UpdateStateMsg();
@@ -299,16 +303,17 @@ public class MobileFSM {
     public static void DetermineAction(Mob mob) {
         if (mob == null)
             return;
-        if(mob.despawned || !mob.isAlive()) {
+        if(mob.despawned == true || mob.isAlive() == false) {
             if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) {
                 if (mob.npcOwner.isAlive() == false || ((Mob) mob.npcOwner).despawned == true) {
                     //minions don't respawn while guard captain is dead
                         mob.deathTime = System.currentTimeMillis();
                         return;
                 }
-                CheckForRespawn(mob);
-                return;
+
             }
+            CheckForRespawn(mob);
+            return;
         }
         if (mob.playerAgroMap.isEmpty() && mob.isPlayerGuard == false)
             //no players loaded, no need to proceed
@@ -402,11 +407,7 @@ public class MobileFSM {
                 break;
             default:
                 if (mob.getCombatTarget() == null) {
-                    if(!mob.isMoving()) {
                         Patrol(mob);
-                    } else{
-                        mob.stopPatrolTime = System.currentTimeMillis();
-                    }
                 }else {
                     chaseTarget(mob);
                 }
diff --git a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java
index f5e059e1..dc2a9b2a 100644
--- a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java
+++ b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java
@@ -4,10 +4,8 @@ import engine.Enum;
 import engine.Enum.DispatchChannel;
 import engine.InterestManagement.WorldGrid;
 import engine.exception.MsgSendException;
-import engine.gameManager.BuildingManager;
-import engine.gameManager.DbManager;
-import engine.gameManager.NPCManager;
-import engine.gameManager.SessionManager;
+import engine.gameManager.*;
+import engine.math.Vector3fImmutable;
 import engine.net.Dispatch;
 import engine.net.DispatchMessage;
 import engine.net.client.ClientConnection;
@@ -155,9 +153,20 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
 
 						//   toCreate.despawn();
 						if (toCreate != null) {
-							toCreate.setSpawnTime(60 * 15);
-							toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + (60 * 15 * 1000));
-							toCreate.setDeathTime(System.currentTimeMillis());
+							//test timer for treb testing
+							toCreate.setSpawnTime(10);
+							//toCreate.setSpawnTime(60 * 15);
+							//toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + (60 * 15 * 1000));
+							Building building = BuildingManager.getBuilding(((MinionTrainingMessage) baseMsg).getBuildingID());
+							int slot = ((NPC)toCreate.npcOwner).getSiegeMinionMap().get(toCreate);
+							Vector3fImmutable slotLocation;
+							toCreate.building = building;
+							toCreate.parentZone = zone;
+							BuildingLocation buildingLocation = BuildingManager._slotLocations.get(building.meshUUID).get(slot);
+							slotLocation = building.getLoc().add(buildingLocation.getLocation());
+							toCreate.setBindLoc(slotLocation);
+							zone.zoneMobSet.add(toCreate);
+							MovementManager.translocate(toCreate,toCreate.getBindLoc(),toCreate.npcOwner.region);
                         }
 					}
 
@@ -289,6 +298,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
 						if (toCreate != null) {
 							toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
 							toCreate.setDeathTime(System.currentTimeMillis());
+							toCreate.parentZone.zoneMobSet.add(toCreate);
                         }
 					}
 
diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java
index 79769d1f..f53d396b 100644
--- a/src/engine/objects/Mob.java
+++ b/src/engine/objects/Mob.java
@@ -825,7 +825,7 @@ public class Mob extends AbstractIntelligenceAgent {
             return null;
 
         mob = new Mob(minionMobBase, guild, parent, level, new Vector3fImmutable(1, 1, 1), 0, false);
-        mob.runAfterLoad();
+        //mob.runAfterLoad();
         mob.despawned = true;
         DbManager.addToCache(mob);
 
@@ -843,7 +843,6 @@ public class Mob extends AbstractIntelligenceAgent {
 
         owner.getSiegeMinionMap().put(mob, slot);
 
-        mob.setSpawnTime(10);
         mob.setNpcOwner(owner);
         mob.BehaviourType = MobBehaviourType.Pet1;
         mob.BehaviourType.canRoam = false;
@@ -1376,7 +1375,7 @@ public class Mob extends AbstractIntelligenceAgent {
     public void respawn() {
         //Commenting out Mob ID rotation.
         this.despawned = false;
-        this.playerAgroMap.clear();
+        //this.playerAgroMap.clear();
         this.setCombatTarget(null);
         this.setHealth(this.healthMax);
         this.stamina.set(this.staminaMax);