diff --git a/maps/mountain_fortress_v3/icw/linked_chests.lua b/maps/mountain_fortress_v3/icw/linked_chests.lua index bebca019..4ad43aef 100644 --- a/maps/mountain_fortress_v3/icw/linked_chests.lua +++ b/maps/mountain_fortress_v3/icw/linked_chests.lua @@ -9,6 +9,7 @@ local Math2D = require 'math2d' local WPT = require 'maps.mountain_fortress_v3.table' local Session = require 'utils.datastore.session_data' local AG = require 'utils.antigrief' +local Core = require 'utils.core' local Discord = require 'utils.discord_handler' local this = {} @@ -434,7 +435,7 @@ local function refresh_main_frame(data) chestitem.enabled = false chestitem.tooltip = '[Antigrief] You have not grown accustomed to this technology yet.' end - Gui.set_data(chestitem, {name = nil, unit_number = unit_number, share = source_chest.share.name}) + Gui.set_data_parent(volatile_tbl, chestitem, {name = nil, unit_number = unit_number, share = source_chest.share.name}) end end end @@ -724,7 +725,8 @@ local function gui_closed(event) if not data then return end - data.frame.destroy() + Gui.destroy(data.volatile_tbl) + Gui.destroy(data.frame) this.linked_gui[player.name] = nil end end @@ -1084,10 +1086,24 @@ Event.add( Gui.on_click( item_name_frame_name, function(event) - local data = Gui.get_data(event.element) + local player = game.get_player(event.player_index) + local player_data = this.linked_gui[player.name] + local element = event.element + if not player_data then + Gui.remove_data_recursively(element) + return + end + local parent = player_data.volatile_tbl + if not parent or not parent.valid then + Gui.remove_data_recursively(element) + return + end + + local data = Gui.get_data_parent(parent, element) if not data then return end + local button = event.button local _, _unit_number, share_container = fetch_share(data.share) @@ -1095,15 +1111,12 @@ Gui.on_click( local container = fetch_container(data.unit_number) if button == defines.mouse_button_type.right then - local player = game.get_player(event.player_index) - if player and player.valid then - Where.create_mini_camera_gui(player, {valid = true, name = share_container.share.name, surface = share_container.chest.surface, position = share_container.chest.position}, 0.7, true) - end + Where.create_mini_camera_gui(player, {valid = true, name = share_container.share.name, surface = share_container.chest.surface, position = share_container.chest.position}, 0.7, true) return end - AG.append_scenario_history(event.player, container.chest, event.player.name .. ' linked chest (' .. data.unit_number .. ') with: ' .. share_container.share.name) - create_message(event.player, 'Linked chest', container.chest.position, share_container.chest.position) + AG.append_scenario_history(player, container.chest, player.name .. ' linked chest (' .. data.unit_number .. ') with: ' .. share_container.share.name) + create_message(player, 'Linked chest', container.chest.position, share_container.chest.position) container.linked_to = _unit_number container.chest.link_id = share_container.link_id container.link_id = share_container.link_id @@ -1112,6 +1125,9 @@ Gui.on_click( this.linked_gui[event.player.name].updated = false refresh_main_frame({unit_number = container.unit_number, player = event.player}) + if element and element.valid then + Gui.remove_data_recursively(element) + end end end ) @@ -1138,6 +1154,18 @@ local function on_player_changed_position(event) end end +function Public.clear_linked_frames() + Core.iter_connected_players( + function(player) + local data = this.linked_gui[player.name] + if data and data.frame and data.frame.valid then + data.frame.destroy() + end + this.linked_gui[player.name] = nil + end + ) +end + function Public.reset() this.main_containers = {} this.linked_gui = {} diff --git a/maps/mountain_fortress_v3/stateful/blueprints.lua b/maps/mountain_fortress_v3/stateful/blueprints.lua index edb73763..a88aed78 100644 --- a/maps/mountain_fortress_v3/stateful/blueprints.lua +++ b/maps/mountain_fortress_v3/stateful/blueprints.lua @@ -28,21 +28,22 @@ function Public.blueprint() surface.request_to_generate_chunks({0, 0}, 1) surface.force_generate_chunk_requests() - local item = surface.create_entity {name = 'item-on-ground', position = position, stack = {name = 'blueprint', count = 1}} - if not item then - return - end - - local ents = surface.find_entities_filtered({type = {'unit-spawner', 'tree'}, area = {{position.x - 70, position.y - 70}, {position.x + 70, position.y + 70}}}) + local ents = surface.find_entities_filtered({area = {{position.x - 70, position.y - 70}, {position.x + 70, position.y + 70}}}) if #ents == 0 then return end + for _, e in pairs(ents) do if e and e.valid then e.destroy() end end + local item = surface.create_entity {name = 'item-on-ground', position = position, stack = {name = 'blueprint', count = 1}} + if not item then + return + end + local success = item.stack.import_stack(bp) if success <= 0 then local ghosts = item.stack.build_blueprint {surface = surface, force = 'player', position = position, force_build = true} diff --git a/maps/mountain_fortress_v3/stateful/gui.lua b/maps/mountain_fortress_v3/stateful/gui.lua index 211b4f6a..02fead89 100644 --- a/maps/mountain_fortress_v3/stateful/gui.lua +++ b/maps/mountain_fortress_v3/stateful/gui.lua @@ -946,6 +946,7 @@ local function update_raw() collection.gather_time = 0 if not collection.gather_time_done then collection.gather_time_done = true + LinkedChests.clear_linked_frames() stateful.final_battle = true Public.set('final_battle', true) end diff --git a/maps/mountain_fortress_v3/stateful/main.lua b/maps/mountain_fortress_v3/stateful/main.lua index 1c79f07c..9eab6373 100644 --- a/maps/mountain_fortress_v3/stateful/main.lua +++ b/maps/mountain_fortress_v3/stateful/main.lua @@ -53,7 +53,7 @@ Event.on_nth_tick( shuffle(area) WD.set_spawn_position(area[1]) - Event.raise(WD.events.on_spawn_unit_group, {fs = true, bypass = true, random_bosses = true}) + Event.raise(WD.events.on_spawn_unit_group, {fs = true, bypass = true, random_bosses = true, scale = Public.stateful.scale(20, 100)}) return end @@ -65,4 +65,6 @@ Event.on_nth_tick( end ) +Event.add(defines.events.on_pre_player_died, Public.on_pre_player_died) + return Public diff --git a/maps/mountain_fortress_v3/stateful/table.lua b/maps/mountain_fortress_v3/stateful/table.lua index 86827143..274d0e03 100644 --- a/maps/mountain_fortress_v3/stateful/table.lua +++ b/maps/mountain_fortress_v3/stateful/table.lua @@ -158,6 +158,67 @@ local move_all_players_token = end ) +local search_corpse_token = + Token.register( + function(event) + local player_index = event.player_index + local player = game.get_player(player_index) + + if not player or not player.valid then + return + end + + local pos = player.position + local entities = + player.surface.find_entities_filtered { + area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.5, pos.y + 0.5}}, + name = 'character-corpse' + } + + local entity + for _, e in ipairs(entities) do + if e.character_corpse_tick_of_death then + entity = e + break + end + end + + if not entity or not entity.valid then + return + end + + entity.destroy() + + local text = player.name .. "'s corpse was consumed by the biters." + + game.print(text) + end +) + +local function on_pre_player_died(event) + local player_index = event.player_index + local player = game.get_player(player_index) + + if not player or not player.valid then + return + end + + local surface = player.surface + + local map_name = 'boss_room' + + local corpse_removal_disabled = Public.get('corpse_removal_disabled') + if corpse_removal_disabled then + return + end + + if string.sub(surface.name, 0, #map_name) ~= map_name then + return + end + + Task.set_timeout_in_ticks(5, search_corpse_token, {player_index = player.index}) +end + local locomotive_market_pickaxe_token = Token.register( function(count) @@ -667,14 +728,18 @@ function Public.migrate_and_create(locomotive) return end local position = locomotive.position + local inc = 6 + local new_position = {x = position.x, y = position.y + inc} - for _, entity in pairs(carriages) do - if entity and entity.valid and entity.unit_number ~= locomotive.unit_number then - local new_position = {x = position.x, y = position.y + 5} - local new_wagon = surface.create_entity({name = entity.name, position = new_position, force = 'player', defines.direction.north}) - if new_wagon and new_wagon.valid then - position = new_position - ICW.migrate_wagon(entity, new_wagon) + for index, entity in pairs(carriages) do + if index ~= 1 then + if entity and entity.valid and entity.unit_number ~= locomotive.unit_number then + local new_wagon = surface.create_entity({name = entity.name, position = new_position, force = 'player', defines.direction.north}) + if new_wagon and new_wagon.valid then + inc = inc + 7 + new_position = {x = position.x, y = position.y + inc} + ICW.migrate_wagon(entity, new_wagon) + end end end end @@ -874,5 +939,6 @@ Public.apply_startup_settings = apply_startup_settings Public.scale = scale Public.stateful_spawn_points = stateful_spawn_points Public.sizeof_stateful_spawn_points = #stateful_spawn_points +Public.on_pre_player_died = on_pre_player_died return Public diff --git a/maps/mountain_fortress_v3/stateful/terrain.lua b/maps/mountain_fortress_v3/stateful/terrain.lua index 0058b909..56bb56e7 100644 --- a/maps/mountain_fortress_v3/stateful/terrain.lua +++ b/maps/mountain_fortress_v3/stateful/terrain.lua @@ -108,7 +108,7 @@ local function void_tiles(p) end local function enemy_spawn_positions(p) - if p.x < 200 and p.x >= -212 then + if p.x < 230 and p.x >= -242 then return false end return true @@ -233,9 +233,11 @@ function Public.heavy_functions(data) return end - border_chunk(p, data) - oozy_tiles(p, data.seed, data.tiles) - draw_rails(data) + if p.y < 250 then + border_chunk(p, data) + oozy_tiles(p, data.seed, data.tiles) + draw_rails(data) + end end return Public diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index ef5c478f..b43b69ef 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -220,6 +220,7 @@ function Public.reset_main_table() redraw_mystical_chest_cost = 3000 } this.collapse_grace = true + this.corpse_removal_disabled = false this.locomotive_biter = nil this.disconnect_wagon = false this.collapse_amount = false diff --git a/modules/biter_health_booster_v2.lua b/modules/biter_health_booster_v2.lua index 8d57c7c7..83628905 100644 --- a/modules/biter_health_booster_v2.lua +++ b/modules/biter_health_booster_v2.lua @@ -8,8 +8,6 @@ local Event = require 'utils.event' local LootDrop = require 'modules.mobs_drop_loot' local WD = require 'modules.wave_defense.table' local Global = require 'utils.global' -local Task = require 'utils.task' -local Token = require 'utils.token' local floor = math.floor local insert = table.insert @@ -90,20 +88,6 @@ local entity_types = { ['unit-spawner'] = true } -local function clear_unit_from_tbl(unit_number) - if this.biter_health_boost_units[unit_number] then - this.biter_health_boost_units[unit_number] = nil - end -end - -local removeUnit = - Token.register( - function(data) - local unit_number = data.unit_number - clear_unit_from_tbl(unit_number) - end -) - local function loaded_biters(event) local cause = event.cause local entity = event.entity @@ -379,7 +363,7 @@ local function on_entity_died(event) local wave_count = WD.get_wave() if health_pool then - Task.set_timeout_in_ticks(30, removeUnit, {unit_number = unit_number}) + this.biter_health_boost_units[unit_number] = nil if health_pool[3] and health_pool[3].healthbar_id then if this.enable_boss_loot then if random(1, 128) == 1 then diff --git a/modules/rpg/settings.lua b/modules/rpg/settings.lua index fde9c911..e53affce 100644 --- a/modules/rpg/settings.lua +++ b/modules/rpg/settings.lua @@ -709,15 +709,11 @@ function Public.extra_settings(player) Gui.set_data(save_button, data) - if not main_frame or not main_frame.valid then - return - end - - player.opened = main_frame if not main_frame or not main_frame.valid then return end main_frame.auto_center = true + player.opened = main_frame end function Public.settings_tooltip(player) diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 75d419fe..2a1ded7a 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -1141,18 +1141,20 @@ local function spawn_unit_group(fs, only_bosses) end else event_data.boss_wave = true - local count = 30 + local count = fs.scale or 30 event_data.spawn_count = count for _ = 1, count, 1 do - local random_boss = (random(1, 100) == 1) + local random_boss = (random(1, 60) == 1) local biter = spawn_biter(surface, spawn_position, fs, random_boss, unit_settings) if not biter then Public.debug_print('spawn_unit_group - No biter was found?') break end unit_group.add_member(biter) + if random_boss then + raise(Public.events.on_entity_created, {entity = biter, boss_unit = true, target = target}) + end end - Public.set('boss_wave', false) end generated_units.unit_groups[unit_group.group_number] = unit_group diff --git a/utils/gui.lua b/utils/gui.lua index 57b8b59d..495afdc2 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -101,6 +101,35 @@ function Public.set_data(element, value) end local set_data = Public.set_data +-- Associates data with the LuaGuiElement. If data is nil then removes the data +function Public.set_data_parent(parent, element, value) + local player_index = parent.player_index + local values = data[player_index] + + if value == nil then + if not values then + return + end + + values[parent.index] = nil + + if next(values) == nil then + data[player_index] = nil + end + else + if not values then + values = {} + data[player_index] = values + end + + if not values[parent.index] then + values[parent.index] = {} + end + + values[parent.index][element.index] = value + end +end + -- Gets the Associated data with this LuaGuiElement if any. function Public.get_data(element) if not element then @@ -117,6 +146,30 @@ function Public.get_data(element) return values[element.index] end +-- Gets the Associated data with this LuaGuiElement if any. +function Public.get_data_parent(parent, element) + if not parent then + return + end + if not element then + return + end + + local player_index = parent.player_index + + local values = data[player_index] + if not values then + return nil + end + + values = values[parent.index] + if not values then + return nil + end + + return values[element.index] +end + -- Adds a gui that is alike the factorio native gui. function Public.add_main_frame_with_toolbar(player, align, set_frame_name, set_settings_button_name, close_main_frame_name, name, info, inside_table_count) if not align then