From 779e3da74e3b4a0f5e7c8e71fd99f78aef84d273 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 1 Sep 2023 14:33:33 -0400 Subject: [PATCH] Cleanup of clear minion logic. --- .../handlers/MinionTrainingMsgHandler.java | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java index edd7caad..a60793cb 100644 --- a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java +++ b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java @@ -15,9 +15,6 @@ import engine.net.client.msg.*; import engine.objects.*; import org.pmw.tinylog.Logger; -import java.util.ArrayList; -import java.util.HashMap; - /* * @Author: * @Summary: Processes application protocol message which @@ -26,8 +23,6 @@ import java.util.HashMap; public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { - public static HashMap> _minionsByCaptain = null; - public MinionTrainingMsgHandler() { super(MinionTrainingMessage.class); } @@ -37,10 +32,11 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { MinionTrainingMessage minionMsg = (MinionTrainingMessage) baseMsg; - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); - if (player == null) + if (playerCharacter == null) return true; + if (minionMsg.getNpcType() == Enum.GameObjectType.NPC.ordinal()) { NPC npc = NPC.getFromCache(minionMsg.getNpcID()); @@ -48,14 +44,15 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { if (npc == null) return true; - Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); + Building building = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); - if (b == null) + if (building == null) return true; //clear minion if (npc.minionLock.writeLock().tryLock()) { + try { if (minionMsg.getType() == 2) { @@ -86,23 +83,21 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { } } - // we Found the move to remove, lets break the for loop so it doesnt look for more. - - ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b); + ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(playerCharacter, building); mca1.actionType = 3; - mca1.setTargetType(b.getObjectType().ordinal()); - mca1.setTargetID(b.getObjectUUID()); + mca1.setTargetType(building.getObjectType().ordinal()); + mca1.setTargetID(building.getObjectUUID()); mca1.setTargetType3(npc.getObjectType().ordinal()); mca1.setTargetID3(npc.getObjectUUID()); - mca1.setAssetName1(b.getName()); + mca1.setAssetName1(building.getName()); mca1.setUnknown54(1); - Dispatch dispatch = Dispatch.borrow(player, mca1); + Dispatch dispatch = Dispatch.borrow(playerCharacter, mca1); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); ManageNPCMsg mnm = new ManageNPCMsg(npc); - dispatch = Dispatch.borrow(player, mnm); + dispatch = Dispatch.borrow(playerCharacter, mnm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); //Add Minion @@ -156,7 +151,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { ManageNPCMsg mnm = new ManageNPCMsg(npc); mnm.setMessageType(1); - Dispatch dispatch = Dispatch.borrow(player, mnm); + Dispatch dispatch = Dispatch.borrow(playerCharacter, mnm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } finally { @@ -199,7 +194,21 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { DbManager.removeFromCache(toRemove); - ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, building); + if (toRemove.agentType.equals(Enum.AIAgentType.SIEGEENGINE)) { + + PlayerCharacter trebOwner = (PlayerCharacter) toRemove.guardCaptain; + + if (trebOwner != null) { + trebOwner.setPet(null); + + toRemove.guardCaptain = null; + PetMsg petMsg = new PetMsg(5, null); + Dispatch dispatch = Dispatch.borrow(trebOwner, petMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + } + + ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(playerCharacter, building); mca1.actionType = 3; mca1.setTargetType(building.getObjectType().ordinal()); mca1.setTargetID(building.getObjectUUID()); @@ -209,11 +218,11 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { mca1.setAssetName1(building.getName()); mca1.setUnknown54(1); - Dispatch dispatch = Dispatch.borrow(player, mca1); + Dispatch dispatch = Dispatch.borrow(playerCharacter, mca1); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); ManageNPCMsg mnm = new ManageNPCMsg(npc); - dispatch = Dispatch.borrow(player, mnm); + dispatch = Dispatch.borrow(playerCharacter, mnm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); //Add Minion @@ -275,7 +284,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { ManageNPCMsg mnm = new ManageNPCMsg(npc); mnm.setMessageType(1); - Dispatch dispatch = Dispatch.borrow(player, mnm); + Dispatch dispatch = Dispatch.borrow(playerCharacter, mnm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } catch (Exception e) {