From c74f3db7c4441c3e802da2f56b2f76ff553a6fbf Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sat, 26 Oct 2024 13:05:31 +0200 Subject: [PATCH] Mtn: Fix many bugs --- maps/mountain_fortress_v3/breached_wall.lua | 4 +-- maps/mountain_fortress_v3/entities.lua | 13 +++++-- maps/mountain_fortress_v3/functions.lua | 5 +-- maps/mountain_fortress_v3/ic/functions.lua | 36 ++++++++++++++++---- maps/mountain_fortress_v3/icw/functions.lua | 5 +++ maps/mountain_fortress_v3/icw/main.lua | 16 +++++++++ maps/mountain_fortress_v3/main.lua | 18 ++++++---- maps/mountain_fortress_v3/stateful/table.lua | 1 + modules/rpg/commands.lua | 21 ++++++------ modules/rpg/gui.lua | 8 ++--- modules/rpg/main.lua | 3 -- modules/rpg/spells.lua | 4 +-- utils/commands.lua | 8 +++++ utils/commands/misc.lua | 2 +- 14 files changed, 101 insertions(+), 43 deletions(-) diff --git a/maps/mountain_fortress_v3/breached_wall.lua b/maps/mountain_fortress_v3/breached_wall.lua index 1a5d4ae53..df60abb60 100644 --- a/maps/mountain_fortress_v3/breached_wall.lua +++ b/maps/mountain_fortress_v3/breached_wall.lua @@ -324,8 +324,6 @@ local function distance(player) local breached_wall = Public.get('breached_wall') local bonus_xp_on_join = Public.get('bonus_xp_on_join') local enable_arties = Public.get('enable_arties') - local final_battle = Public.get('final_battle') - local p = player.physical_position @@ -421,7 +419,7 @@ local function distance(player) end end - if not Collapse.has_collapse_started() or not final_battle then + if not Collapse.has_collapse_started() then clear_breach_text_and_render() Public.set('collapse_started', true) Collapse.start_now(true) diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index c7031c05e..76c54076b 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -109,6 +109,15 @@ local reset_game = end ) +local change_force_for_drills_token = + Task.register( + function (event) + local entity = event.entity + if not entity or not entity.valid then return end + entity.force = 'bonus_drill' + end + ) + local function get_random_weighted(player, weighted_table, item_index, weight_index) local total_weight = 0 item_index = item_index or 1 @@ -1507,7 +1516,7 @@ local function on_built_entity(event) } if valid_drills[entity.name] then - entity.force = 'bonus_drill' + Task.set_timeout_in_ticks(30, change_force_for_drills_token, { entity = entity }) return end @@ -1598,7 +1607,7 @@ local function on_robot_built_entity(event) } if valid_drills[entity.name] then - entity.force = 'bonus_drill' + Task.set_timeout_in_ticks(30, change_force_for_drills_token, { entity = entity }) return end diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 0acf1c399..5baba05fb 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1567,10 +1567,7 @@ function Public.is_creativity_mode_on() end function Public.disable_creative() - local creative_enabled = Misc.get('creative_enabled') - if creative_enabled then - Misc.set('creative_enabled', false) - end + Misc.set('creative_enabled', false) end function Public.on_player_respawned(event) diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index c477a6872..35dfdc5ab 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -39,6 +39,18 @@ local function validate_entity(entity) return true end +local get_filters = function (points) + local filters = {} + for _, section in pairs(points.sections) do + for _, filter in pairs(section.filters) do + if filter and filter.value and filter.value.name then + filters[#filters + 1] = filter + end + end + end + return filters +end + ---Returns the car from the unit_number. ---@param unit_number any ---@return table|boolean @@ -560,10 +572,11 @@ local function input_filtered(car_inv, chest, chest_inv, free_slots) local request_stacks = {} local prototypes = prototypes.item - for slot_index = 1, 30, 1 do - local stack = chest.get_request_slot(slot_index) - if stack then - request_stacks[stack.name] = 10 * prototypes[stack.name].stack_size + local logistics = chest.get_logistic_point(defines.logistic_member_index.logistic_container) + local filters = get_filters(logistics) + for _, filter in pairs(filters) do + if filter.value.name then + request_stacks[filter.value.name] = 10 * prototypes[filter.value.name].stack_size end end for i = 1, #car_inv - 1, 1 do @@ -606,7 +619,16 @@ local function input_cargo(car, chest) end end - if chest.get_request_slot(1) then + local has_request_slot = false + local logistics = chest.get_logistic_point(defines.logistic_member_index.logistic_container) + local filters = get_filters(logistics) + for _, filter in pairs(filters) do + if filter.value.name then + has_request_slot = true + end + end + + if has_request_slot then input_filtered(car_inventory, chest, chest_inventory, free_slots) goto continue end @@ -811,7 +833,7 @@ function Public.save_car(event) restore_surface(p, e) elseif p.can_insert({ name = car.name, count = 1 }) then p.insert({ name = car.name, count = 1, health = health }) - p.print(module_tag .. 'Your car was stolen from you - the gods foresaw this and granted you a new one.', {color = Color.info}) + p.print(module_tag .. 'Your car was stolen from you - the gods foresaw this and granted you a new one.', { color = Color.info }) end end end @@ -1081,7 +1103,7 @@ function Public.validate_owner(player, entity) player.driving = false if not player.admin then if list.notify_on_driver_change == 'left' then - p.print(player.name .. ' tried to drive your car.', {color = Color.warning}) + p.print(player.name .. ' tried to drive your car.', { color = Color.warning }) end return end diff --git a/maps/mountain_fortress_v3/icw/functions.lua b/maps/mountain_fortress_v3/icw/functions.lua index 3552834ff..3458774f3 100644 --- a/maps/mountain_fortress_v3/icw/functions.lua +++ b/maps/mountain_fortress_v3/icw/functions.lua @@ -761,6 +761,7 @@ function Public.use_cargo_wagon_door_with_entity(icw, player, door) return end + if not door then return end @@ -1062,6 +1063,10 @@ function Public.toggle_minimap(icw, event) return end local player = game.players[event.player_index] + if player.controller_type == defines.controllers.remote then + return + end + local is_spamming = SpamProtection.is_spamming(player, 5, 'ICW Toggle Minimap') if is_spamming then return diff --git a/maps/mountain_fortress_v3/icw/main.lua b/maps/mountain_fortress_v3/icw/main.lua index 4b72da35d..801a5fec2 100644 --- a/maps/mountain_fortress_v3/icw/main.lua +++ b/maps/mountain_fortress_v3/icw/main.lua @@ -24,11 +24,18 @@ end local function on_player_driving_changed_state(event) local icw = ICW.get() local player = game.players[event.player_index] + if player.controller_type == defines.controllers.remote then + return + end + Functions.use_cargo_wagon_door_with_entity(icw, player, event.entity) end local function on_player_changed_surface(event) local player = game.players[event.player_index] + if player.controller_type == defines.controllers.remote then + return + end Functions.kill_minimap(player) end @@ -37,6 +44,7 @@ local function on_gui_closed(event) if not entity then return end + if not entity.valid then return end @@ -52,6 +60,10 @@ local function on_gui_closed(event) return end + if player.controller_type == defines.controllers.remote then + return + end + Functions.kill_minimap(player) end @@ -77,6 +89,10 @@ local function on_gui_opened(event) return end + if player.controller_type == defines.controllers.remote then + return + end + Functions.draw_minimap( icw, player, diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 9c3fc8673..135acfd99 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -42,6 +42,7 @@ local JailData = require 'utils.datastore.jail_data' local RPG_Progression = require 'utils.datastore.rpg_data' local OfflinePlayers = require 'modules.clear_vacant_players' local Beam = require 'modules.render_beam' +local Commands = require 'utils.commands' -- Use these settings for live local send_ping_to_channel = Discord.channel_names.mtn_channel @@ -142,6 +143,15 @@ partial_reset = function () Public.locomotive_spawn(surface, { x = -18, y = 25 }, this.adjusted_zones.reversed) end + init_bonus_drill_force() + + Public.init_enemy_weapon_damage() + + game.forces.player.manual_mining_speed_modifier = 0 + game.forces.player.set_ammo_damage_modifier('artillery-shell', -0.95) + game.forces.player.worker_robots_battery_modifier = 4 + game.forces.player.worker_robots_storage_bonus = 15 + Public.render_train_hp() Public.render_direction(surface, this.adjusted_zones.reversed) end @@ -185,7 +195,6 @@ function Public.reset_map() Group.alphanumeric_only(false) Public.disable_tech() - init_bonus_drill_force() local surface = game.surfaces[this.active_surface_index] @@ -204,11 +213,6 @@ function Public.reset_map() Beam.reset_valid_targets() - game.forces.player.manual_mining_speed_modifier = 0 - game.forces.player.set_ammo_damage_modifier('artillery-shell', -0.95) - game.forces.player.worker_robots_battery_modifier = 4 - game.forces.player.worker_robots_storage_bonus = 15 - BiterHealthBooster.set_active_surface(tostring(surface.name)) BiterHealthBooster.acid_nova(true) BiterHealthBooster.check_on_entity_died(true) @@ -216,7 +220,6 @@ function Public.reset_map() BiterHealthBooster.enable_boss_loot(false) BiterHealthBooster.enable_randomize_stun_and_slowdown_sticker(true) - Public.init_enemy_weapon_damage() -- AntiGrief.whitelist_types('tree', true) AntiGrief.enable_capsule_warning(false) @@ -296,6 +299,7 @@ function Public.reset_map() Public.set_difficulty() Public.disable_creative() Public.boost_difficulty() + Commands.restore_states() if this.adjusted_zones.reversed then if not surface.is_chunk_generated({ x = -20, y = -22 }) then diff --git a/maps/mountain_fortress_v3/stateful/table.lua b/maps/mountain_fortress_v3/stateful/table.lua index ab53cd047..bd84ed2c4 100644 --- a/maps/mountain_fortress_v3/stateful/table.lua +++ b/maps/mountain_fortress_v3/stateful/table.lua @@ -519,6 +519,7 @@ local search_corpse_token = Task.register( function (event) local player_index = event.player_index + if not player_index then return end local player = game.get_player(player_index) if not player or not player.valid then diff --git a/modules/rpg/commands.lua b/modules/rpg/commands.lua index 61164e58b..d16553254 100644 --- a/modules/rpg/commands.lua +++ b/modules/rpg/commands.lua @@ -109,18 +109,19 @@ Commands.new('stats', 'Check what stats a user has!') end ) +Commands.new('rpg_give_xp', 'Give players XP!') + :require_admin() + :require_validation("Running this again will grant EVERY player XP. Are you sure you want to continue?") + :add_parameter('amount', false, 'number') + :callback( + function (_, amount) + Public.give_xp(amount) + game.print('Distributed ' .. amount .. ' of xp.') + end + ) -if _DEBUG then - Commands.new('give_xp', 'Give a player XP!') - :require_admin() - :add_parameter('amount', false, 'number') - :callback( - function (_, amount) - Public.give_xp(amount) - game.print('Distributed ' .. amount .. ' of xp.') - end - ) +if _DEBUG then Commands.new('rpg_debug_module', 'Toggle debug mode for RPG module!') :require_admin() :callback( diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index dfc175776..bac318dbb 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -157,18 +157,18 @@ end local function add_gui_increase_stat(element, name, player) local rpg_t = Public.get_value_from_player(player.index) - local sprite = 'virtual-signal/signal-red' local symbol = '✚' + local e = element.add({ type = 'sprite-button', name = name, caption = symbol }) if rpg_t.points_left <= 0 then - sprite = 'virtual-signal/signal-black' + e.style.font_color = { 0, 0, 0 } + else + e.style.font_color = { 195, 0, 0 } end - local e = element.add({ type = 'sprite-button', name = name, caption = symbol, sprite = sprite }) e.style.maximal_height = 38 e.style.minimal_height = 38 e.style.maximal_width = 38 e.style.minimal_width = 38 e.style.font = 'default-large-semibold' - e.style.font_color = { 0, 0, 0 } e.style.horizontal_align = 'center' e.style.vertical_align = 'center' e.style.padding = 0 diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 559581ccb..9dc9c8396 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -64,9 +64,6 @@ local function on_gui_click(event) if element.caption ~= '✚' then return end - if element.sprite ~= 'virtual-signal/signal-red' then - return - end local rpg_t = Public.get_value_from_player(player.index) diff --git a/modules/rpg/spells.lua b/modules/rpg/spells.lua index 3dfb66de2..291a342a2 100644 --- a/modules/rpg/spells.lua +++ b/modules/rpg/spells.lua @@ -1109,7 +1109,7 @@ spells[#spells + 1] = { local surface = data.surface - local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) + local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0) if pos then player.teleport(pos, surface) else @@ -1145,7 +1145,7 @@ spells[#spells + 1] = { Public.register_cooldown_for_spell(player) - local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) + local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0) if pos then player.teleport(pos, surface) else diff --git a/utils/commands.lua b/utils/commands.lua index 3a1a7a59b..25b4c0293 100644 --- a/utils/commands.lua +++ b/utils/commands.lua @@ -523,6 +523,14 @@ function Public:set_default(defaults) return self end +--- Restores the command_activated state for each command +function Public.restore_states() + for _, command in pairs(this.commands) do + command.validated_command = false + command.command_activated = false + end +end + --- Registers the command to the game. Will return the player/server and the args as separate arguments. ---@param func function function Public:callback(func) diff --git a/utils/commands/misc.lua b/utils/commands/misc.lua index 90a68c32d..b5d36b50c 100644 --- a/utils/commands/misc.lua +++ b/utils/commands/misc.lua @@ -318,7 +318,7 @@ local function clear_corpses(cmd) local radius = { { x = (pos.x + -param), y = (pos.y + -param) }, { x = (pos.x + param), y = (pos.y + param) } } - for _, entity in pairs(player.surface.find_entities_filtered { area = radius, type = 'corpse' }) do + for _, entity in pairs(player.surface.find_entities_filtered { area = radius, type = { 'corpse' } }) do if entity.corpse_expires then entity.destroy() i = i + 1