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; @@ -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 { @@ -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 { @@ -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) {

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

@ -88,14 +88,16 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { @@ -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

Loading…
Cancel
Save