From 24c702d981b10b4ec3f7f916afc79c1b07685b79 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 21 Nov 2023 02:12:50 -0300 Subject: [PATCH] fix: ensure loot over stack size drops in multiple stacks (#1862) Resolves #1838 --- data/libs/functions/container.lua | 16 ++++++++++++---- .../monster/ondroploot_wealth_duplex.lua | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/data/libs/functions/container.lua b/data/libs/functions/container.lua index 30131fec934..5b85e297872 100644 --- a/data/libs/functions/container.lua +++ b/data/libs/functions/container.lua @@ -13,10 +13,18 @@ function Container:addLoot(loot) goto continue end if iType:isStackable() or iType:getCharges() ~= 0 then - local tmpItem = self:addItem(itemId, item.count, INDEX_WHEREEVER, FLAG_NOLIMIT) - if not tmpItem then - logger.warn("Container:addLoot: failed to add item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId()) - goto continue + local stackSize = iType:getStackSize() + local remainingCount = item.count + + while remainingCount > 0 do + local countToAdd = math.min(remainingCount, stackSize) + local tmpItem = self:addItem(itemId, countToAdd, INDEX_WHEREEVER, FLAG_NOLIMIT) + if not tmpItem then + logger.warn("Container:addLoot: failed to add stackable item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId()) + goto continue + end + + remainingCount = remainingCount - countToAdd end else for i = 1, item.count do diff --git a/data/scripts/eventcallbacks/monster/ondroploot_wealth_duplex.lua b/data/scripts/eventcallbacks/monster/ondroploot_wealth_duplex.lua index add4273dad7..008352174f4 100644 --- a/data/scripts/eventcallbacks/monster/ondroploot_wealth_duplex.lua +++ b/data/scripts/eventcallbacks/monster/ondroploot_wealth_duplex.lua @@ -29,7 +29,7 @@ function callback.monsterOnDropLoot(monster, corpse) local wealthDuplex = Concoction.find(Concoction.Ids.WealthDuplex) if not wealthDuplex then - logger.warn("[Monster:onDropLoot] - Could not find WealthDuplex concoction.") + logger.debug("[Monster:onDropLoot] - Could not find WealthDuplex concoction.") return end local chance = 0