diff --git a/sonic-radiance.love/game/loot/init.lua b/sonic-radiance.love/game/loot/init.lua index 7b6e636..0ba6070 100644 --- a/sonic-radiance.love/game/loot/init.lua +++ b/sonic-radiance.love/game/loot/init.lua @@ -51,6 +51,13 @@ function LootManager:addItem(type, item, number) end end +function LootManager:removeItem(type, item, number) + local pocket = self:getPocketByName(type) + if (itemutils.itemExists(type, item)) then + pocket:removeItem(item, number) + end +end + function LootManager:getItemData(type, item) return itemutils.getItemData(type, item) end diff --git a/sonic-radiance.love/game/loot/pocket.lua b/sonic-radiance.love/game/loot/pocket.lua index 39cf081..f0616c5 100644 --- a/sonic-radiance.love/game/loot/pocket.lua +++ b/sonic-radiance.love/game/loot/pocket.lua @@ -26,6 +26,18 @@ function Pocket:addItem(item, number) end end +function Pocket:removeItem(item, number) + for i,itemData in ipairs(self.list) do + if (itemData.name == item) then + if (itemData.number > number) then + itemData.number = itemData.number - number + else + table.remove(self.list, i) + end + end + end +end + function Pocket:getItem(name) for i, itemData in ipairs(self.list) do if (itemData.name == name) then