From 0c0f0aa54d09cce8e4078c03dfbe6d1d0e10db87 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 17 Mar 2024 12:25:59 -0400 Subject: [PATCH] Overdraft method written --- src/engine/objects/Warehouse.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index adcd6b9d..39d2c064 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -25,6 +25,7 @@ import org.pmw.tinylog.Logger; import java.sql.SQLException; import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; public class Warehouse { @@ -68,6 +69,20 @@ public class Warehouse { } + public static HashMap calculateWarehouseOverdraft(Warehouse warehouse, HashMap costMap) { + HashMap overdraft = new HashMap<>(); + + for (Enum.ResourceType resourceType : costMap.keySet()) { + + int cost = costMap.get(resourceType); + + if (cost > warehouse.resources.get(resourceType)) + overdraft.put(resourceType, cost - warehouse.resources.get(resourceType)); + } + + return overdraft; + } + public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc) { Building warehouseBuilding;