diff --git a/wadsrc/static/zscript/actors/inventory/inventory.zs b/wadsrc/static/zscript/actors/inventory/inventory.zs index 40a89cb08..10ee3a5f2 100644 --- a/wadsrc/static/zscript/actors/inventory/inventory.zs +++ b/wadsrc/static/zscript/actors/inventory/inventory.zs @@ -923,6 +923,25 @@ class Inventory : Actor } } + //=========================================================================== + // + // Inventory :: DepleteBy + // + // Handles item depletion when using or taking items + // + //=========================================================================== + virtual void DepleteBy(int by) + { + if (amount < 1 || by >= amount) + { + DepleteOrDestroy(); + } + else + { + amount -= by; + } + } + //=========================================================================== // // Inventory :: DepleteOrDestroy diff --git a/wadsrc/static/zscript/actors/inventory_util.zs b/wadsrc/static/zscript/actors/inventory_util.zs index 011ca134f..6b35a2898 100644 --- a/wadsrc/static/zscript/actors/inventory_util.zs +++ b/wadsrc/static/zscript/actors/inventory_util.zs @@ -146,11 +146,7 @@ extend class Actor if (!fromdecorate) { - item.Amount -= amount; - if (item.Amount <= 0) - { - item.DepleteOrDestroy(); - } + item.DepleteBy(amount); // It won't be used in non-decorate context, so return false here return false; } @@ -169,11 +165,10 @@ extend class Actor // Nothing to do here, except maybe res = false;? Would it make sense? result = false; } - else if (!amount || amount >= item.Amount) + else { - item.DepleteOrDestroy(); + item.DepleteBy(amount); } - else item.Amount -= amount; return result; } @@ -271,10 +266,9 @@ extend class Actor { return true; } - - if (--item.Amount <= 0) + else { - item.DepleteOrDestroy (); + item.DepleteBy(1); //useinventory can only really use one item at a time } return true; }