Browse Source

Handler uses enumeration

combat-2
MagicBot 7 months ago
parent
commit
cf38362d84
  1. 55
      src/engine/net/client/handlers/ItemProductionMsgHandler.java

55
src/engine/net/client/handlers/ItemProductionMsgHandler.java

@ -34,17 +34,6 @@ import java.util.HashMap;
*/ */
public class ItemProductionMsgHandler extends AbstractClientMsgHandler { 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() { public ItemProductionMsgHandler() {
super(ItemProductionMsg.class); super(ItemProductionMsg.class);
} }
@ -77,11 +66,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
return; return;
} }
targetItem.setValue(itemPrice); 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); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); 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); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} else if (targetItem.getObjectType() == GameObjectType.MobLoot) { } else if (targetItem.getObjectType() == GameObjectType.MobLoot) {
@ -91,11 +80,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
return; return;
} }
targetItem.setValue(itemPrice); 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); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); 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); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); 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); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); 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); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
@ -218,7 +207,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
vendor.removeItemFromForge(targetItem); vendor.removeItemFromForge(targetItem);
outMsg = new ManageNPCMsg(vendor); outMsg = new ManageNPCMsg(vendor);
outMsg.setMessageType(ACTION_PRODUCE); outMsg.setMessageType(mbEnums.ProductionActionType.PRODUCE.ordinal());
dispatch = Dispatch.borrow(player, outMsg); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} finally { } finally {
@ -299,7 +288,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
// ChatManager.chatSystemInfo(player, "Took " + timetook + " ms to finish"); // 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); dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
@ -452,9 +441,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
// Process Request // Process Request
switch (msg.getActionType()) { mbEnums.ProductionActionType actionType = mbEnums.ProductionActionType.values()[msg.getActionType()];
switch (actionType) {
case ACTION_PRODUCE: case PRODUCE:
boolean isRandom = false; boolean isRandom = false;
if (msg.getUnknown03() != 0 && msg.getpToken() == 0 && msg.getsToken() == 0) if (msg.getUnknown03() != 0 && msg.getpToken() == 0 && msg.getsToken() == 0)
isRandom = true; isRandom = true;
@ -469,39 +460,29 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
} else } else
vendorNPC.produceItem(player.getObjectUUID(), msg.getTotal_to_produce(), isRandom, msg.getpToken(), msg.getsToken(), msg.getName(), msg.getTemplateID()); vendorNPC.produceItem(player.getObjectUUID(), msg.getTotal_to_produce(), isRandom, msg.getpToken(), msg.getsToken(), msg.getName(), msg.getTemplateID());
break; break;
case ACTION_JUNK: case JUNK:
junkItem(msg.getTemplateID(), vendorNPC, origin); junkItem(msg.getTemplateID(), vendorNPC, origin);
break; break;
case ACTION_RECYCLE: case RECYCLE:
recycleItem(msg.getItems(), vendorNPC, origin); recycleItem(msg.getItems(), vendorNPC, origin);
msg.setActionType(7); msg.setActionType(7);
dispatch = Dispatch.borrow(player, msg); dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
break; break;
case ACTION_COMPLETE: case COMPLETE:
vendorNPC.completeItem(msg.getTemplateID()); vendorNPC.completeItem(msg.getTemplateID());
// ManageNPCMsg outMsg = new ManageNPCMsg(vendorNPC);
// outMsg.setMessageType(1);
//
// dispatch = Dispatch.borrow(player, outMsg);
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
break; break;
case ACTION_DEPOSIT: case DEPOSIT:
depositItem(msg.getTemplateID(), vendorNPC, origin); depositItem(msg.getTemplateID(), vendorNPC, origin);
break; break;
case ACTION_SETPRICE: case SETPRICE:
setItemPrice(msg.getItemType(), msg.getTemplateID(), msg.getItemPrice(), vendorNPC, origin); setItemPrice(msg.getItemType(), msg.getTemplateID(), msg.getItemPrice(), vendorNPC, origin);
break; break;
case ACTION_TAKE: case TAKE:
takeItem(msg.getItems(), vendorNPC, origin); takeItem(msg.getItems(), vendorNPC, origin);
dispatch = Dispatch.borrow(player, msg); dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
break; break;
} }
return true; return true;
} }

Loading…
Cancel
Save