diff --git a/locale/en/mtn_fortress_v3.cfg b/locale/en/mtn_fortress_v3.cfg index dc9683b2..107f2c34 100644 --- a/locale/en/mtn_fortress_v3.cfg +++ b/locale/en/mtn_fortress_v3.cfg @@ -164,7 +164,7 @@ crafted_items=[font=default-bold]Handcraft item (__1__): [/font] cast_spell=[font=default-bold]Cast spell (__1__): [/font] launch_item=[font=default-bold]Launch item __1__ to orbit: [/font] launch_rockets=[font=default-bold]Rockets launched: [/font] -minerals_mined=[font=default-bold]Minerals mined: [/font] +minerals_mined=[font=default-bold]Entities mined: [/font] production=[font=default-bold]Produce the following items: [/font] production_single=[font=default-bold]Produce the following item: [/font] market_spent=[font=default-bold]Spend coins in market: [/font] @@ -183,9 +183,11 @@ linked_tooltip=Complete this objective by converting the given amount of chests linked_static_tooltip=Complete this objective by purchasing the given amount of linked chests. production_tooltip=Complete this objective by producing the given item(s). generic_tooltip=Complete this to mark the objective as complete. +mined_entities_tooltip=Complete this objective by mining the given amount of entities.\nMine rocks, trees and scrap. win_conditions_tooltip=In order to win the game, you must complete all these objectives that are listed below! [img=utility/force_editor_icon] tooltip_failed=You've failed to complete this objective. [img=utility/not_available] tooltip_not_completed=This objective has not been completed. [img=utility/not_available] +tooltip_not_completed_entities=This objective has not been completed. [img=utility/not_available]\nMine rocks, trees and scrap. tooltip_completed=This objective has been completed. [img=utility/check_mark_green] tooltip_final=[entity=behemoth-biter] Final battle awaits. tooltip_final_disabled=[entity=behemoth-biter] Final battle is currently being reworked. diff --git a/maps/mountain_fortress_v3/core.lua b/maps/mountain_fortress_v3/core.lua index c19f54c0..aa508378 100644 --- a/maps/mountain_fortress_v3/core.lua +++ b/maps/mountain_fortress_v3/core.lua @@ -31,4 +31,6 @@ Public.permission_groups = require 'maps.mountain_fortress_v3.locomotive.permiss Public.spawn_locomotive = require 'maps.mountain_fortress_v3.locomotive.spawn_locomotive' Public.charging_station = require 'maps.mountain_fortress_v3.charging_station' +require 'modules.melee_mode' + return Public diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 9a0129f8..74524bf9 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -777,7 +777,7 @@ local set_unit_raffle_token = local spitter_raffle = WD.get('spitter_raffle') --[[@as table]] local boss_raffle = WD.get('boss_raffle') --[[@as table]] - if level > 100 then + if level >= 100 and level < 200 then biter_raffle['mtn-addon-small-piercing-biter-t2'] = round(2000 - level * 1.75, 6) biter_raffle['mtn-addon-small-acid-biter-t2'] = round(2000 - level * 1.75, 6) biter_raffle['mtn-addon-small-explosive-biter-t2'] = round(2000 - level * 1.75, 6) @@ -802,7 +802,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-medium-fire-biter-t2'] = round(2000 - (level - 1.50), 6) end - if level > 200 then + if level >= 200 and level < 250 then biter_raffle['mtn-addon-small-piercing-biter-t3'] = round(1500 - level * 1.75, 6) biter_raffle['mtn-addon-small-acid-biter-t3'] = round(1500 - level * 1.75, 6) biter_raffle['mtn-addon-small-explosive-biter-t3'] = round(1500 - level * 1.75, 6) @@ -827,7 +827,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-medium-poison-biter-t3'] = round(1500 - (level - 1.50), 6) boss_raffle['mtn-addon-medium-fire-biter-t3'] = round(1500 - (level - 1.50), 6) end - if level > 250 then + if level >= 250 and level < 300 then if Public.is_modded_pt2 then biter_raffle['medium-wriggler-pentapod'] = round(250 - (level - 250), 6) end @@ -843,7 +843,7 @@ local set_unit_raffle_token = spitter_raffle['mtn-addon-medium-poison-spitter-t1'] = round(250 - (level - 250), 6) spitter_raffle['mtn-addon-medium-fire-spitter-t1'] = round(250 - (level - 250), 6) end - if level > 300 then + if level >= 300 and level < 350 then biter_raffle['mtn-addon-medium-piercing-biter-t2'] = round(300 - (level - 300), 6) biter_raffle['mtn-addon-medium-acid-biter-t2'] = round(300 - (level - 300), 6) biter_raffle['mtn-addon-medium-explosive-biter-t2'] = round(300 - (level - 300), 6) @@ -868,7 +868,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-big-poison-biter-t1'] = round(300 - (level - 300), 6) boss_raffle['mtn-addon-big-fire-biter-t1'] = round(300 - (level - 300), 6) end - if level > 350 then + if level >= 350 and level < 400 then biter_raffle['mtn-addon-medium-piercing-biter-t3'] = round(350 - (level - 350), 6) biter_raffle['mtn-addon-medium-acid-biter-t3'] = round(350 - (level - 350), 6) biter_raffle['mtn-addon-medium-explosive-biter-t3'] = round(350 - (level - 350), 6) @@ -894,7 +894,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-big-fire-biter-t2'] = round(350 - (level - 350), 6) end - if level > 400 then + if level >= 400 and level < 500 then boss_raffle['mtn-addon-big-piercing-spitter-t3'] = round(400 - (level - 400), 6) boss_raffle['mtn-addon-big-acid-spitter-t3'] = round(400 - (level - 400), 6) boss_raffle['mtn-addon-big-explosive-spitter-t3'] = round(400 - (level - 400), 6) @@ -908,7 +908,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-big-fire-biter-t3'] = round(400 - (level - 400), 6) end - if level > 500 then + if level >= 500 and level < 550 then if Public.is_modded_pt2 then biter_raffle['big-wriggler-pentapod'] = round(500 - (level - 500) * 2, 6) end @@ -936,7 +936,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-behemoth-poison-biter-t1'] = round(500 - (level - 500) * 2, 6) boss_raffle['mtn-addon-behemoth-fire-biter-t1'] = round(500 - (level - 500) * 2, 6) end - if level > 550 then + if level >= 550 and level < 600 then biter_raffle['mtn-addon-big-piercing-biter-t2'] = round(550 - (level - 550) * 2, 6) biter_raffle['mtn-addon-big-acid-biter-t2'] = round(550 - (level - 550) * 2, 6) biter_raffle['mtn-addon-big-explosive-biter-t2'] = round(550 - (level - 550) * 2, 6) @@ -962,7 +962,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-behemoth-fire-biter-t2'] = round(550 - (level - 550) * 2, 6) end - if level > 600 then + if level >= 600 and level < 800 then biter_raffle['mtn-addon-big-piercing-biter-t3'] = round(600 - (level - 600) * 2, 6) biter_raffle['mtn-addon-big-acid-biter-t3'] = round(600 - (level - 600) * 2, 6) biter_raffle['mtn-addon-big-explosive-biter-t3'] = round(600 - (level - 600) * 2, 6) @@ -988,7 +988,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-behemoth-fire-biter-t3'] = round(600 - (level - 600) * 2, 6) end - if level > 800 then + if level >= 800 and level < 900 then biter_raffle['mtn-addon-behemoth-piercing-biter-t1'] = round((level - 800) * 2.75, 6) biter_raffle['mtn-addon-behemoth-acid-biter-t1'] = round((level - 800) * 2.75, 6) biter_raffle['mtn-addon-behemoth-explosive-biter-t1'] = round((level - 800) * 2.75, 6) @@ -1013,7 +1013,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-boss-poison-spitter-t1'] = round((level - 800) * 2.75, 6) boss_raffle['mtn-addon-boss-fire-spitter-t1'] = round((level - 800) * 2.75, 6) end - if level > 900 then + if level >= 900 and level < 1000 then biter_raffle['mtn-addon-behemoth-piercing-biter-t2'] = round((level - 900) * 2.75, 6) biter_raffle['mtn-addon-behemoth-acid-biter-t2'] = round((level - 900) * 2.75, 6) biter_raffle['mtn-addon-behemoth-explosive-biter-t2'] = round((level - 900) * 2.75, 6) @@ -1039,7 +1039,7 @@ local set_unit_raffle_token = boss_raffle['mtn-addon-boss-fire-spitter-t2'] = round((level - 900) * 2.75, 6) end - if level > 1000 then + if level >= 1000 then biter_raffle['mtn-addon-behemoth-piercing-biter-t3'] = round((level - 1000) * 2.75, 6) biter_raffle['mtn-addon-behemoth-acid-biter-t3'] = round((level - 1000) * 2.75, 6) biter_raffle['mtn-addon-behemoth-explosive-biter-t3'] = round((level - 1000) * 2.75, 6) diff --git a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua index f461a84d..b173530d 100644 --- a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua @@ -6,6 +6,19 @@ local Event = require 'utils.event' local Server = require 'utils.server' local random = math.random +local random_tiles = +{ + 'black-refined-concrete', + 'refined-concrete', + 'refined-hazard-concrete-left', + 'refined-hazard-concrete-right', + 'brown-refined-concrete', + 'blue-refined-concrete', + 'red-refined-concrete', + 'yellow-refined-concrete', + 'concrete', +} + local function initial_cargo_boxes() return { @@ -81,7 +94,7 @@ local place_tiles_token = return end - MapFunctions.draw_noise_tile_circle(position, 'black-refined-concrete', surface, 22) + MapFunctions.draw_noise_tile_circle(position, random_tiles[random(1, #random_tiles)], surface, 22) end ) @@ -290,8 +303,8 @@ function Public.locomotive_spawn(surface, position, reversed) this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({ name = 'raw-fish', count = 999999 }) end - Task.set_timeout_in_ticks(15, place_tiles_token, { surface = surface, position = position }) Task.set_timeout_in_ticks(50, set_loco_cargo, data) + Task.set_timeout_in_ticks(300, place_tiles_token, { surface = surface, position = position }) game.forces.player.set_spawn_position({ this.locomotive.position.x - 5, this.locomotive.position.y }, locomotive.surface) end diff --git a/maps/mountain_fortress_v3/stateful/table.lua b/maps/mountain_fortress_v3/stateful/table.lua index f2f967ae..96693eb9 100644 --- a/maps/mountain_fortress_v3/stateful/table.lua +++ b/maps/mountain_fortress_v3/stateful/table.lua @@ -1056,7 +1056,7 @@ local minerals_farmed_token = if actual >= expected then return true, { 'stateful.minerals_mined' }, { 'stateful.done', format_number(expected, true), format_number(expected, true) }, { 'stateful.generic_tooltip' }, { 'stateful.tooltip_completed' } end - return false, { 'stateful.minerals_mined' }, { 'stateful.not_done', format_number(actual, true), format_number(expected, true) }, { 'stateful.generic_tooltip' }, { 'stateful.tooltip_not_completed' } + return false, { 'stateful.minerals_mined' }, { 'stateful.not_done', format_number(actual, true), format_number(expected, true) }, { 'stateful.mined_entities_tooltip' }, { 'stateful.tooltip_not_completed_entities' } end ) @@ -2518,417 +2518,4 @@ Public.grant_non_limit_reached_buff = grant_non_limit_reached_buff Public.apply_buffs = apply_buffs Public.apply_permanent_buffs = apply_permanent_buffs -if _DEBUG then - Event.on_init( - function () - local cbl = Task.get(apply_settings_token) - storage.tokens.utils_server.server_time.secs = 1187954 - local data = - { - rounds_survived = 75, - season = 10, - test_mode = false, - permanent_buffs = - { - { - name = 'xp_level', - discord = 'RPG XP level bonus - start with more XP levels', - tooltip = 'Selecting this buff will grant the team 20 more XP levels!', - poll_name = 'RPG XP level', - modifier = 'rpg', - per_force = true, - state = 20 - } - }, - buffs = - { - { - name = 'character_running_speed_modifier', - discord = 'Running speed modifier - run faster!', - tooltip = 'Selecting this buff will grant the team 5% increased running speed!', - poll_name = 'Running speed', - modifier = 'force', - per_force = true, - state = 0.05 - }, - { - name = 'manual_mining_speed_modifier', - discord = 'Mining speed modifier - mine faster!', - tooltip = 'Selecting this buff will grant the team 15% increased mining speed!', - poll_name = 'Mining speed', - modifier = 'force', - per_force = true, - state = 0.15 - }, - { - name = 'laboratory_speed_modifier', - discord = 'Laboratory speed modifier - labs work faster!', - tooltip = 'Selecting this buff will grant the team 15% increased laboratory speed!', - poll_name = 'Laboratory speed', - modifier = 'force', - per_force = true, - state = 0.15 - }, - { - name = 'laboratory_productivity_bonus', - discord = 'Laboratory productivity bonus - labs dupe things!', - tooltip = 'Selecting this buff will grant the team 15% increased laboratory productivity!', - poll_name = 'Laboratory productivity', - modifier = 'force', - per_force = true, - state = 0.15 - }, - { - name = 'worker_robots_storage_bonus', - discord = 'Robot storage bonus - robots carry more!', - tooltip = 'Selecting this buff will grant the team 100% increased robot storage!', - poll_name = 'Robot storage', - modifier = 'force', - per_force = true, - state = 1 - }, - { - name = 'worker_robots_battery_modifier', - discord = 'Robot battery bonus - robots work longer!', - tooltip = 'Selecting this buff will grant the team 100% increased robot battery!', - poll_name = 'Robot battery', - modifier = 'force', - per_force = true, - state = 1 - }, - { - name = 'worker_robots_speed_modifier', - discord = 'Robot speed modifier - robots move faster!', - tooltip = 'Selecting this buff will grant the team 50% increased robot speed!', - poll_name = 'Robot speed', - modifier = 'force', - per_force = true, - state = 0.5 - }, - { - name = 'mining_drill_productivity_bonus', - discord = 'Drill productivity bonus - drills work faster!', - tooltip = 'Selecting this buff will grant the team 50% increased drill productivity!', - poll_name = 'Drill productivity', - modifier = 'force', - per_force = true, - state = 0.5 - }, - { - name = 'character_health_bonus', - discord = 'Character health bonus - more health!', - tooltip = 'Selecting this buff will grant the team 250 flat increased character health!', - poll_name = 'Character health', - modifier = 'force', - per_force = true, - state = 250 - }, - { - name = 'distance', - discord = 'RPG reach distance bonus - reach further!', - tooltip = 'Selecting this buff will grant the team 5% increased reach distance!', - poll_name = 'RPG reach distance', - modifier = 'rpg_distance', - per_force = true, - modifiers = { 'character_resource_reach_distance_bonus', 'character_item_pickup_distance_bonus', 'character_loot_pickup_distance_bonus', 'character_reach_distance_bonus' }, - state = 0.05 - }, - { - name = 'manual_crafting_speed_modifier', - discord = 'Crafting speed modifier - craft faster!', - tooltip = 'Selecting this buff will grant the team 12% increased crafting speed!', - poll_name = 'Crafting speed', - modifier = 'force', - per_force = true, - state = 0.12 - }, - { - name = 'xp_bonus', - discord = 'RPG XP point bonus - more XP points from kills etc.', - tooltip = 'Selecting this buff will grant the team 12% increased XP points from kills etc.', - poll_name = 'RPG XP point', - modifier = 'rpg', - per_force = true, - state = 0.12 - }, - { - name = 'xp_level', - discord = 'RPG XP level bonus - start with more XP levels', - tooltip = 'Selecting this buff will grant the team 20 more XP levels!', - poll_name = 'RPG XP level', - modifier = 'rpg', - per_force = true, - state = 20 - }, - { - name = 'chemicals_s', - discord = 'Starting items supplies - start with some sulfur', - tooltip = 'Selecting this buff will grant the team 50 sulfur at start!', - poll_name = 'Starting items (sulfur)', - modifier = 'starting_items', - limit = 200, - add_per_buff = 50, - items = - { - { name = 'sulfur', count = 50 } - } - }, - { - name = 'chemicals_p', - discord = 'Starting items supplies - start with some plastic bar', - tooltip = 'Selecting this buff will grant the team 100 plastic bar at start!', - poll_name = 'Starting items (plastic bar)', - modifier = 'starting_items', - limit = 200, - add_per_buff = 50, - items = - { - { name = 'plastic-bar', count = 100 } - } - }, - { - name = 'supplies', - discord = 'Starting items supplies - start with some copper and iron plates', - tooltip = 'Selecting this buff will grant the team 100 copper and iron plates at start!', - poll_name = 'Starting items (copper and iron plates)', - modifier = 'starting_items', - limit = 1000, - add_per_buff = 100, - items = - { - { name = 'iron-plate', count = 100 }, - { name = 'copper-plate', count = 100 } - } - }, - { - name = 'supplies_1', - discord = 'Starting items supplies - start with more copper and iron plates', - tooltip = 'Selecting this buff will grant the team 200 copper and iron plates at start!', - poll_name = 'Starting items (more copper and iron plates)', - modifier = 'starting_items', - limit = 1000, - add_per_buff = 200, - items = - { - { name = 'iron-plate', count = 200 }, - { name = 'copper-plate', count = 200 } - } - }, - { - name = 'supplies_2', - discord = 'Starting items supplies - start with even more copper and iron plates', - tooltip = 'Selecting this buff will grant the team 400 copper and iron plates at start!', - poll_name = 'Starting items (even more copper and iron plates)', - modifier = 'starting_items', - limit = 1000, - add_per_buff = 400, - items = - { - { name = 'iron-plate', count = 400 }, - { name = 'copper-plate', count = 400 } - } - }, - { - name = 'defense_3', - discord = 'Defense starting supplies - start with more turrets and ammo', - tooltip = 'Selecting this buff will grant the team 1 rocket launcher and 100 rockets at start!', - poll_name = 'Starting items (more turrets and ammo)', - modifier = 'starting_items', - limit = 1, - add_per_buff = 1, - items = - { - { name = 'rocket-launcher', count = 1 }, - { name = 'rocket', count = 100 } - } - }, - { - name = 'armor', - discord = 'Armor starting supplies - start with some armor and solar panels', - tooltip = 'Selecting this buff will grant the team 1 modular armor and 2 solar panel equipment at start!', - poll_name = 'Starting items (armor and solar panels)', - modifier = 'starting_items', - limit = 1, - add_per_buff = 1, - items = - { - { name = 'modular-armor', count = 1 }, - { name = 'solar-panel-equipment', count = 2 } - } - }, - { - name = 'production_1', - discord = 'Production starting supplies - start with some steel furnaces and solid fuel', - tooltip = 'Selecting this buff will grant the team 4 steel furnaces and 100 solid fuel at start!', - poll_name = 'Starting items (steel furnaces and solid fuel)', - modifier = 'starting_items', - limit = 2, - add_per_buff = 1, - items = - { - { name = 'steel-furnace', count = 4 }, - { name = 'solid-fuel', count = 100 } - } - }, - { - name = 'fast_startup_1', - discord = 'Assembling starting supplies - start with some assembling machines T2', - tooltip = 'Selecting this buff will grant the team 2 assembling machines T2 at start!', - poll_name = 'Starting items (assembling machines T2)', - modifier = 'starting_items', - limit = 25, - add_per_buff = 2, - items = - { - { name = 'assembling-machine-2', count = 2 } - } - }, - { - name = 'fast_startup_2', - discord = 'Assembling starting supplies - start with some assembling machines T3', - tooltip = 'Selecting this buff will grant the team 2 assembling machines T3 at start!', - poll_name = 'Starting items (assembling machines T3)', - modifier = 'starting_items', - limit = 25, - add_per_buff = 2, - items = - { - { name = 'assembling-machine-3', count = 2 } - } - }, - { - name = 'heal-thy-buildings', - discord = 'Repair starting supplies - start with some repair packs', - tooltip = 'Selecting this buff will grant the team 5 repair packs at start!', - poll_name = 'Starting items (repair packs)', - modifier = 'starting_items', - limit = 20, - add_per_buff = 2, - items = - { - { name = 'repair-pack', count = 5 } - } - }, - { - name = 'extra_wagons', - discord = 'Extra wagon at start', - tooltip = 'Selecting this buff will grant the team 1 extra wagon at start!', - poll_name = 'Starting items (extra wagon)', - modifier = 'locomotive', - limit = 4, - state = 1 - }, - { - name = 'american_oil', - discord = 'Oil tech - start with some crude oil barrels', - tooltip = 'Selecting this buff will grant the team 20 crude oil barrels at start!', - poll_name = 'Starting items (crude oil barrels)', - modifier = 'starting_items', - limit = 40, - add_per_buff = 20, - items = - { - { name = 'crude-oil-barrel', count = 20 } - } - }, - { - name = 'steel_plates', - discord = 'Steel tech - start with some steel plates', - tooltip = 'Selecting this buff will grant the team 100 steel plates at start!', - poll_name = 'Starting items (steel plates)', - modifier = 'starting_items', - limit = 200, - add_per_buff = 100, - items = - { - { name = 'steel-plate', count = 100 } - } - }, - { - name = 'red_science', - discord = 'Science tech - start with some red science packs', - tooltip = 'Selecting this buff will grant the team 10 red science packs at start!', - poll_name = 'Starting items (red science packs)', - modifier = 'starting_items', - limit = 200, - add_per_buff = 10, - items = - { - { name = 'automation-science-pack', count = 10 } - } - }, - { - name = 'roboport_equipement', - discord = 'Equipement tech - start with a personal roboport', - tooltip = 'Selecting this buff will grant the team 1 personal roboport equipment at start!', - poll_name = 'Starting items (personal roboport)', - modifier = 'starting_items', - limit = 4, - add_per_buff = 1, - items = - { - { name = 'personal-roboport-equipment', count = 1 } - } - }, - { - name = 'mk1_tech_unlocked', - discord = 'Equipement tech - start with power armor tech unlocked.', - tooltip = 'Selecting this buff will grant the team power armor tech unlocked at start!', - poll_name = 'Tech unlock (power armor)', - modifier = 'tech', - limit = 1, - add_per_buff = 1, - techs = - { - { name = 'power-armor', count = 1 } - } - }, - { - name = 'steel_axe_unlocked', - discord = 'Equipement tech - start with steel axe tech unlocked.', - tooltip = 'Selecting this buff will grant the team steel axe tech unlocked at start!', - poll_name = 'Tech unlock (steel axe)', - modifier = 'tech', - limit = 1, - add_per_buff = 1, - techs = - { - { name = 'steel-axe', count = 1 } - } - }, - { - name = 'military_2_unlocked', - discord = 'Equipement tech - start with military 2 tech unlocked.', - tooltip = 'Selecting this buff will grant the team military 2 tech unlocked at start!', - poll_name = 'Tech unlock (military 2)', - modifier = 'tech', - limit = 1, - add_per_buff = 1, - techs = - { - { name = 'military-2', count = 1 } - } - }, - { - name = 'all_the_fish', - discord = 'Wagon is full of fish!', - tooltip = 'Selecting this buff will grant the team 1 wagon full of fish at start!', - poll_name = 'Fishes', - modifier = 'fish', - limit = 1, - add_per_buff = 1 - } - }, - current_date = 1811187954 - } - local settings = - { - value = data - } - cbl(settings) - end - ) -end - - return Public diff --git a/modules/melee_mode.lua b/modules/melee_mode.lua index c2d533cc..8c05f184 100644 --- a/modules/melee_mode.lua +++ b/modules/melee_mode.lua @@ -1,20 +1,26 @@ local Event = require 'utils.event' local Global = require 'utils.global' +local SpamProtection = require 'utils.spam_protection' +local BottomFrame = require 'utils.gui.bottom_frame' +local Gui = require 'utils.gui' + +local melee_mode_name = Gui.uid_name() local state = {} Global.register(state, function (s) state = s end) local function create_gui_button(player) - if player.gui.top.melee_mode then + if player.gui.top[melee_mode_name] then return end local tooltip = { "modules_melee.tooltip" } - local b = player.gui.top.add({ - type = 'sprite-button', - sprite = 'item/pistol', - name = 'melee_mode', - tooltip = tooltip - }) + local b = player.gui.top.add( + { + type = 'sprite-button', + sprite = 'item/pistol', + name = melee_mode_name, + tooltip = tooltip + }) b.style.font_color = { r = 0.11, g = 0.8, b = 0.44 } b.style.font = 'heading-1' b.style.minimal_height = 40 @@ -26,7 +32,24 @@ local function create_gui_button(player) end local function on_player_joined_game(event) - create_gui_button(game.players[event.player_index]) + local activate_custom_buttons = BottomFrame.get('activate_custom_buttons') + local player = game.get_player(event.player_index) + + if activate_custom_buttons then + BottomFrame.add_inner_frame( + { + player = player, + element_name = melee_mode_name, + tooltip = + { + 'modules_melee.tooltip' + }, + sprite = 'item/pistol' + } + ) + else + create_gui_button(player) + end end local function move_to_main(player, from, to) @@ -96,30 +119,38 @@ local function change_to_ranged(player) end local function on_gui_click(event) + local activate_custom_buttons = BottomFrame.get('activate_custom_buttons') + if activate_custom_buttons then + return + end + if not event.element then return end if not event.element.valid then return end - if event.element.name ~= 'melee_mode' then + if event.element.name ~= melee_mode_name then return end - local player = game.players[event.player_index] - local mm = player.gui.top.melee_mode - if mm.sprite == 'item/pistol' then + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + local mm = player.gui.top[melee_mode_name] + if mm and mm.valid and mm.sprite == 'item/pistol' then if change_to_melee(player) then - player.print({ "modules_melee.change_to_melee" }) + player.print({ "modules_melee.change_to_melee" }) mm.sprite = 'technology/steel-axe' else - player.print({ "modules_melee.change_to_melee_failed" }) + player.print({ "modules_melee.change_to_melee_failed" }) end else if change_to_ranged(player) then - player.print({ "modules_melee.change_to_ranged" }) - mm.sprite = 'item/pistol' + player.print({ "modules_melee.change_to_ranged" }) + mm.sprite = 'item/pistol' else - player.print({ "modules_melee.change_to_ranged_failed" }) + player.print({ "modules_melee.change_to_ranged_failed" }) end end end @@ -136,28 +167,79 @@ local function moved_to_string(tbl) end local function player_inventory_changed(player_index, inv_id, name) - local player = game.players[player_index] - if player.gui.top.melee_mode.sprite == 'item/pistol' then + local player = game.get_player(player_index) + if not player or not player.valid then return end + + local activate_custom_buttons = BottomFrame.get('activate_custom_buttons') + if activate_custom_buttons then + local old_frame = BottomFrame.get_frame_by_element_name(player, melee_mode_name) + if old_frame and old_frame.sprite == 'item/pistol' then + return + end + else + if player.gui.top[melee_mode_name] and player.gui.top[melee_mode_name].valid and player.gui.top[melee_mode_name].sprite == 'item/pistol' then + return + end + end + local inv = player.get_inventory(inv_id) local moved = move_to_main(player, inv, player.get_main_inventory()) if #moved > 0 then - player.print({ "melee_mode.move_to_main_inventory", moved_to_string(moved) }) + player.print({ "modules_melee.move_to_main_inventory", moved_to_string(moved) }) end if not inv or not inv.is_empty() then - player.print({ "melee_mode.move_to_main_inventory_failed", name }) + player.print({ "modules_melee.move_to_main_inventory_failed", name }) end end local function on_player_ammo_inventory_changed(event) + if event.tick < 200 then return end player_inventory_changed(event.player_index, defines.inventory.character_ammo, 'ammo') end local function on_player_gun_inventory_changed(event) + if event.tick < 200 then return end player_inventory_changed(event.player_index, defines.inventory.character_guns, 'guns') end +Gui.on_click( + melee_mode_name, + function (event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Mtn v3 Spectate Ready Button') + if is_spamming then + return + end + + local player = event.player + if not player or not player.valid or not player.connected then + return + end + + local old_frame = BottomFrame.get_frame_by_element_name(player, melee_mode_name) + if old_frame and old_frame.sprite == 'item/pistol' then + if change_to_melee(player) then + player.print({ "modules_melee.change_to_melee" }) + old_frame.sprite = 'technology/steel-axe' + BottomFrame.refresh_inner_frames(player) + else + player.print({ "modules_melee.change_to_melee_failed" }) + end + else + if change_to_ranged(player) then + player.print({ "modules_melee.change_to_ranged" }) + old_frame.sprite = 'item/pistol' + BottomFrame.refresh_inner_frames(player) + else + player.print({ "modules_melee.change_to_ranged_failed" }) + end + end + + on_gui_click(event) + end +) + Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_player_ammo_inventory_changed, on_player_ammo_inventory_changed) diff --git a/modules/wave_defense/gui.lua b/modules/wave_defense/gui.lua index de96ee21..d3c60907 100644 --- a/modules/wave_defense/gui.lua +++ b/modules/wave_defense/gui.lua @@ -131,11 +131,14 @@ function Public.update_gui(player) gui.label.tooltip = 'Next pause will occur in: ' .. floor((Public.get('next_pause_interval') - game.tick) / 60 / 60) + 1 .. ' minute(s)' gui.wave_number.tooltip = 'Next pause will occur in: ' .. floor((Public.get('next_pause_interval') - game.tick) / 60 / 60) + 1 .. ' minute(s)' local interval = next_wave - last_wave - local value = 1 - (next_wave - game.tick) / interval - if value < 0 then - value = 0 - elseif value > 1 then - value = 1 + local value = 0 + if interval > 0 then + value = 1 - (next_wave - game.tick) / interval + if value < 0 then + value = 0 + elseif value > 1 then + value = 1 + end end gui.progressbar.value = value else @@ -149,11 +152,14 @@ function Public.update_gui(player) gui.wave_number.tooltip = 'Wave: ' .. wave_number local interval = paused_waves_for - last_pause - local value = 1 - (paused_waves_for - game.tick) / interval - if value < 0 then - value = 0 - elseif value > 1 then - value = 1 + local value = 0 + if interval > 0 then + value = 1 - (paused_waves_for - game.tick) / interval + if value < 0 then + value = 0 + elseif value > 1 then + value = 1 + end end gui.progressbar.value = value return diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 1e940f00..60bf7dee 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -754,6 +754,34 @@ local function increase_unit_group_size() end end +local function set_multi_command() + local surface_index = Public.get('surface_index') + local surface = game.get_surface(surface_index) + if not surface or not surface.valid then + return + end + + local target = Public.get('target') + if not valid(target) then + Event.raise(Public.events.on_primary_target_missing) + return + end + + surface.set_multi_command( + { + command = + { + type = defines.command.attack, + target = target, + distraction = defines.distraction.none + }, + unit_count = 256, + force = 'aggressors', + unit_search_distance = 1024 + } + ) +end + local function increase_max_active_unit_groups() local _increase_max_active_unit_groups = Public.get('increase_max_active_unit_groups') if not _increase_max_active_unit_groups then @@ -1483,7 +1511,8 @@ local tick_tasks = [120] = give_main_command_to_group, [150] = log_threat, [180] = Public.build_worm, - [210] = Public.build_nest + [210] = Public.build_nest, + [600] = set_multi_command, } local tick_tasks_t2 = @@ -1495,8 +1524,7 @@ local tick_tasks_t2 = Public.spawn_unit_group = spawn_unit_group -Event.on_nth_tick( - 30, +Event.add(defines.events.on_tick, function () local tick = game.tick diff --git a/utils/gui/bottom_frame.lua b/utils/gui/bottom_frame.lua index d62a83ac..d071255c 100644 --- a/utils/gui/bottom_frame.lua +++ b/utils/gui/bottom_frame.lua @@ -3,7 +3,8 @@ local Global = require 'utils.global' local Gui = require 'utils.gui' local Task = require 'utils.task_token' -local this = { +local this = +{ players = {}, storage = {}, activate_custom_buttons = false, @@ -21,8 +22,10 @@ Global.register( -- @table events -- @field bottom_quickbar_respawn_raise The event triggered when the bottom quickbar is respawned or raised. -- @field bottom_quickbar_location_changed The event triggered when the location of the bottom quickbar is changed. -local Public = { - events = { +local Public = +{ + events = + { bottom_quickbar_respawn_raise = Event.generate_event_name('bottom_quickbar_respawn_raise'), bottom_quickbar_location_changed = Event.generate_event_name('bottom_quickbar_location_changed') } @@ -35,7 +38,8 @@ local get_player_data local main_frame_name = Gui.uid_name() -local sections = { +local sections = +{ [1] = 1, [2] = 1, [3] = 2, @@ -81,7 +85,8 @@ get_player_data = function (player, remove_user_data) return end if not this.players[player.index] then - this.players[player.index] = { + this.players[player.index] = + { state = 'bottom_right', section = {}, direction = 'vertical', @@ -130,7 +135,8 @@ local function refresh_inner_frames(player) end section_row_index[row_selection] = - section_row_index.inner_frame.add { + section_row_index.inner_frame.add + { type = 'sprite-button', sprite = row_selection_data.sprite, name = row_selection_data.name, @@ -208,7 +214,8 @@ local function add_inner_frame(data) end local storage_data_section = storage_data[player_data.row_index] - storage_data_section[player_data.row_selection] = { + storage_data_section[player_data.row_selection] = + { name = element_name, sprite = sprite, tooltip = tooltip @@ -220,6 +227,23 @@ local function add_inner_frame(data) Task.priority_delay(2, refresh_inner_frames_token, { player_index = player.index }) end +local function get_frame_by_element_name(player, element_name) + local player_data, storage_data = get_player_data(player) + if not player_data or not storage_data or not player_data.frame or not player_data.frame.valid then + return + end + + for _, row_index_data in pairs(storage_data) do + if row_index_data and type(row_index_data) == 'table' then + for _, row_selection_data in pairs(row_index_data) do + if row_selection_data and row_selection_data.name == element_name then + return row_selection_data + end + end + end + end +end + destroy_frame = function (player) local gui = player.gui local frame = gui.screen[main_frame_name] @@ -244,7 +268,8 @@ local function create_frame(player, alignment, location, data) alignment = alignment or 'vertical' frame = - player.gui.screen.add { + player.gui.screen.add + { type = 'frame', name = main_frame_name, direction = alignment @@ -265,7 +290,8 @@ local function create_frame(player, alignment, location, data) end local inner_frame = - frame.add { + frame.add + { type = 'frame', direction = alignment } @@ -305,13 +331,15 @@ set_location = function (player, state) if state == 'bottom_left' then if data.above then - location = { + location = + { x = (resolution.width / 2) - ((259) * scale), y = (resolution.height - (-12 + (40 * 5) * scale)) } alignment = 'horizontal' else - location = { + location = + { -- x = (resolution.width / 2) - ((54 + 528 - 44) * scale), x = (resolution.width / 2) - ((455 + (data.row_index * 40)) * scale), y = (resolution.height - (96 * scale)) @@ -320,21 +348,24 @@ set_location = function (player, state) data.bottom_state = 'bottom_left' elseif state == 'bottom_right' then if data.above then - location = { + location = + { -- x = (resolution.width / 2) - ((-262 - (40 * t[data.row_index])) * scale), x = (resolution.width / 2) - ((-460 + (data.row_index * 40)) * scale), y = (resolution.height - (-12 + (40 * 5) * scale)) } alignment = 'horizontal' else - location = { + location = + { x = (resolution.width / 2) - ((54 + -689) * scale), y = (resolution.height - (96 * scale)) } end data.bottom_state = 'bottom_right' else - location = { + location = + { x = (resolution.width / 2) - ((54 + -528) * scale), y = (resolution.height - (96 * scale)) } @@ -577,12 +608,14 @@ Event.add( ) Public.main_frame_name = main_frame_name +Public.refresh_inner_frames = refresh_inner_frames Public.get_player_data = get_player_data Public.remove_player = remove_player Public.set_location = set_location Public.get_location = get_location Public.set_top = set_top Public.add_inner_frame = add_inner_frame +Public.get_frame_by_element_name = get_frame_by_element_name Gui.screen_to_bypass(main_frame_name) return Public