Browse Source

Cleanup of clear minion logic.

feature-workorder
MagicBot 1 year ago
parent
commit
779e3da74e
  1. 53
      src/engine/net/client/handlers/MinionTrainingMsgHandler.java

53
src/engine/net/client/handlers/MinionTrainingMsgHandler.java

@ -15,9 +15,6 @@ import engine.net.client.msg.*; @@ -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; @@ -26,8 +23,6 @@ import java.util.HashMap;
public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
public static HashMap<Integer, ArrayList<Integer>> _minionsByCaptain = null;
public MinionTrainingMsgHandler() {
super(MinionTrainingMessage.class);
}
@ -37,10 +32,11 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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) {

Loading…
Cancel
Save