From 2feba8ac50ae52a27601b9269466f52f994794b7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 14 Apr 2024 12:08:51 -0400 Subject: [PATCH] Rework of error handling. --- src/engine/gameManager/ForgeManager.java | 49 ++++++++++--------- .../handlers/ItemProductionMsgHandler.java | 12 +++-- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index fc507586..b941d1f9 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -10,8 +10,10 @@ package engine.gameManager; import engine.loot.WorkOrder; import engine.mbEnums; -import engine.net.client.msg.ErrorPopupMsg; -import engine.objects.*; +import engine.objects.Item; +import engine.objects.ItemTemplate; +import engine.objects.MobLoot; +import engine.objects.Warehouse; import engine.powers.EffectsBase; import org.pmw.tinylog.Logger; @@ -86,7 +88,12 @@ public enum ForgeManager implements Runnable { forgeManager.start(); } - public static void submit(WorkOrder workOrder) { + public static int submit(WorkOrder workOrder) { + + int validation_result = ForgeManager.validate(workOrder); + + if (validation_result != 0) + return validation_result; workOrder.workOrderID = wordOrderCounter.incrementAndGet(); workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); @@ -111,39 +118,33 @@ public enum ForgeManager implements Runnable { Logger.info(workOrder.toString()); workOrder.vendor.workOrders.add(workOrder); forge.add(workOrder); + + return validation_result; } - public static boolean validate(PlayerCharacter playerCharacter, WorkOrder workOrder) { + public static int validate(WorkOrder workOrder) { + + int validation_result = 0; ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID); - if (!workOrder.vendor.charItemManager.hasRoomInventory(template.item_wt)) { - if (playerCharacter != null) - ErrorPopupMsg.sendErrorPopup(playerCharacter, 30); //30: That person cannot carry that item - return false; - } + if (!workOrder.vendor.charItemManager.hasRoomInventory(template.item_wt)) + return 30; //30: That person cannot carry that item - if (!workOrder.vendor.getItemModTable().contains(((byte) template.modTable))) { - if (playerCharacter != null) - ErrorPopupMsg.sendErrorPopup(playerCharacter, 59); //59: This hireling does not have this formula - return false; - } + if (!workOrder.vendor.getItemModTable().contains(((byte) template.modTable))) + return 59; //59: This hireling does not have this formula - if (!calcCostOverrun(workOrder).isEmpty()) { - if (playerCharacter != null) - ErrorPopupMsg.sendErrorPopup(playerCharacter, 18); //18: You can't really afford that - return false; - } + + if (!calcCostOverrun(workOrder).isEmpty()) + return 10; //18: You can't really afford that // Forge must be protected in order to access warehouse. if (calcProductionCost(workOrder).size() > 1) - if (!workOrder.vendor.building.protectionState.equals(mbEnums.ProtectionState.PROTECTED)) { - if (playerCharacter != null) - ErrorPopupMsg.sendErrorPopup(playerCharacter, 193); //193: Production denied: This building must be protected to gain access to warehouse - } + if (!workOrder.vendor.building.protectionState.equals(mbEnums.ProtectionState.PROTECTED)) + return 193; //193: Production denied: This building must be protected to gain access to warehouse - return true; + return validation_result; } public static long calcRollingDuration(WorkOrder workOrder) { diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index b42b5dd4..99a5cdbf 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -88,14 +88,16 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { workOrder.item_name_override = msg.name; workOrder.multiple_slot_request = msg.size; - // Validate vendor can roll this item + // Submit workOder to begin rolling items - if (ForgeManager.validate(player, workOrder) == false) - return true; + int validation_result = ForgeManager.submit(workOrder); - // Start rolling the item(s) + // workOrder cannot be completed - ForgeManager.submit(workOrder); + if (validation_result != 0) { + ErrorPopupMsg.sendErrorPopup(player, validation_result); + return true; + } //Create Multiple Item Function.. Fill all empty slots