From 30800478f20b981a42ad03726cc717e9f54d1122 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 7 Apr 2024 12:04:15 -0400 Subject: [PATCH] Message now uses enum --- src/engine/mbEnums.java | 15 +++++ .../net/client/msg/ItemProductionMsg.java | 59 ++++++++----------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/engine/mbEnums.java b/src/engine/mbEnums.java index 251aee27..0196d136 100644 --- a/src/engine/mbEnums.java +++ b/src/engine/mbEnums.java @@ -3024,5 +3024,20 @@ public class mbEnums { } } + + public enum ProductionActionType { + NONE, + PRODUCE, + JUNK, + RECYCLE, + COMPLETE, + SETPRICE, + DEPOSIT, + TAKE, + CONFIRM_PRODUCE, + CONFIRM_SETPRICE, + CONFIRM_DEPOSIT, + CONFIRM_TAKE; + } } diff --git a/src/engine/net/client/msg/ItemProductionMsg.java b/src/engine/net/client/msg/ItemProductionMsg.java index ea684a7a..fafd075c 100644 --- a/src/engine/net/client/msg/ItemProductionMsg.java +++ b/src/engine/net/client/msg/ItemProductionMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.gameManager.BuildingManager; import engine.gameManager.PowersManager; +import engine.mbEnums; import engine.mbEnums.GameObjectType; import engine.net.*; import engine.objects.Building; @@ -23,18 +24,6 @@ import java.util.HashMap; public class ItemProductionMsg extends ClientNetMsg { - 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; - private static final int ACTION_CONFIRM_DEPOSIT = 10; - private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client - private static final int ACTION_CONFIRM_PRODUCE = 8; - private int size; private int buildingUUID; private int unknown01; @@ -45,7 +34,7 @@ public class ItemProductionMsg extends ClientNetMsg { private int pToken; private int sToken; private String name; - private int actionType; + private mbEnums.ProductionActionType actionType; private int npcUUID; private boolean add; private int itemPrice; @@ -57,7 +46,7 @@ public class ItemProductionMsg extends ClientNetMsg { public ItemProductionMsg() { super(Protocol.ITEMPRODUCTION); - this.actionType = 0; + this.actionType = mbEnums.ProductionActionType.NONE; this.size = 0; this.buildingUUID = 0; this.unknown01 = 0; @@ -76,7 +65,7 @@ public class ItemProductionMsg extends ClientNetMsg { public ItemProductionMsg(Building building, NPC vendor, Item item, int actionType, boolean add) { super(Protocol.ITEMPRODUCTION); - this.actionType = actionType; + this.actionType = mbEnums.ProductionActionType.values()[actionType]; this.size = 0; this.buildingUUID = building.getObjectUUID(); this.npcUUID = vendor.getObjectUUID(); @@ -123,7 +112,7 @@ public class ItemProductionMsg extends ClientNetMsg { return; // Common Header - writer.putInt(this.actionType); + writer.putInt(this.actionType.ordinal()); writer.putInt(GameObjectType.Building.ordinal()); writer.putInt(this.buildingUUID); writer.putInt(GameObjectType.NPC.ordinal()); @@ -131,7 +120,7 @@ public class ItemProductionMsg extends ClientNetMsg { switch (this.actionType) { - case ACTION_CONFIRM_DEPOSIT: + case CONFIRM_DEPOSIT: writer.putInt(0); // Not item ordinal? writer.putInt(0); // Not item uuid? writer.putInt(1); @@ -164,7 +153,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.put((byte) 0); break; - case ACTION_CONFIRM_TAKE: + case CONFIRM_TAKE: writer.putInt(this.itemType); writer.putInt(this.templateID); writer.putInt(1); @@ -176,7 +165,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.put((byte) 0); break; - case ACTION_SETPRICE: + case SETPRICE: writer.putInt(this.itemType); writer.putInt(this.templateID); writer.putInt(1); @@ -189,7 +178,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.put((byte) 0); break; - case ACTION_CONFIRM_SETPRICE: + case CONFIRM_SETPRICE: writer.putInt(this.itemType); writer.putInt(this.templateID); writer.putInt(1); @@ -203,7 +192,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); //writer.put((byte) 0); break; - case ACTION_DEPOSIT: + case DEPOSIT: writer.putInt(this.itemType); writer.putInt(this.templateID); writer.putInt(1); @@ -215,8 +204,8 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.put((byte) 0); break; - case ACTION_TAKE: - case ACTION_RECYCLE: + case TAKE: + case RECYCLE: writer.putInt(0); writer.putInt(0); @@ -242,7 +231,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); break; - case ACTION_CONFIRM_PRODUCE: + case CONFIRM_PRODUCE: writer.putInt(0); writer.putInt(0); writer.putInt(1); @@ -320,7 +309,7 @@ public class ItemProductionMsg extends ClientNetMsg { //writer.putInt(0); //error popup break; - case ACTION_COMPLETE: + case COMPLETE: writer.putInt(this.itemType); writer.putInt(this.templateID); writer.putInt(this.total_to_produce); @@ -332,7 +321,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.put((byte) 0); break; - case ACTION_JUNK: + case JUNK: writer.putInt(this.itemType); writer.putInt(this.templateID); writer.putInt(this.total_to_produce); @@ -363,14 +352,14 @@ public class ItemProductionMsg extends ClientNetMsg { // Common header - this.actionType = reader.getInt(); + this.actionType = mbEnums.ProductionActionType.values()[reader.getInt()]; reader.getInt(); // Building type padding this.buildingUUID = reader.getInt(); reader.getInt(); // NPC type padding this.npcUUID = reader.getInt(); switch (this.actionType) { - case ACTION_SETPRICE: + case SETPRICE: this.itemType = reader.getInt(); this.templateID = reader.getInt(); reader.getInt(); @@ -383,8 +372,8 @@ public class ItemProductionMsg extends ClientNetMsg { reader.getInt(); reader.get(); break; - case ACTION_RECYCLE: - case ACTION_TAKE: + case RECYCLE: + case TAKE: reader.getInt(); reader.getInt(); reader.getInt(); @@ -403,7 +392,7 @@ public class ItemProductionMsg extends ClientNetMsg { reader.getInt(); this.items = tempIDs; break; - case ACTION_DEPOSIT: + case DEPOSIT: this.itemType = reader.getInt(); this.templateID = reader.getInt(); reader.getInt(); @@ -415,7 +404,7 @@ public class ItemProductionMsg extends ClientNetMsg { reader.getInt(); reader.get(); break; - case ACTION_JUNK: + case JUNK: this.itemType = reader.getInt(); this.templateID = reader.getInt(); this.total_to_produce = reader.getInt(); @@ -438,7 +427,7 @@ public class ItemProductionMsg extends ClientNetMsg { this.size = reader.getInt(); reader.getInt(); - if (this.actionType == ACTION_COMPLETE || this.actionType == ACTION_JUNK) + if (this.actionType == mbEnums.ProductionActionType.COMPLETE || this.actionType == mbEnums.ProductionActionType.JUNK) reader.get(); else reader.getShort(); @@ -516,11 +505,11 @@ public class ItemProductionMsg extends ClientNetMsg { } public int getActionType() { - return actionType; + return actionType.ordinal(); } public final void setActionType(int actionType) { - this.actionType = actionType; + this.actionType = mbEnums.ProductionActionType.values()[actionType]; } public int getNpcUUID() {