From cf38362d84974943f9303bbb72b90c38216fe020 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 7 Apr 2024 12:45:13 -0400 Subject: [PATCH] Handler uses enumeration --- .../handlers/ItemProductionMsgHandler.java | 55 ++++++------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index c5a32c33..cdce3cb7 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -34,17 +34,6 @@ import java.util.HashMap; */ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { - private static final int ACTION_PRODUCE = 1; - private static final int ACTION_JUNK = 2; - private static final int ACTION_RECYCLE = 3; - private static final int ACTION_COMPLETE = 4; - private static final int ACTION_DEPOSIT = 6; - private static final int ACTION_SETPRICE = 5; - private static final int ACTION_TAKE = 7; - private static final int ACTION_CONFIRM_SETPRICE = 9; // Unsure. Sent by client - private static final int ACTION_CONFIRM_DEPOSIT = 10; // Unsure. Sent by client - private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client - public ItemProductionMsgHandler() { super(ItemProductionMsg.class); } @@ -77,11 +66,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { return; } targetItem.setValue(itemPrice); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.DEPOSIT.ordinal(), true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_SETPRICE, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.SETPRICE.ordinal(), true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); } else if (targetItem.getObjectType() == GameObjectType.MobLoot) { @@ -91,11 +80,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { return; } targetItem.setValue(itemPrice); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.DEPOSIT.ordinal(), true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_SETPRICE, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.SETPRICE.ordinal(), true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); } @@ -158,11 +147,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { } - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.DEPOSIT.ordinal(), true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_CONFIRM_DEPOSIT, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.CONFIRM_DEPOSIT.ordinal(), true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); @@ -218,7 +207,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { vendor.removeItemFromForge(targetItem); outMsg = new ManageNPCMsg(vendor); - outMsg.setMessageType(ACTION_PRODUCE); + outMsg.setMessageType(mbEnums.ProductionActionType.PRODUCE.ordinal()); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); } finally { @@ -299,7 +288,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { // ChatManager.chatSystemInfo(player, "Took " + timetook + " ms to finish"); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_TAKE, true); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.TAKE.ordinal(), true); dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); @@ -452,9 +441,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { // Process Request - switch (msg.getActionType()) { + mbEnums.ProductionActionType actionType = mbEnums.ProductionActionType.values()[msg.getActionType()]; + + switch (actionType) { - case ACTION_PRODUCE: + case PRODUCE: boolean isRandom = false; if (msg.getUnknown03() != 0 && msg.getpToken() == 0 && msg.getsToken() == 0) isRandom = true; @@ -469,39 +460,29 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { } else vendorNPC.produceItem(player.getObjectUUID(), msg.getTotal_to_produce(), isRandom, msg.getpToken(), msg.getsToken(), msg.getName(), msg.getTemplateID()); break; - case ACTION_JUNK: + case JUNK: junkItem(msg.getTemplateID(), vendorNPC, origin); break; - case ACTION_RECYCLE: + case RECYCLE: recycleItem(msg.getItems(), vendorNPC, origin); msg.setActionType(7); dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); break; - case ACTION_COMPLETE: - + case COMPLETE: vendorNPC.completeItem(msg.getTemplateID()); - - // ManageNPCMsg outMsg = new ManageNPCMsg(vendorNPC); - // outMsg.setMessageType(1); - // - // dispatch = Dispatch.borrow(player, outMsg); - // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - break; - case ACTION_DEPOSIT: + case DEPOSIT: depositItem(msg.getTemplateID(), vendorNPC, origin); break; - case ACTION_SETPRICE: + case SETPRICE: setItemPrice(msg.getItemType(), msg.getTemplateID(), msg.getItemPrice(), vendorNPC, origin); break; - case ACTION_TAKE: + case TAKE: takeItem(msg.getItems(), vendorNPC, origin); dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); break; - } return true; }