diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index c75cdc1a..49a698fe 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -11,12 +11,17 @@ draw_map_scores would be a function with the player and the frame as arguments ]] local Event = require 'utils.event' local Server = require 'utils.server' -local CommandFrame = require 'commands.misc' local SpamProtection = require 'utils.spam_protection' comfy_panel_tabs = {} local Public = {} +local screen_elements = {} + +function Public.screen_to_bypass(elem) + screen_elements[elem] = true + return screen_elements +end function Public.get_tabs(data) return comfy_panel_tabs @@ -36,7 +41,7 @@ end function Public.comfy_panel_clear_screen_gui(player) for _, child in pairs(player.gui.screen.children) do - if child.name ~= CommandFrame.bottom_guis_frame then + if not screen_elements[child.name] then child.visible = false end end @@ -44,7 +49,7 @@ end function Public.comfy_panel_restore_screen_gui(player) for _, child in pairs(player.gui.screen.children) do - if child.name ~= 'ups_label' then + if not screen_elements[child.name] then child.visible = true end end diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index 6e42c32d..ac459809 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -411,6 +411,9 @@ end local function remove_create_poll_frame(create_poll_frame, player_index) local data = Gui.get_data(create_poll_frame) + if not data then + return + end data.edit_mode = nil player_create_poll_data[player_index] = data @@ -906,6 +909,10 @@ Gui.on_click( local button_data = Gui.get_data(event.element) local data = button_data.data + if not data then + return + end + table.remove(data.answers, button_data.count) redraw_create_poll_content(data) end @@ -915,7 +922,13 @@ Gui.on_click( create_poll_label_name, function(event) local textfield = Gui.get_data(event.element) - textfield.focus() + if not textfield then + return + end + + if textfield and textfield.valid then + textfield.focus() + end end ) @@ -925,7 +938,13 @@ Gui.on_text_changed( local textfield = event.element local data = Gui.get_data(textfield) - data.question = textfield.text + if not data then + return + end + + if textfield and textfield.valid then + data.question = textfield.text + end end ) @@ -935,7 +954,13 @@ Gui.on_text_changed( local textfield = event.element local data = Gui.get_data(textfield) - data.answers[data.count].text = textfield.text + if not data then + return + end + + if textfield and textfield.valid then + data.answers[data.count].text = textfield.text + end end ) @@ -957,7 +982,9 @@ Gui.on_click( create_poll_close_name, function(event) local frame = Gui.get_data(event.element) - remove_create_poll_frame(frame, event.player_index) + if frame and frame.valid then + remove_create_poll_frame(frame, event.player_index) + end end ) diff --git a/commands/misc.lua b/commands/misc.lua index 78861754..fd110eff 100644 --- a/commands/misc.lua +++ b/commands/misc.lua @@ -4,6 +4,7 @@ local Server = require 'utils.server' local Color = require 'utils.color_presets' local Event = require 'utils.event' local Global = require 'utils.global' +local ComfyGui = require 'comfy_panel.main' local Gui = require 'utils.gui' local this = { @@ -669,5 +670,6 @@ Event.add( ) Public.bottom_guis_frame = bottom_guis_frame +ComfyGui.screen_to_bypass(bottom_guis_frame) return Public diff --git a/locale/en/mtn_fortress_v3.cfg b/locale/en/mtn_fortress_v3.cfg index 33ea0b58..d0b7502b 100644 --- a/locale/en/mtn_fortress_v3.cfg +++ b/locale/en/mtn_fortress_v3.cfg @@ -87,7 +87,7 @@ sold_out=Sold out! flamethrower_turret=Upgrades the amount of flamethrowers that can be placed. land_mine=Upgrades the amount of landmines that can be placed. car=Portable Car Surface\nCan be killed easily. -tank=Portable Tank Surface\nChonk tank, can resist heavy damage.\nTo buy this, you need to have a car in your inventory. +tank=Portable Tank Surface\nChonk tank, can resist heavy damage. tank_cannon_na=Tank Cannon\nAvailable after wave __1__. vehicle_machine_gun_na=Car Machine Gun\nAvailable after wave __1__. diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index 86559af3..b0b1f1cd 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -259,6 +259,8 @@ local function on_player_changed_surface(event) local diff = player.gui.top['difficulty_gui'] local charging = player.gui.top['charging_station'] local frame = player.gui.top[main_frame_name] + local spell_gui_frame_name = RPG_Settings.spell_gui_frame_name + local spell_cast_buttons = player.gui.screen[spell_gui_frame_name] if info then info.tooltip = ({'gui.info_tooltip'}) @@ -287,6 +289,9 @@ local function on_player_changed_surface(event) if rpg_b and not rpg_b.visible then rpg_b.visible = true end + if spell_cast_buttons and not spell_cast_buttons.visible then + spell_cast_buttons.visible = true + end if diff and not diff.visible then diff.visible = true end @@ -308,6 +313,9 @@ local function on_player_changed_surface(event) if rpg_b then rpg_b.visible = false end + if spell_cast_buttons and spell_cast_buttons.visible then + spell_cast_buttons.visible = false + end if rpg_f then rpg_f.destroy() end @@ -366,6 +374,7 @@ local function enable_guis(event) if rpg_b and not rpg_b.visible then rpg_b.visible = true end + if diff and not diff.visible then diff.visible = true end diff --git a/maps/mountain_fortress_v3/icw/functions.lua b/maps/mountain_fortress_v3/icw/functions.lua index a2e77c67..1bfcf3b3 100644 --- a/maps/mountain_fortress_v3/icw/functions.lua +++ b/maps/mountain_fortress_v3/icw/functions.lua @@ -2,11 +2,21 @@ local Public = {} local ICW = require 'maps.mountain_fortress_v3.icw.table' local WPT = require 'maps.mountain_fortress_v3.table' +local Task = require 'utils.task' +local Token = require 'utils.token' local SpamProtection = require 'utils.spam_protection' local main_tile_name = 'tutorial-grid' +local reconstruct_all_trains = + Token.register( + function(data) + local icw = data.icw + Public.reconstruct_all_trains(icw) + end +) + function Public.request_reconstruction(icw) - icw.rebuild_tick = game.tick + 30 + Task.set_timeout_in_ticks(60, reconstruct_all_trains, {icw = icw}) end local function validate_entity(entity) @@ -434,9 +444,9 @@ function Public.create_wagon_room(icw, wagon) construct_wagon_doors(icw, wagon) local mgs = surface.map_gen_settings - mgs.width = area.right_bottom.x * 2 - mgs.height = area.right_bottom.y * 2 - surface.map_gen_settings = mgs + mgs.width = area.right_bottom.x * 2 + mgs.height = area.right_bottom.y * 2 + surface.map_gen_settings = mgs if wagon.entity.type == 'fluid-wagon' then local height = area.right_bottom.y - area.left_top.y diff --git a/maps/mountain_fortress_v3/icw/main.lua b/maps/mountain_fortress_v3/icw/main.lua index 419ff40d..abac56d8 100644 --- a/maps/mountain_fortress_v3/icw/main.lua +++ b/maps/mountain_fortress_v3/icw/main.lua @@ -94,22 +94,12 @@ end local function on_tick() local icw = ICW.get() local tick = game.tick - - if tick % 10 == 1 then + if tick % 10 == 0 then Functions.item_transfer(icw) end if tick % 240 == 0 then Functions.update_minimap(icw) end - - if not icw.rebuild_tick then - return - end - if icw.rebuild_tick ~= tick then - return - end - Functions.reconstruct_all_trains(icw) - icw.rebuild_tick = nil end local function on_init() @@ -141,7 +131,7 @@ end local on_player_or_robot_built_tile = Functions.on_player_or_robot_built_tile Event.on_init(on_init) -Event.add(defines.events.on_tick, on_tick) +Event.on_nth_tick(5, on_tick) Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state) Event.add(defines.events.on_player_changed_surface, on_player_changed_surface) Event.add(defines.events.on_entity_died, on_entity_died) diff --git a/modules/biter_health_booster_v2.lua b/modules/biter_health_booster_v2.lua index 1c396b88..25fa238f 100644 --- a/modules/biter_health_booster_v2.lua +++ b/modules/biter_health_booster_v2.lua @@ -109,7 +109,6 @@ function Public.add_unit(unit, health_multiplier) floor(unit.prototype.max_health * health_multiplier), round(1 / health_multiplier, 5) } - clean_table() end function Public.add_boss_unit(unit, health_multiplier, health_bar_size) @@ -125,7 +124,6 @@ function Public.add_boss_unit(unit, health_multiplier, health_bar_size) round(1 / health_multiplier, 5), {max_health = health, healthbar_id = create_boss_healthbar(unit, health_bar_size), last_update = game.tick} } - clean_table() end local function on_entity_damaged(event) @@ -242,6 +240,7 @@ end Event.on_init(on_init) Event.add(defines.events.on_entity_damaged, on_entity_damaged) +Event.on_nth_tick(7200, clean_table) Event.add(defines.events.on_entity_died, on_entity_died) return Public diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index 251d15d9..592d501f 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -1,4 +1,4 @@ -local Tabs = require 'comfy_panel.main' +local ComfyGui = require 'comfy_panel.main' local P = require 'player_modifiers' local Gui = require 'utils.gui' @@ -513,9 +513,9 @@ function Public.toggle(player, recreate) end if main_frame then remove_main_frame(main_frame, screen) - Tabs.comfy_panel_restore_left_gui(player) + ComfyGui.comfy_panel_restore_left_gui(player) else - Tabs.comfy_panel_clear_left_gui(player) + ComfyGui.comfy_panel_clear_left_gui(player) draw_main_frame(player) end end @@ -526,7 +526,7 @@ function Public.remove_frame(player) if main_frame then remove_main_frame(main_frame, screen) - Tabs.comfy_panel_restore_left_gui(player) + ComfyGui.comfy_panel_restore_left_gui(player) end end @@ -815,4 +815,6 @@ Gui.on_click( end ) +ComfyGui.screen_to_bypass(spell_gui_frame_name) + return Public diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 837c28d3..6d6d6a0d 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -1091,7 +1091,7 @@ local function on_player_used_capsule(event) player.character.surface.create_entity({name = 'water-splash', position = player.position}) p(({'rpg_main.warped_ok'}), Color.info) rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost - elseif projectile_types[obj_name] then + elseif projectile_types[obj_name] then -- projectiles for i = 1, object.amount do local damage_area = { left_top = {x = position.x - 2, y = position.y - 2}, @@ -1107,11 +1107,11 @@ local function on_player_used_capsule(event) p(({'rpg_main.object_spawned', obj_name}), Color.success) rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost else - if object.target then + if object.target then -- rockets and such surface.create_entity({name = obj_name, position = position, force = force, target = target_pos, speed = 1}) p(({'rpg_main.object_spawned', obj_name}), Color.success) rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost - elseif object.obj_to_create == 'fish' then + elseif object.obj_to_create == 'fish' then -- spawn in some fish player.insert({name = 'raw-fish', count = object.amount}) p(({'rpg_main.object_spawned', 'raw-fish'}), Color.success) rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost diff --git a/modules/rpg/settings.lua b/modules/rpg/settings.lua index 5eee5d28..9a6a571f 100644 --- a/modules/rpg/settings.lua +++ b/modules/rpg/settings.lua @@ -31,7 +31,9 @@ function Public.update_spell_gui(player, spell_index) local rpg_t = RPG.get('rpg_t') local spells, names = RPG.rebuild_spells() local main_frame = player.gui.screen[spell_gui_frame_name] - if not main_frame then return end + if not main_frame then + return + end local spell_table = main_frame['spell_table'] if spell_index then if spell_index == 1 then @@ -90,9 +92,30 @@ function Public.spell_gui_settings(player) ) main_frame.auto_center = true local table = main_frame.add({type = 'table', column_count = 3, name = 'spell_table'}) - table.add({type = 'sprite-button', sprite = spells[rpg_t[player.index].dropdown_select_index1].sprite, name = spell1_button_name, tooltip = names[rpg_t[player.index].dropdown_select_index1] or '---'}) - table.add({type = 'sprite-button', sprite = spells[rpg_t[player.index].dropdown_select_index2].sprite, name = spell2_button_name, tooltip = names[rpg_t[player.index].dropdown_select_index2] or '---'}) - table.add({type = 'sprite-button', sprite = spells[rpg_t[player.index].dropdown_select_index3].sprite, name = spell3_button_name, tooltip = names[rpg_t[player.index].dropdown_select_index3] or '---'}) + table.add( + { + type = 'sprite-button', + sprite = spells[rpg_t[player.index].dropdown_select_index1].sprite, + name = spell1_button_name, + tooltip = names[rpg_t[player.index].dropdown_select_index1] or '---' + } + ) + table.add( + { + type = 'sprite-button', + sprite = spells[rpg_t[player.index].dropdown_select_index2].sprite, + name = spell2_button_name, + tooltip = names[rpg_t[player.index].dropdown_select_index2] or '---' + } + ) + table.add( + { + type = 'sprite-button', + sprite = spells[rpg_t[player.index].dropdown_select_index3].sprite, + name = spell3_button_name, + tooltip = names[rpg_t[player.index].dropdown_select_index3] or '---' + } + ) local b1 = table.add({type = 'sprite-button', name = 'mana-cost', tooltip = {'rpg_settings.mana_cost'}, caption = 0}) local b2 = table.add({type = 'sprite-button', name = 'mana', tooltip = {'rpg_settings.mana'}, caption = 0}) local b3 = table.add({type = 'sprite-button', name = 'maxmana', tooltip = {'rpg_settings.mana_max'}, caption = 0}) @@ -515,6 +538,16 @@ function Public.extra_settings(player) }) end end + if not spells[rpg_t[player.index].dropdown_select_index1] then + rpg_t[player.index].dropdown_select_index1 = 1 + end + if not spells[rpg_t[player.index].dropdown_select_index2] then + rpg_t[player.index].dropdown_select_index2 = 1 + end + if not spells[rpg_t[player.index].dropdown_select_index3] then + rpg_t[player.index].dropdown_select_index3 = 1 + end + mana_frame.add({type = 'label', caption = {'rpg_settings.spell_gui_setup'}, tooltip = {'rpg_settings.spell_gui_tooltip'}}) local spell_grid = mana_frame.add({type = 'table', column_count = 4, name = 'spell_grid_table'}) spell_gui_input1 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index1) @@ -523,7 +556,7 @@ function Public.extra_settings(player) spell_gui_input2.style.maximal_width = 135 spell_gui_input3 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index3) spell_gui_input3.style.maximal_width = 135 - spell_select_button = spell_grid.add({type = 'sprite-button', name = spell_gui_button_name, sprite = 'item/raw-fish'}) + spell_grid.add({type = 'sprite-button', name = spell_gui_button_name, sprite = 'item/raw-fish'}) end if rpg_extra.enable_auto_allocate then diff --git a/modules/show_inventory.lua b/modules/show_inventory.lua index 5efecce0..23da9f17 100644 --- a/modules/show_inventory.lua +++ b/modules/show_inventory.lua @@ -350,7 +350,7 @@ local function update_gui() if valid then if success then - if target then + if target and target.valid then local main = target.get_main_inventory().get_contents() local armor = target.get_inventory(defines.inventory.character_armor).get_contents() local guns = target.get_inventory(defines.inventory.character_guns).get_contents() @@ -392,7 +392,7 @@ commands.add_command( end local target_player = game.players[cmd.parameter] - if target_player == player then + if target_player == player and not player.admin then return player.print('Cannot open self.', Color.warning) end local valid, opened = player_opened(player) diff --git a/modules/spawners_contain_biters.lua b/modules/spawners_contain_biters.lua index 2afa716a..07cca049 100644 --- a/modules/spawners_contain_biters.lua +++ b/modules/spawners_contain_biters.lua @@ -1,32 +1,45 @@ -- spawners release biters on death -- by mewmew -local event = require 'utils.event' +local Event = require 'utils.event' local math_random = math.random local biter_building_inhabitants = { - [1] = {{"small-biter",8,16}}, - [2] = {{"small-biter",12,24}}, - [3] = {{"small-biter",8,16},{"medium-biter",1,2}}, - [4] = {{"small-biter",4,8},{"medium-biter",4,8}}, - [5] = {{"small-biter",3,5},{"medium-biter",8,12}}, - [6] = {{"small-biter",3,5},{"medium-biter",5,7},{"big-biter",1,2}}, - [7] = {{"medium-biter",6,8},{"big-biter",3,5}}, - [8] = {{"medium-biter",2,4},{"big-biter",6,8}}, - [9] = {{"medium-biter",2,3},{"big-biter",7,9}}, - [10] = {{"big-biter",4,8},{"behemoth-biter",3,4}} + [1] = {{'small-biter', 8, 16}}, + [2] = {{'small-biter', 12, 24}}, + [3] = {{'small-biter', 8, 16}, {'medium-biter', 1, 2}}, + [4] = {{'small-biter', 4, 8}, {'medium-biter', 4, 8}}, + [5] = {{'small-biter', 3, 5}, {'medium-biter', 8, 12}}, + [6] = {{'small-biter', 3, 5}, {'medium-biter', 5, 7}, {'big-biter', 1, 2}}, + [7] = {{'medium-biter', 6, 8}, {'big-biter', 3, 5}}, + [8] = {{'medium-biter', 2, 4}, {'big-biter', 6, 8}}, + [9] = {{'medium-biter', 2, 3}, {'big-biter', 7, 9}}, + [10] = {{'big-biter', 4, 8}, {'behemoth-biter', 3, 4}} } -local function on_entity_died(event) - if not event.entity.valid then return end - if event.entity.type ~= "unit-spawner" then return end - local e = math.ceil(event.entity.force.evolution_factor * 10) - if e < 1 then e = 1 end - for _, t in pairs(biter_building_inhabitants[e]) do - for x = 1, math_random(t[2],t[3]), 1 do - local p = event.entity.surface.find_non_colliding_position(t[1] , event.entity.position, 6, 1) - if p then event.entity.surface.create_entity {name=t[1], position=p, force = event.entity.force.name} end - end - end +local function on_entity_died(event) + if not event.entity.valid then + return + end + local entity = event.entity + if entity.type ~= 'unit-spawner' then + return + end + if entity.force.index == 1 then + return + end + + local e = math.ceil(entity.force.evolution_factor * 10) + if e < 1 then + e = 1 + end + for _, t in pairs(biter_building_inhabitants[e]) do + for _ = 1, math_random(t[2], t[3]), 1 do + local p = entity.surface.find_non_colliding_position(t[1], entity.position, 6, 1) + if p then + entity.surface.create_entity {name = t[1], position = p, force = entity.force.name} + end + end + end end - -event.add(defines.events.on_entity_died, on_entity_died) + +Event.add(defines.events.on_entity_died, on_entity_died) diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index befcf29c..d3545e53 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -526,7 +526,7 @@ local function increase_biters_health() modified_unit_health = 30 end debug_print('[HEALTHBOOSTER] > Normal Units Health Boosted: ' .. modified_unit_health) - WD.set('modified_unit_health', modified_unit_health + 0.02) + WD.set('modified_unit_health', modified_unit_health + 0.04) -- this sets boss units health if boosted_health == 1 then diff --git a/utils/datastore/jail_data.lua b/utils/datastore/jail_data.lua index 9782ee2f..97d1854d 100644 --- a/utils/datastore/jail_data.lua +++ b/utils/datastore/jail_data.lua @@ -282,6 +282,10 @@ local validate_args = function(data) local message = data.message local cmd = data.cmd + if not griefer then + return + end + if not type(griefer) == 'string' then Utils.print_to(player, 'Invalid name.') return false diff --git a/utils/datastore/server_ups.lua b/utils/datastore/server_ups.lua index 4da99109..9d582376 100644 --- a/utils/datastore/server_ups.lua +++ b/utils/datastore/server_ups.lua @@ -1,5 +1,6 @@ local Server = require 'utils.server' local Event = require 'utils.event' +local ComfyGui = require 'comfy_panel.main' local Color = require 'utils.color_presets' local ups_label = 'ups_label' @@ -105,6 +106,8 @@ commands.add_command( end ) +ComfyGui.screen_to_bypass(ups_label) + Event.add( defines.events.on_player_display_resolution_changed, function(event)