From d573b238de8d5d43cab6ae32e54f3bbd47294268 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 27 Aug 2023 21:04:34 -0500 Subject: [PATCH] refactored mob get/set owner --- src/engine/devcmd/cmds/InfoCmd.java | 4 +- src/engine/gameManager/NPCManager.java | 12 +++-- src/engine/mobileAI/MobAI.java | 19 +++++--- .../handlers/MinionTrainingMsgHandler.java | 14 ++++-- .../objects/AbstractIntelligenceAgent.java | 5 ++- src/engine/objects/AbstractWorldObject.java | 4 +- src/engine/objects/Mob.java | 44 ++++++++++--------- src/engine/objects/NPC.java | 6 ++- src/engine/objects/PlayerCharacter.java | 3 +- .../poweractions/CreateMobPowerAction.java | 8 ++-- 10 files changed, 74 insertions(+), 45 deletions(-) diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index 5cb88ef9..51edb93a 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -440,7 +440,9 @@ public class InfoCmd extends AbstractDevCmd { output += "isSummonedPet: true"; else output += "isSummonedPet: false"; - PlayerCharacter owner = targetMob.getOwner(); + + + PlayerCharacter owner = (PlayerCharacter) targetMob.guardCaptain; if (owner != null) output += " owner: " + owner.getObjectUUID(); output += newline; diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index b4362249..b112fe17 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -127,10 +127,12 @@ public enum NPCManager { DbManager.removeFromCache(necroPet); - PlayerCharacter petOwner = necroPet.getOwner(); + + PlayerCharacter petOwner = (PlayerCharacter) necroPet.guardCaptain; if (petOwner != null) { - necroPet.setOwner(null); + + necroPet.guardCaptain = null; petOwner.setPet(null); if (updateOwner == false) @@ -228,12 +230,14 @@ public enum NPCManager { WorldGrid.removeObject(toRemove); DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); + + PlayerCharacter petOwner = (PlayerCharacter) toRemove.guardCaptain; if (petOwner != null) { petOwner.setPet(null); - toRemove.setOwner(null); + + toRemove.guardCaptain = null; PetMsg petMsg = new PetMsg(5, null); Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 0f8af705..ec202e6b 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -786,24 +786,30 @@ public class MobAI { switch (mob.behaviourType) { case Pet1: - if (mob.getOwner() == null) + + + if ((PlayerCharacter) mob.guardCaptain == null) return; - if (!mob.playerAgroMap.containsKey(mob.getOwner().getObjectUUID())) { + + if (!mob.playerAgroMap.containsKey(((PlayerCharacter) mob.guardCaptain).getObjectUUID())) { //mob no longer has its owner loaded, translocate pet to owner - MovementManager.translocate(mob, mob.getOwner().getLoc(), null); + + MovementManager.translocate(mob, ((PlayerCharacter) mob.guardCaptain).getLoc(), null); return; } if (mob.getCombatTarget() == null) { //move back to owner - if (CombatUtilities.inRange2D(mob, mob.getOwner(), 6)) + + if (CombatUtilities.inRange2D(mob, (PlayerCharacter) mob.guardCaptain, 6)) return; - mob.destination = mob.getOwner().getLoc(); + + mob.destination = ((PlayerCharacter) mob.guardCaptain).getLoc(); MovementUtilities.moveToLocation(mob, mob.destination, 5); } else chaseTarget(mob); @@ -1103,7 +1109,8 @@ public class MobAI { try { - if (mob.getOwner() == null && mob.isNecroPet() == false && mob.isSiege() == false) + + if ((PlayerCharacter) mob.guardCaptain == null && mob.isNecroPet() == false && mob.isSiege() == false) if (ZoneManager.getSeaFloor().zoneMobSet.contains(mob)) mob.killCharacter("no owner"); diff --git a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java index 66db649a..a6aa404e 100644 --- a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java +++ b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java @@ -73,11 +73,14 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { toRemove.getParentZone().zoneMobSet.remove(toRemove); DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); + + + PlayerCharacter petOwner = (PlayerCharacter) toRemove.guardCaptain; if (petOwner != null) { petOwner.setPet(null); - toRemove.setOwner(null); + + toRemove.guardCaptain = null; PetMsg petMsg = new PetMsg(5, null); Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); @@ -195,11 +198,14 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { toRemove.getParentZone().zoneMobSet.remove(toRemove); DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); + + + PlayerCharacter petOwner = (PlayerCharacter) toRemove.guardCaptain; if (petOwner != null) { petOwner.setPet(null); - toRemove.setOwner(null); + + toRemove.guardCaptain = null; PetMsg petMsg = new PetMsg(5, null); Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); diff --git a/src/engine/objects/AbstractIntelligenceAgent.java b/src/engine/objects/AbstractIntelligenceAgent.java index e0b49454..f18d4acb 100644 --- a/src/engine/objects/AbstractIntelligenceAgent.java +++ b/src/engine/objects/AbstractIntelligenceAgent.java @@ -101,7 +101,8 @@ public abstract class AbstractIntelligenceAgent extends AbstractCharacter { this.agentType = Enum.AIAgentType.CHARMED; if (this.getObjectType().equals(GameObjectType.Mob)) { - ((Mob) this).setOwner(owner); + + ((Mob) this).guardCaptain = owner; } } @@ -180,7 +181,7 @@ public abstract class AbstractIntelligenceAgent extends AbstractCharacter { owner.setPet(null); if (this.getObjectType().equals(GameObjectType.Mob)) - ((Mob) this).setOwner(null); + ((Mob) this).guardCaptain = null; } diff --git a/src/engine/objects/AbstractWorldObject.java b/src/engine/objects/AbstractWorldObject.java index 97d8a5d1..5f087a55 100644 --- a/src/engine/objects/AbstractWorldObject.java +++ b/src/engine/objects/AbstractWorldObject.java @@ -357,7 +357,9 @@ public abstract class AbstractWorldObject extends AbstractGameObject { Mob mob = (Mob) this; if (mob.isSiege()) { if (mob.isPet()) { - PlayerCharacter petOwner = mob.getOwner(); + + + PlayerCharacter petOwner = (PlayerCharacter) mob.guardCaptain; if (petOwner != null && source.equals(EffectSourceType.Effect)) { petOwner.dismissPet(); return; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 7b2178a9..1cfcdeaa 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -316,9 +316,14 @@ public class Mob extends AbstractIntelligenceAgent { writer.put((byte) 1); - if (mob.getOwner() != null) { - writer.putInt(mob.getOwner().getObjectType().ordinal()); - writer.putInt(mob.getOwner().getObjectUUID()); + + if ((PlayerCharacter) mob.guardCaptain != null) { + + + writer.putInt(((PlayerCharacter) mob.guardCaptain).getObjectType().ordinal()); + + + writer.putInt(((PlayerCharacter) mob.guardCaptain).getObjectUUID()); } else { writer.putInt(0); //ownerType writer.putInt(0); //ownerID @@ -732,17 +737,6 @@ public class Mob extends AbstractIntelligenceAgent { return this.guild.getObjectUUID(); } - public PlayerCharacter getOwner() { - - - return (PlayerCharacter) this.guardCaptain; - } - - public void setOwner(PlayerCharacter value) { - - this.guardCaptain = value; - } - public void setFearedObject(AbstractWorldObject awo) { this.fearedObject = awo; } @@ -751,7 +745,7 @@ public class Mob extends AbstractIntelligenceAgent { public Vector3fImmutable getBindLoc() { if (this.isPet() && !this.behaviourType.equals(MobBehaviourType.SiegeEngine)) - return this.getOwner() != null ? this.getOwner().getLoc() : this.getLoc(); + return (PlayerCharacter) this.guardCaptain != null ? ((PlayerCharacter) this.guardCaptain).getLoc() : this.getLoc(); else return this.bindLoc; } @@ -875,7 +869,8 @@ public class Mob extends AbstractIntelligenceAgent { if (mobAttacker.isPet()) { - PlayerCharacter owner = mobAttacker.getOwner(); + + PlayerCharacter owner = (PlayerCharacter) mobAttacker.guardCaptain; if (owner != null) if (!this.isPet() && !this.isNecroPet() && !(this.agentType.equals(AIAgentType.PET)) && !this.isPlayerGuard) { @@ -945,13 +940,17 @@ public class Mob extends AbstractIntelligenceAgent { if (this.isPet()) { - PlayerCharacter petOwner = this.getOwner(); + + PlayerCharacter petOwner = (PlayerCharacter) this.guardCaptain; if (petOwner != null) { - this.setOwner(null); + + this.guardCaptain = null; petOwner.setPet(null); PetMsg petMsg = new PetMsg(5, null); - dispatch = Dispatch.borrow(this.getOwner(), petMsg); + + + dispatch = Dispatch.borrow((PlayerCharacter) this.guardCaptain, petMsg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); } } @@ -974,10 +973,13 @@ public class Mob extends AbstractIntelligenceAgent { WorldGrid.RemoveWorldObject(this); DbManager.removeFromCache(this); - PlayerCharacter petOwner = this.getOwner(); + + + PlayerCharacter petOwner = (PlayerCharacter) this.guardCaptain; if (petOwner != null) { - this.setOwner(null); + + this.guardCaptain = null; petOwner.setPet(null); PetMsg petMsg = new PetMsg(5, null); dispatch = Dispatch.borrow(petOwner, petMsg); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index 1ebc4c39..ae8f63bd 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -655,12 +655,14 @@ public class NPC extends AbstractCharacter { WorldGrid.RemoveWorldObject(toRemove); DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); + + PlayerCharacter petOwner = (PlayerCharacter) toRemove.guardCaptain; if (petOwner != null) { petOwner.setPet(null); - toRemove.setOwner(null); + + toRemove.guardCaptain = null; PetMsg petMsg = new PetMsg(5, null); Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 7d7baaa5..92cdf909 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -4690,7 +4690,8 @@ public class PlayerCharacter extends AbstractCharacter { } else if (currentPet.isSiege()) { currentPet.agentType = AIAgentType.MOBILE; - currentPet.setOwner(null); + + currentPet.guardCaptain = null; currentPet.setCombatTarget(null); if (currentPet.isAlive()) WorldGrid.updateObject(currentPet); diff --git a/src/engine/powers/poweractions/CreateMobPowerAction.java b/src/engine/powers/poweractions/CreateMobPowerAction.java index c9e9d994..41c7e810 100644 --- a/src/engine/powers/poweractions/CreateMobPowerAction.java +++ b/src/engine/powers/poweractions/CreateMobPowerAction.java @@ -94,7 +94,8 @@ public class CreateMobPowerAction extends AbstractPowerAction { } else if (currentPet != null && currentPet.isSiege()) { currentPet.agentType = Enum.AIAgentType.MOBILE; - currentPet.setOwner(null); + + currentPet.guardCaptain = null; currentPet.setCombatTarget(null); if (currentPet.isAlive()) @@ -110,7 +111,7 @@ public class CreateMobPowerAction extends AbstractPowerAction { DbManager.removeFromCache(currentPet); currentPet.setCombatTarget(null); - currentPet.setOwner(null); + currentPet.guardCaptain = null; WorldGrid.RemoveWorldObject(currentPet); //currentPet.getParentZone().zoneMobSet.remove(currentPet); seaFloor.zoneMobSet.remove(currentPet); @@ -120,7 +121,8 @@ public class CreateMobPowerAction extends AbstractPowerAction { } else { if (currentPet.isSiege()) { currentPet.agentType = Enum.AIAgentType.MOBILE; - currentPet.setOwner(null); + + currentPet.guardCaptain = null; currentPet.setCombatTarget(null); if (currentPet.isAlive())