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

Rich item copy for inventory drops #1346

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Update dump_offline_inventories.lua
Change corpse inventories to rich copies so it preserves equipment grids.
  • Loading branch information
Soggs committed Feb 10, 2023
commit 2b8d57002ff1fd597353c3384a1475fe8b055180
40 changes: 17 additions & 23 deletions features/dump_offline_inventories.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,13 @@ local function spawn_player_corpse(player, banned, timeout_minutes)
local inv_main = player.get_inventory(defines.inventory.character_main)
local inv_trash = player.get_inventory(defines.inventory.character_trash)

local inv_main_contents
if inv_main and inv_main.valid then
inv_main_contents = inv_main.get_contents()
end

local inv_trash_contents
if inv_trash and inv_trash.valid then
inv_trash_contents = inv_trash.get_contents()
end

local inv_corpse_size = 0
if inv_main_contents then
if inv_main and inv_main.valid and not inv_main.is_empty() then
inv_corpse_size = inv_corpse_size + (#inv_main - inv_main.count_empty_stacks())
end

if inv_trash_contents then
if inv_trash and inv_trash.valid and not inv_trash.is_empty() then
inv_corpse_size = inv_corpse_size + (#inv_trash - inv_trash.count_empty_stacks())
end

if inv_corpse_size <= 0 then
return
end
Expand All @@ -63,17 +51,23 @@ local function spawn_player_corpse(player, banned, timeout_minutes)

local inv_corpse = corpse.get_inventory(defines.inventory.character_corpse)

for item_name, count in pairs(inv_main_contents or {}) do
inv_corpse.insert({name = item_name, count = count})
end
for item_name, count in pairs(inv_trash_contents or {}) do
inv_corpse.insert({name = item_name, count = count})
end

if inv_main_contents then
local i = 1 -- corpse inventory counter
if not inv_main.is_empty() then
for j = 1, #inv_main do
if inv_main[j].valid_to_read then
inv_corpse[i].transfer_stack(inv_main[j])
i = i + 1
end
end
inv_main.clear()
end
if inv_trash_contents then
if not inv_trash.is_empty() then
for j = 1, #inv_trash do
if inv_trash[j].valid_to_read then
inv_corpse[i].transfer_stack(inv_trash[j])
i = i + 1
end
end
inv_trash.clear()
end

Expand Down