Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: item drop loot with charges and /i talkaction #1937

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions data/libs/functions/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Container:addLoot(loot)
logger.warn("Container:addLoot: invalid item type: {}", itemId)
goto continue
end
if iType:isStackable() or iType:getCharges() ~= 0 then
if iType:isStackable() then
local stackSize = iType:getStackSize()
local remainingCount = item.count

Expand All @@ -23,9 +23,13 @@ function Container:addLoot(loot)
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
elseif 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 charge item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
end
else
for i = 1, item.count do
local tmpItem = self:addItem(itemId, 1, INDEX_WHEREEVER, FLAG_NOLIMIT)
Expand Down
18 changes: 14 additions & 4 deletions data/scripts/talkactions/god/create_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ function createItem.onSay(player, words, param)
local count = tonumber(split[2])
if count then
if itemType:isStackable() then
local stackSize = itemType:getStackSize()
local container = Game.createItem(2854)
local mainContainer = player:getSlotItem(CONST_SLOT_BACKPACK)
if not mainContainer then
player:addItemEx(Game.createItem(2854), CONST_SLOT_BACKPACK)
mainContainer = player:getSlotItem(CONST_SLOT_BACKPACK)
end
local remainingCount = count
local stackSize = itemType:getStackSize()

while remainingCount > 0 do
local freeSlots = mainContainer and (mainContainer:getCapacity() - mainContainer:getSize()) or 0
if freeSlots <= 1 and mainContainer:getSize() ~= 0 then
mainContainer = Game.createItem(2854)
player:addItemEx(mainContainer)
end

local countToAdd = math.min(remainingCount, stackSize)
local tmpItem = container:addItem(itemType:getId(), countToAdd, INDEX_WHEREEVER, FLAG_NOLIMIT)
local tmpItem = mainContainer:addItem(itemType:getId(), countToAdd)
if tmpItem then
remainingCount = remainingCount - countToAdd
else
logger.warn("Failed to add item: {}, to container", itemType:getName())
break
end
end

player:addItemEx(container)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
return true
elseif not itemType:isFluidContainer() then
Expand Down