From 7b375bfed2f23d2392e81338b421de0a9f34aae4 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 12 Mar 2021 20:54:45 +0100 Subject: [PATCH] feat: add item removal functions --- sonic-radiance.love/game/loot/init.lua | 7 +++++++ sonic-radiance.love/game/loot/pocket.lua | 12 ++++++++++++ 2 files changed, 19 insertions(+) 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