From 2b8d57002ff1fd597353c3384a1475fe8b055180 Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 12:51:50 +0100 Subject: [PATCH 1/7] Update dump_offline_inventories.lua Change corpse inventories to rich copies so it preserves equipment grids. --- features/dump_offline_inventories.lua | 40 ++++++++++++--------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index 5ea29689a..7e9a1c81a 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -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 @@ -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 From c75d6680a986f3950a3f8d41e7be2476351b4987 Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 13:10:51 +0100 Subject: [PATCH 2/7] Update dump_offline_inventories.lua --- features/dump_offline_inventories.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index 7e9a1c81a..e27a95f3f 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -59,7 +59,6 @@ local function spawn_player_corpse(player, banned, timeout_minutes) i = i + 1 end end - inv_main.clear() end if not inv_trash.is_empty() then for j = 1, #inv_trash do @@ -68,7 +67,6 @@ local function spawn_player_corpse(player, banned, timeout_minutes) i = i + 1 end end - inv_trash.clear() end local text = player.name .. "'s inventory (offline)" From b4b3684a4fd0cc9e42b564275bfedc8ea8f5e14c Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 14:09:14 +0100 Subject: [PATCH 3/7] Added item filtering for offline corpse dumps --- config.lua | 1 + features/dump_offline_inventories.lua | 35 ++++++++++++++------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/config.lua b/config.lua index 798e1f525..20e56104b 100644 --- a/config.lua +++ b/config.lua @@ -85,6 +85,7 @@ global.config = { dump_offline_inventories = { enabled = false, offline_timout_mins = 15, -- time after which a player logs off that their inventory is provided to the team + ignored_items = {} -- list of prototype names that remain in the player inventory }, -- enables players to create and prioritize tasks tasklist = { diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index e27a95f3f..0cfa665bc 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -11,6 +11,11 @@ local Config = require 'config' local set_timeout_in_ticks = Task.set_timeout_in_ticks local config = Config.dump_offline_inventories +local ignored_items_set = {} +for _ , k in pairs(config.ignored_items) + ignored_items_set[k] = true +end + local offline_player_queue = {} Global.register({offline_player_queue = offline_player_queue}, function(tbl) @@ -18,6 +23,17 @@ Global.register({offline_player_queue = offline_player_queue}, function(tbl) config = Config.dump_offline_inventories end) +local function move_items(source, target) + if not source.is_empty() then + for i = 1, #source do + if source[i].valid_to_read and not ignored_items_set[source[i].name] then + target.insert(source[i]) + source[i].clear() + end + end + end +end + local function spawn_player_corpse(player, banned, timeout_minutes) local player_index = player.index offline_player_queue[player_index] = nil @@ -51,23 +67,8 @@ local function spawn_player_corpse(player, banned, timeout_minutes) local inv_corpse = corpse.get_inventory(defines.inventory.character_corpse) - 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 - end - 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 - end + move_items(inv_main, inv_corpse) + move_items(inv_trash, inv_corpse) local text = player.name .. "'s inventory (offline)" local tag = player.force.add_chart_tag(player.surface, { From afdb8f150bef86f6e3a7f6d4de5ebdc2692e6da3 Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 14:13:31 +0100 Subject: [PATCH 4/7] Update dump_offline_inventories.lua --- features/dump_offline_inventories.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index 0cfa665bc..4f71463de 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -12,7 +12,7 @@ local set_timeout_in_ticks = Task.set_timeout_in_ticks local config = Config.dump_offline_inventories local ignored_items_set = {} -for _ , k in pairs(config.ignored_items) +for _ , k in pairs(config.ignored_items) do ignored_items_set[k] = true end From 1836ef61aa66da6e588a9b24179459859ae1c91a Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 14:15:24 +0100 Subject: [PATCH 5/7] Update dump_offline_inventories.lua --- features/dump_offline_inventories.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index 4f71463de..c345ccd47 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -26,7 +26,7 @@ end) local function move_items(source, target) if not source.is_empty() then for i = 1, #source do - if source[i].valid_to_read and not ignored_items_set[source[i].name] then + if source[i].valid_for_read and not ignored_items_set[source[i].name] then target.insert(source[i]) source[i].clear() end From ae76d9f89e1f9a9966768d3283ed368a4665d5ed Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 14:34:25 +0100 Subject: [PATCH 6/7] Update dump_offline_inventories.lua --- features/dump_offline_inventories.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index c345ccd47..696c06f0c 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -26,9 +26,10 @@ end) local function move_items(source, target) if not source.is_empty() then for i = 1, #source do - if source[i].valid_for_read and not ignored_items_set[source[i].name] then - target.insert(source[i]) - source[i].clear() + local stack = source[i] + if stack.valid_for_read and not ignored_items_set[stack.name] then + target.insert(stack) + stack.clear() end end end From 91dc1f97a0073d81660ed9285385618535ac95fd Mon Sep 17 00:00:00 2001 From: Soggs Date: Fri, 10 Feb 2023 14:44:07 +0100 Subject: [PATCH 7/7] Update dump_offline_inventories.lua --- features/dump_offline_inventories.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index 696c06f0c..dc9791c7f 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -27,7 +27,7 @@ local function move_items(source, target) if not source.is_empty() then for i = 1, #source do local stack = source[i] - if stack.valid_for_read and not ignored_items_set[stack.name] then + if stack.valid_for_read and not stack.is_selection_tool() and not stack.is_blueprint_book() and not ignored_items_set[stack.name] then target.insert(stack) stack.clear() end