From 80a99e4f170f01bab2163d1f13332da5b04eb18f Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 19 Nov 2024 13:54:09 +0100 Subject: [PATCH] Push fix for jail handler and bug fixes for Mtn --- maps/mountain_fortress_v3/functions.lua | 35 ++++++++++++++++++++++++ maps/mountain_fortress_v3/main.lua | 1 + maps/mountain_fortress_v3/soft_reset.lua | 5 ++++ maps/mountain_fortress_v3/table.lua | 3 ++ modules/rpg/functions.lua | 3 +- utils/datastore/jail_data.lua | 7 ++--- 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index fde11333..30d33814 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1370,6 +1370,40 @@ local function on_player_cursor_stack_changed(event) end end +local function on_chart_tag_added(event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + + local tag = event.tag + if not tag then return end + local force = event.force + if not force then return end + + local charts = Public.get('charts') + if not charts then return end + if not charts.tags then return end + + + charts.tags[#charts.tags + 1] = tag +end + +function Public.clear_all_chart_tags() + local charts = Public.get('charts') + if not charts then return end + if not charts.tags then return end + + for i = 1, #charts.tags do + local tag = charts.tags[i] + if tag and tag.valid then + tag.destroy() + end + end + + charts.tags = {} +end + function Public.set_xp_yield() RPG.set_rpg_xp_yield({ ['biter-spawner'] = 64, @@ -2934,6 +2968,7 @@ Event.add(de.on_player_respawned, on_player_respawned) Event.add(de.on_player_driving_changed_state, on_player_driving_changed_state) Event.add(de.on_pre_player_toggled_map_editor, on_pre_player_toggled_map_editor) Event.add(de.on_player_cursor_stack_changed, on_player_cursor_stack_changed) +Event.add(de.on_chart_tag_added, on_chart_tag_added) Event.on_nth_tick(10, tick) Event.add(WD.events.on_wave_created, on_wave_created) Event.add(WD.events.on_primary_target_missing, on_primary_target_missing) diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 8b1163e4..6d3c4dea 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -445,6 +445,7 @@ function Public.pre_init_task(current_task) Public.set_xp_yield() end RPG.set_extra('modded_hotkeys', true) + Public.clear_all_chart_tags() current_task.message = 'Pre init done!' current_task.state = 'init_stateful' diff --git a/maps/mountain_fortress_v3/soft_reset.lua b/maps/mountain_fortress_v3/soft_reset.lua index 12c1e624..2cd881ec 100644 --- a/maps/mountain_fortress_v3/soft_reset.lua +++ b/maps/mountain_fortress_v3/soft_reset.lua @@ -5,8 +5,13 @@ local Event = require 'utils.event' local mapkeeper = '[color=blue]Mapkeeper:[/color]' local function reset_forces() + local surface = game.get_surface('nauvis') + if not surface or not surface.valid then + return + end for _, f in pairs(game.forces) do f.reset() + f.clear_chart(surface) f.reset_evolution() end for _, tech in pairs(game.forces.player.technologies) do diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index 8ce85064..53fb05c5 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -162,6 +162,9 @@ function Public.reset_main_table() this.breach_wall_warning = false this.icw_locomotive = nil this.game_lost = false + this.charts = { + tags = {} + } this.death_mode = false this.collapse_started = false this.locomotive_position = nil diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index c27b9c0f..0c95b362 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -566,7 +566,8 @@ function Public.update_health(player) if rpg_extra.enable_health_and_mana_bars then if rpg_t.show_bars then - local max_life = math.floor(player.character.max_health + player.character_health_bonus + player.force.character_health_bonus) + local proto_char = prototypes.entity.character.get_max_health('normal') + local max_life = math.floor(proto_char + player.character_health_bonus + player.force.character_health_bonus) if not rpg_t.health_bar or not rpg_t.health_bar.valid then rpg_t.health_bar = create_healthbar(player, 0.5) end diff --git a/utils/datastore/jail_data.lua b/utils/datastore/jail_data.lua index 375dcffd..74aa78ba 100644 --- a/utils/datastore/jail_data.lua +++ b/utils/datastore/jail_data.lua @@ -609,7 +609,6 @@ local function vote_to_free(player, offender) else Utils.print_to(player, 'You have already voted to free ' .. offender .. '.') end - return end local function jail(player, offender, msg, raised, mute) @@ -742,11 +741,11 @@ local function free(player, offender) return false end - if not game.get_player(offender) then + local to_jail_player = game.get_player(offender) + if not to_jail_player or not to_jail_player.valid then return end - local to_jail_player = game.get_player(offender) teleport_player_to_gulag(to_jail_player, 'free') local message = offender .. ' was set free from jail by ' .. player .. '.' @@ -987,7 +986,7 @@ end -- @param message string -- @param mute boolean function Public.try_ul_data(key, value, player, message, mute) - if type(key) == 'table' then + if type(key) == 'userdata' then key = key.name end