Browse Source

Rework of error handling.

combat-2
MagicBot 7 months ago
parent
commit
2feba8ac50
  1. 49
      src/engine/gameManager/ForgeManager.java
  2. 12
      src/engine/net/client/handlers/ItemProductionMsgHandler.java

49
src/engine/gameManager/ForgeManager.java

@ -10,8 +10,10 @@ package engine.gameManager;
import engine.loot.WorkOrder; import engine.loot.WorkOrder;
import engine.mbEnums; import engine.mbEnums;
import engine.net.client.msg.ErrorPopupMsg; import engine.objects.Item;
import engine.objects.*; import engine.objects.ItemTemplate;
import engine.objects.MobLoot;
import engine.objects.Warehouse;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -86,7 +88,12 @@ public enum ForgeManager implements Runnable {
forgeManager.start(); 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.workOrderID = wordOrderCounter.incrementAndGet();
workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder);
@ -111,39 +118,33 @@ public enum ForgeManager implements Runnable {
Logger.info(workOrder.toString()); Logger.info(workOrder.toString());
workOrder.vendor.workOrders.add(workOrder); workOrder.vendor.workOrders.add(workOrder);
forge.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); ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID);
if (!workOrder.vendor.charItemManager.hasRoomInventory(template.item_wt)) { if (!workOrder.vendor.charItemManager.hasRoomInventory(template.item_wt))
if (playerCharacter != null) return 30; //30: That person cannot carry that item
ErrorPopupMsg.sendErrorPopup(playerCharacter, 30); //30: That person cannot carry that item
return false;
}
if (!workOrder.vendor.getItemModTable().contains(((byte) template.modTable))) { if (!workOrder.vendor.getItemModTable().contains(((byte) template.modTable)))
if (playerCharacter != null) return 59; //59: This hireling does not have this formula
ErrorPopupMsg.sendErrorPopup(playerCharacter, 59); //59: This hireling does not have this formula
return false;
}
if (!calcCostOverrun(workOrder).isEmpty()) {
if (playerCharacter != null) if (!calcCostOverrun(workOrder).isEmpty())
ErrorPopupMsg.sendErrorPopup(playerCharacter, 18); //18: You can't really afford that return 10; //18: You can't really afford that
return false;
}
// Forge must be protected in order to access warehouse. // Forge must be protected in order to access warehouse.
if (calcProductionCost(workOrder).size() > 1) if (calcProductionCost(workOrder).size() > 1)
if (!workOrder.vendor.building.protectionState.equals(mbEnums.ProtectionState.PROTECTED)) { if (!workOrder.vendor.building.protectionState.equals(mbEnums.ProtectionState.PROTECTED))
if (playerCharacter != null) return 193; //193: Production denied: This building must be protected to gain access to warehouse
ErrorPopupMsg.sendErrorPopup(playerCharacter, 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) { public static long calcRollingDuration(WorkOrder workOrder) {

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

@ -88,14 +88,16 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
workOrder.item_name_override = msg.name; workOrder.item_name_override = msg.name;
workOrder.multiple_slot_request = msg.size; workOrder.multiple_slot_request = msg.size;
// Validate vendor can roll this item // Submit workOder to begin rolling items
if (ForgeManager.validate(player, workOrder) == false) int validation_result = ForgeManager.submit(workOrder);
return true;
// 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 //Create Multiple Item Function.. Fill all empty slots

Loading…
Cancel
Save