mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-11 14:49:59 +02:00
WIP
This commit is contained in:
parent
c0da8fbdc7
commit
a4d9707f42
@ -84,8 +84,8 @@ global.config = {
|
||||
-- enables dumping of inventories of offline players to a corpse near spawn
|
||||
-- This feature is dependant upon corpse_util and will enable it
|
||||
dump_offline_inventories = {
|
||||
enabled = true,
|
||||
offline_timout_mins = 1, -- time after which a player logs off that their inventory is provided to the team
|
||||
enabled = false,
|
||||
offline_timout_mins = 15, -- time after which a player logs off that their inventory is provided to the team
|
||||
},
|
||||
-- enables players to create and prioritize tasks
|
||||
tasklist = {
|
||||
|
@ -53,10 +53,6 @@ if config.corpse_util.enabled then
|
||||
require 'features.corpse_util'
|
||||
end
|
||||
if config.dump_offline_inventories.enabled then
|
||||
if not config.corpse_util.enabled then
|
||||
config.corpse_util.enabled = true
|
||||
require 'features.corpse_util'
|
||||
end
|
||||
require 'features.dump_offline_inventories'
|
||||
end
|
||||
if config.admin_commands.enabled then
|
||||
|
@ -138,7 +138,7 @@ local function mined_entity(event)
|
||||
local player = game.get_player(player_index)
|
||||
local corpse_owner = game.get_player(corpse_owner_index)
|
||||
|
||||
if player and corpse_owner and entity.active == true then
|
||||
if player and corpse_owner and entity.active then
|
||||
local message = table.concat {player.name, ' has looted ', corpse_owner.name, "'s corpse"}
|
||||
Utils.action_warning('[Corpse]', message)
|
||||
end
|
||||
@ -160,7 +160,7 @@ local function on_gui_opened(event)
|
||||
local player = game.get_player(player_index)
|
||||
local corpse_owner = game.get_player(corpse_owner_index)
|
||||
|
||||
if player and corpse_owner and entity.active == true then
|
||||
if player and corpse_owner and entity.active then
|
||||
local message = table.concat {player.name, ' is looting ', corpse_owner.name, "'s corpse"}
|
||||
Utils.action_warning('[Corpse]', message)
|
||||
end
|
||||
|
@ -5,55 +5,61 @@
|
||||
local Event = require 'utils.event'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
local corpse_util = require 'features.corpse_util'
|
||||
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
local config = global.config.dump_offline_inventories
|
||||
local offline_timout_mins = config.offline_timout_mins
|
||||
local offline_player_queue = {}
|
||||
|
||||
--[[local config = global.config
|
||||
config.dump_offline_inventories = {
|
||||
enabled = true,
|
||||
offline_timout_mins = 1, -- time after which a player logs off that their inventory is provided to the team
|
||||
}]]--
|
||||
local offline_player_queue = {}
|
||||
Global.register({offline_player_queue = offline_player_queue}, function(tbl)
|
||||
offline_player_queue = tbl.offline_player_queue
|
||||
end)
|
||||
|
||||
local spawn_player_corpse =
|
||||
Token.register(
|
||||
function(player)
|
||||
if player and player.valid and player.connected == false and offline_player_queue[player.index] then
|
||||
-- fetch table of items in main inventory and logistics trash. Leave weapons and armor.
|
||||
local inv_main = player.get_inventory(defines.inventory.character_main)
|
||||
local inv_trash = player.get_inventory(defines.inventory.character_trash)
|
||||
function(data)
|
||||
local player = data.player
|
||||
if not player or not player.valid or player.connected or not offline_player_queue[player.index] or offline_player_queue[player.index].tick ~= data.tick then
|
||||
return
|
||||
end
|
||||
|
||||
local inv_main_contents = inv_main.get_contents()
|
||||
local inv_trash_contents = inv_trash.get_contents()
|
||||
local inv_corpse_size = (#inv_main - inv_main.count_empty_stacks()) + (#inv_trash - inv_trash.count_empty_stacks())
|
||||
-- create corpse
|
||||
local position = player.position
|
||||
local corpse = player.surface.create_entity{name="character-corpse", position=position, inventory_size = inv_corpse_size, player_index = player.index}
|
||||
corpse.active = false
|
||||
game.print("Debug: callback reached")
|
||||
local inv_main = player.get_inventory(defines.inventory.character_main)
|
||||
local inv_trash = player.get_inventory(defines.inventory.character_trash)
|
||||
|
||||
local inv_corpse = corpse.get_inventory(defines.inventory.character_corpse)
|
||||
local inv_main_contents = inv_main.get_contents()
|
||||
local inv_trash_contents = inv_trash.get_contents()
|
||||
|
||||
for item_name, count in pairs(inv_main_contents) do
|
||||
inv_corpse.insert({name = item_name, count = count})
|
||||
end
|
||||
for item_name, count in pairs(inv_trash_contents) do
|
||||
inv_corpse.insert({name = item_name, count = count})
|
||||
end
|
||||
local inv_corpse_size = (#inv_main - inv_main.count_empty_stacks()) + (#inv_trash - inv_trash.count_empty_stacks())
|
||||
|
||||
inv_main.clear()
|
||||
inv_trash.clear()
|
||||
local position = player.position
|
||||
local corpse = player.surface.create_entity{name="character-corpse", position=position, inventory_size = inv_corpse_size, player_index = player.index}
|
||||
corpse.active = false
|
||||
|
||||
local text = player.name .. "'s inventory (offline)"
|
||||
local tag = player.force.add_chart_tag(player.surface, {
|
||||
icon = {type = 'item', name = 'modular-armor'},
|
||||
position = position,
|
||||
text = text
|
||||
})
|
||||
local inv_corpse = corpse.get_inventory(defines.inventory.character_corpse)
|
||||
|
||||
corpse_util.player_corpses[player.index * 0x100000000 + game.tick] = tag
|
||||
for item_name, count in pairs(inv_main_contents) do
|
||||
inv_corpse.insert({name = item_name, count = count})
|
||||
end
|
||||
for item_name, count in pairs(inv_trash_contents) do
|
||||
inv_corpse.insert({name = item_name, count = count})
|
||||
end
|
||||
|
||||
inv_main.clear()
|
||||
inv_trash.clear()
|
||||
|
||||
offline_player_queue[data.player.index] = nil
|
||||
|
||||
local text = player.name .. "'s inventory (offline)"
|
||||
local tag = player.force.add_chart_tag(player.surface, {
|
||||
icon = {type = 'item', name = 'modular-armor'},
|
||||
position = position,
|
||||
text = text
|
||||
})
|
||||
if tag then
|
||||
corpse_util.player_corpses[player.index * 0x100000000 + game.tick] = tag
|
||||
end
|
||||
end
|
||||
)
|
||||
@ -62,6 +68,7 @@ Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
offline_player_queue[event.player_index] = nil -- ensures they're not in the offline_player_queue for wealth redistribution
|
||||
game.print("Debug: player removed from queue")
|
||||
end
|
||||
)
|
||||
|
||||
@ -70,9 +77,22 @@ Event.add(
|
||||
function(event)
|
||||
local player_index = event.player_index
|
||||
local player = game.get_player(player_index)
|
||||
if player.character then -- if player leaves before respawning they wont have a character and we don't need to add them to the list
|
||||
offline_player_queue[player_index] = true
|
||||
set_timeout_in_ticks(offline_timout_mins*60*60, spawn_player_corpse, player)
|
||||
if player and player.valid and player.character then -- if player leaves before respawning they wont have a character and we don't need to add them to the list
|
||||
offline_player_queue[player_index] = game.tick -- tick is used to check that the callback happens after X minutes as multiple callbacks may be active if the player logs off and on multiple times
|
||||
game.print("Debug: player added to queue")
|
||||
set_timeout_in_ticks(offline_timout_mins*60*60, spawn_player_corpse, {player = player, tick = game.tick})
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_banned,
|
||||
function(event)
|
||||
local player_index = event.player_index
|
||||
local player = game.get_player(player_index)
|
||||
if player and player.valid and player.character then -- if player leaves before respawning they wont have a character and we don't need to add them to the list
|
||||
offline_player_queue[player_index] = game.tick -- tick is used to check that the callback happens after X minutes as multiple callbacks may be active if the player logs off and on multiple times
|
||||
set_timeout_in_ticks(60, spawn_player_corpse, {player = player, tick = game.tick})
|
||||
end
|
||||
end
|
||||
)
|
@ -18,8 +18,6 @@ local RedmewConfig = require 'config'
|
||||
local Cutscene = require 'map_gen.maps.crash_site.cutscene'
|
||||
local cutscene_surface_settings = require 'map_gen.maps.crash_site.cutscene_surface_settings'
|
||||
|
||||
|
||||
|
||||
local degrees = math.degrees
|
||||
local cutscene_force_name = 'cutscene'
|
||||
|
||||
@ -46,9 +44,14 @@ local function control(config)
|
||||
local map_gen_settings = config.map_gen_settings or default_map_gen_settings
|
||||
RS.set_map_gen_settings(map_gen_settings)
|
||||
end
|
||||
|
||||
--[[]]
|
||||
RedmewConfig.market.enabled = false
|
||||
RedmewConfig.biter_attacks.enabled = false
|
||||
RedmewConfig.dump_offline_inventories = {
|
||||
enabled = true,
|
||||
offline_timout_mins = 1, -- time after which a player logs off that their inventory is provided to the team
|
||||
}]]
|
||||
|
||||
|
||||
-- leave seeds nil to have them filled in based on the map seed.
|
||||
local outpost_seed = nil --91000
|
||||
|
Loading…
x
Reference in New Issue
Block a user