From 08d7bef75c5e469439ad2c9030cd2c4f30d51834 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Wed, 29 Nov 2023 00:42:11 +0100 Subject: [PATCH] Fix server output not working and mtn v3 bug abuse --- maps/mountain_fortress_v3/entities.lua | 2 +- maps/mountain_fortress_v3/functions.lua | 4 +- .../icw/linked_chests.lua | 96 ++++++++++++++++++- maps/mountain_fortress_v3/icw/table.lua | 2 - maps/mountain_fortress_v3/loot.lua | 6 +- maps/mountain_fortress_v3/main.lua | 3 + maps/mountain_fortress_v3/terrain.lua | 5 + utils/server.lua | 6 +- 8 files changed, 110 insertions(+), 14 deletions(-) diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index af640517..c119c90c 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -358,7 +358,7 @@ local function hidden_treasure(player, entity) local magic = rpg.magicka - if magic >= 50 then + if magic >= 450 then local msg = rare_treasure_chest_messages[random(1, #rare_treasure_chest_messages)] Alert.alert_player(player, 5, msg) Public.add_loot_rare(entity.surface, entity.position, 'wooden-chest', magic) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 7585d775..788ac607 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1475,10 +1475,8 @@ function Public.on_research_finished(event) local research_name = research.name local force = research.force - local technology_prototypes = game.technology_prototypes - if Public.get('print_tech_to_discord') and force.name == 'player' then - Server.to_discord_bold({'functions.researched_complete', technology_prototypes[research_name].localised_name}, true) + Server.to_discord_embed_raw(' ' .. research_name:gsub('^%l', string.upper) .. ' has been researched!') end research.force.character_inventory_slots_bonus = player.mining_drill_productivity_bonus * 50 -- +5 Slots / diff --git a/maps/mountain_fortress_v3/icw/linked_chests.lua b/maps/mountain_fortress_v3/icw/linked_chests.lua index 4bd3a898..2b279619 100644 --- a/maps/mountain_fortress_v3/icw/linked_chests.lua +++ b/maps/mountain_fortress_v3/icw/linked_chests.lua @@ -53,6 +53,43 @@ function Public.set(key, value) end end +local clear_chest_token = + Token.register( + function(event) + local entity = event.entity + if not entity or not entity.valid then + return + end + local link_id = event.link_id + + if link_id then + entity.link_id = link_id + end + + entity.get_inventory(defines.inventory.chest).clear() + entity.destroy() + end +) + +local create_clear_chest_token = + Token.register( + function(event) + local surface = game.get_surface('gulag') + local entity = surface.create_entity {name = 'linked-chest', position = {x = -62, y = -6}, force = game.forces.player} + if not entity or not entity.valid then + return + end + + local link_id = event.link_id + if link_id then + entity.link_id = link_id + end + + entity.get_inventory(defines.inventory.chest).clear() + entity.destroy() + end +) + local remove_all_linked_items_token = Token.register( function(event) @@ -207,6 +244,7 @@ local function create_chest(entity, name, mode) if not previous then entity.link_id = uid_counter() + entity.get_inventory(defines.inventory.chest).set_bar(1) end if not does_exists(unit_number) then @@ -231,6 +269,7 @@ local function create_chest(entity, name, mode) if mode then container.mode = mode + entity.get_inventory(defines.inventory.chest).set_bar() end add_object(unit_number, container) @@ -600,6 +639,13 @@ local function on_built_entity(event, mode, bypass) return end + local final_battle = WPT.get('final_battle') + if final_battle then + entity.destroy() + player.print(module_name .. 'Game will reset shortly.', Color.warning) + return + end + if player.surface.index ~= active_surface_index then if entity.type ~= 'entity-ghost' then player.insert({name = 'linked-chest', count = 1}) @@ -630,6 +676,12 @@ local function on_built_entity(event, mode, bypass) end end + local final_battle = WPT.get('final_battle') + if final_battle then + entity.destroy() + return + end + local surface = entity.surface local position = entity.position if mode and entity.name ~= 'linked-chest' then @@ -660,6 +712,12 @@ local function built_entity_robot(event) return end + local final_battle = WPT.get('final_battle') + if final_battle then + entity.destroy() + return + end + local robot = event.robot if not robot or not robot.valid then return @@ -864,7 +922,7 @@ local function on_gui_checked_state_changed(event) if element.name == 'disconnect_state' then container.chest.link_id = uid_counter() - AG.append_scenario_history(player, container.chest, player.name .. ' disconnected link from chest (' .. container.unit_number .. ') to chest (' .. container.linked_to or 'unknown' .. ')') + AG.append_scenario_history(player, container.chest, player.name .. ' disconnected link from chest (' .. container.unit_number .. ') to chest (' .. container.linked_to .. ')') local destination_chest = fetch_container(container.linked_to) if destination_chest then create_message(player, 'Disconnected link', container.chest.position, destination_chest.chest.position) @@ -875,6 +933,7 @@ local function on_gui_checked_state_changed(event) container.linked_to = nil container.link_id = nil container.chest.minable = true + container.chest.get_inventory(defines.inventory.chest).set_bar(1) refresh_main_frame({unit_number = unit_number, player = player}) end @@ -1037,6 +1096,7 @@ local function on_entity_settings_pasted(event) destination_container.mode = 2 destination_container.chest.minable = false destination_container.chest.destructible = false + destination_container.chest.get_inventory(defines.inventory.chest).set_bar() end player.print(module_name .. 'Successfully pasted settings.', Color.success) @@ -1352,16 +1412,47 @@ function Public.clear_linked_frames() ) end -function Public.reset() +function Public.pre_reset() + local surface_index = WPT.get('active_surface_index') + if not surface_index then + return + end + + this.pre_reset_run = true + + local iter = 1 + for i = 1, 500 do + Task.set_timeout_in_ticks(iter, create_clear_chest_token, {link_id = i}) + iter = iter + 1 + end + + local surface = game.get_surface(surface_index) + if surface and surface.valid then + local ents = surface.find_entities_filtered {name = 'linked-chest'} + iter = 1 + if ents and next(ents) then + for _, e in pairs(ents) do + Task.set_timeout_in_ticks(iter, clear_chest_token, {entity = e}) + iter = iter + 1 + end + end + end + if this.main_containers and next(this.main_containers) then for _, container in pairs(this.main_containers) do local chest = container.chest if chest and chest.valid then chest.get_inventory(defines.inventory.chest).clear() + chest.destroy() end end end +end +function Public.reset() + if not this.pre_reset_run then + Public.pre_reset() + end this.main_containers = {} this.linked_gui = {} this.valid_chests = { @@ -1374,6 +1465,7 @@ function Public.reset() this.convert_enabled = false this.cost_to_convert = 500 this.notify_discord = false + this.pre_reset_run = false end Event.add(defines.events.on_built_entity, on_built_entity) diff --git a/maps/mountain_fortress_v3/icw/table.lua b/maps/mountain_fortress_v3/icw/table.lua index ddfc8dc5..ecf98f2e 100644 --- a/maps/mountain_fortress_v3/icw/table.lua +++ b/maps/mountain_fortress_v3/icw/table.lua @@ -1,5 +1,4 @@ local Global = require 'utils.global' -local LinkedChests = require 'maps.mountain_fortress_v3.icw.linked_chests' local this = {} Global.register( @@ -12,7 +11,6 @@ Global.register( local Public = {} function Public.reset() - LinkedChests.reset() if this.surfaces then for _, surface in pairs(this.surfaces) do if surface and surface.valid then diff --git a/maps/mountain_fortress_v3/loot.lua b/maps/mountain_fortress_v3/loot.lua index feb3d374..349e58c3 100644 --- a/maps/mountain_fortress_v3/loot.lua +++ b/maps/mountain_fortress_v3/loot.lua @@ -50,7 +50,7 @@ function Public.add_loot(surface, position, chest) local c = game.entity_prototypes[chest] local slots = c.get_inventory_size(defines.inventory.chest) - local item_stacks = LootRaffle.roll(result, slots, blacklist) + local item_stacks = LootRaffle.roll(result, slots / 2, blacklist) local container = surface.create_entity({name = chest, position = position, force = 'neutral', create_build_effect_smoke = false}) for _, item_stack in pairs(item_stacks) do container.insert(item_stack) @@ -79,7 +79,7 @@ function Public.add_loot(surface, position, chest) end function Public.add_loot_rare(surface, position, chest, magic) - local budget = magic * 48 + abs(position.y) * 1.75 + local budget = (magic * 22) + abs(position.y) * 1.75 budget = budget * random(25, 175) * 0.01 if random(1, 128) == 1 then @@ -102,7 +102,7 @@ function Public.add_loot_rare(surface, position, chest, magic) local c = game.entity_prototypes[chest] local slots = c.get_inventory_size(defines.inventory.chest) - local item_stacks = LootRaffle.roll(result, slots, blacklist) + local item_stacks = LootRaffle.roll(result, slots / 2, blacklist) local container = surface.create_entity({name = chest, position = position, force = 'neutral', create_build_effect_smoke = false}) for _, item_stack in pairs(item_stacks) do container.insert(item_stack) diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 26f0126d..83286a03 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -25,6 +25,7 @@ local Server = require 'utils.server' local Explosives = require 'modules.explosives' local ICW = require 'maps.mountain_fortress_v3.icw.main' local WD = require 'modules.wave_defense.table' +local LinkedChests = require 'maps.mountain_fortress_v3.icw.linked_chests' local Map = require 'modules.map_info' local RPG = require 'modules.rpg.main' local Score = require 'utils.gui.score' @@ -120,6 +121,8 @@ function Public.reset_map() Misc.set('creative_are_you_sure', false) Misc.set('creative_enabled', false) + LinkedChests.reset() + this.active_surface_index = Public.create_surface() this.old_surface_index = this.active_surface_index diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index 963cb309..b2ce6e9f 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -247,6 +247,11 @@ local function is_position_near(area, table_to_check) end local function place_wagon(data, adjusted_zones) + local final_battle = Public.get('final_battle') + if final_battle then + return + end + local x_min = (-zone_settings.zone_width / 2) + 10 local x_max = (zone_settings.zone_width / 2) - 10 diff --git a/utils/server.lua b/utils/server.lua index 37cebf3e..dfb424d4 100644 --- a/utils/server.lua +++ b/utils/server.lua @@ -99,12 +99,12 @@ local player_leave_tag = '[PLAYER-LEAVE]' Public.raw_print = raw_print -local function output_data(...) +local function output_data(primary, secondary) if start_data and start_data.output then local write = game.write_file - write(start_data.output, ... .. newline, true, 0) + write(start_data.output, primary .. (secondary or '') .. newline, true, 0) else - raw_print(...) + raw_print(primary .. (secondary or '')) end end