diff --git a/locale/en/mtn_fortress_v3.cfg b/locale/en/mtn_fortress_v3.cfg index 136d49bd..673c0d0a 100644 --- a/locale/en/mtn_fortress_v3.cfg +++ b/locale/en/mtn_fortress_v3.cfg @@ -175,7 +175,7 @@ warp_tooltip=This is the time you have left before the train enters the boss zon clock=within __3__/__4__ __5__ [img=utility/clock] not_done=__1__/__2__ [img=utility/not_available] not_done_empty=[img=utility/not_available] -done=__2__/__2__ [img=utility/check_mark_green] +done=__1__/__2__ [img=utility/check_mark_green] done_empty=[img=utility/check_mark_green] final_boss_message_start=[font=default-bold][color=blue]Mapkeeper:[/color]\nGet ready! Final battle awaits.[/font] diff --git a/maps/mountain_fortress_v3/icw/linked_chests.lua b/maps/mountain_fortress_v3/icw/linked_chests.lua index 194b6f5b..7f11ba1e 100644 --- a/maps/mountain_fortress_v3/icw/linked_chests.lua +++ b/maps/mountain_fortress_v3/icw/linked_chests.lua @@ -604,6 +604,15 @@ local function on_built_entity(event, mode, bypass) return end + if not WPT.locomotive.is_around_train(entity) then + if entity.type ~= 'entity-ghost' then + player.insert({name = 'linked-chest', count = 1}) + end + entity.destroy() + player.print(module_name .. 'Linked chests only work inside the locomotive aura.', Color.warning) + return + end + local trusted_player = Session.get_trusted_player(player) if not trusted_player then @@ -670,6 +679,15 @@ local function built_entity_robot(event) return end + if not WPT.locomotive.is_around_train(entity) then + if entity.type ~= 'entity-ghost' then + player.insert({name = 'linked-chest', count = 1}) + end + entity.destroy() + player.print(module_name .. 'Linked chests only work inside the locomotive aura.', Color.warning) + return + end + local trusted_player = Session.get_trusted_player(player) if not trusted_player then diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 406c5b08..22ebed97 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -9,6 +9,8 @@ local Gui = require 'utils.gui' local Alert = require 'utils.alert' local Color = require 'utils.color_presets' +local zone_settings = Public.zone_settings + local rpg_main_frame = RPG.main_frame_name local random = math.random local floor = math.floor @@ -115,6 +117,18 @@ local function is_around_train(data) return false end +local function is_inside_zone(data) + local entity = data.entity + local loco = data.locomotive.position + local position = entity.position + local inside = ((position.y - loco.y) ^ 2) < zone_settings.zone_depth ^ 2 + + if inside then + return true + end + return false +end + local function hurt_players_outside_of_aura() local Diff = Difficulty.get() if not Diff then @@ -647,6 +661,36 @@ function Public.is_around_train(entity) return success end +function Public.is_inside_zone(entity) + local locomotive = Public.get('locomotive') + local active_surface_index = Public.get('active_surface_index') + + if not active_surface_index then + return false + end + if not locomotive then + return false + end + if not locomotive.valid then + return false + end + + if not entity or not entity.valid then + return false + end + + local surface = game.surfaces[active_surface_index] + + local data = { + locomotive = locomotive, + surface = surface, + entity = entity + } + + local success = is_inside_zone(data) + return success +end + function Public.render_train_hp() local active_surface_index = Public.get('active_surface_index') local surface = game.surfaces[active_surface_index] diff --git a/maps/mountain_fortress_v3/locomotive/market.lua b/maps/mountain_fortress_v3/locomotive/market.lua index 8e4a25c9..b57dcecb 100644 --- a/maps/mountain_fortress_v3/locomotive/market.lua +++ b/maps/mountain_fortress_v3/locomotive/market.lua @@ -964,6 +964,8 @@ local function gui_click(event) if name == 'upgrade_pickaxe' then player.remove_item({name = item.value, count = item.price}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + this.upgrades.pickaxe_tier = this.upgrades.pickaxe_tier + item.stack local pickaxe_upgrades = Public.pickaxe_upgrades @@ -997,6 +999,8 @@ local function gui_click(event) player.remove_item({name = item.value, count = item.price}) local message = ({'locomotive.health_bought_info', shopkeeper, player.name, format_number(item.price, true)}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + Alert.alert_all_players(5, message) Server.to_discord_bold( table.concat { @@ -1049,6 +1053,8 @@ local function gui_click(event) end player.remove_item({name = item.value, count = item.price}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + local message = ({'locomotive.aura_bought_info', shopkeeper, player.name, format_number(item.price, true)}) Alert.alert_all_players(5, message) @@ -1091,6 +1097,8 @@ local function gui_click(event) player.remove_item({name = item.value, count = item.price}) local message = ({'locomotive.xp_bought_info', shopkeeper, player.name, format_number(item.price, true)}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + Alert.alert_all_players(5, message) Server.to_discord_bold( table.concat { @@ -1111,6 +1119,8 @@ local function gui_click(event) player.remove_item({name = item.value, count = item.price}) local message = ({'locomotive.mystical_bought_info', shopkeeper, player.name, format_number(item.price, true)}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + Alert.alert_all_players(5, message) Server.to_discord_bold( table.concat { @@ -1135,6 +1145,8 @@ local function gui_click(event) format_number(item.price, true) }) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + Alert.alert_all_players(5, message) Server.to_discord_bold( table.concat { @@ -1159,6 +1171,8 @@ local function gui_click(event) format_number(item.price, true) }) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + Alert.alert_all_players(5, message) Server.to_discord_bold( table.concat { @@ -1182,6 +1196,8 @@ local function gui_click(event) format_number(item.price, true) }) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + Alert.alert_all_players(5, message) Server.to_discord_bold( table.concat { @@ -1198,6 +1214,8 @@ local function gui_click(event) if name == 'flamethrower_turrets' then player.remove_item({name = item.value, count = item.price}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + if item.stack >= 1 then local message = ({ 'locomotive.one_flamethrower_bought_info', @@ -1237,6 +1255,8 @@ local function gui_click(event) if name == 'land_mine' then player.remove_item({name = item.value, count = item.price}) + Event.raise(Public.events.on_market_item_purchased, {cost = item.price}) + if item.stack >= 1 and this.upgrades.landmine.bought % 10 == 0 then local message = ({ 'locomotive.landmine_bought_info', @@ -1274,8 +1294,10 @@ local function gui_click(event) player.print(({'locomotive.change_returned'}), {r = 0.98, g = 0.66, b = 0.22}) player.insert({name = name, count = inserted_count}) player.remove_item({name = item.value, count = ceil(item.price * (inserted_count / item.stack))}) + Event.raise(Public.events.on_market_item_purchased, {cost = ceil(item.price * (inserted_count / item.stack))}) else player.remove_item({name = item.value, count = cost}) + Event.raise(Public.events.on_market_item_purchased, {cost = cost}) end redraw_market_items(data.item_frame, player, data.search_text) redraw_coins_left(data.coins_left, player) diff --git a/maps/mountain_fortress_v3/stateful/gui.lua b/maps/mountain_fortress_v3/stateful/gui.lua index 00bdb518..2bb04573 100644 --- a/maps/mountain_fortress_v3/stateful/gui.lua +++ b/maps/mountain_fortress_v3/stateful/gui.lua @@ -740,9 +740,10 @@ local function update_data() local objective = stateful.selected_objectives[objective_index] local objective_name = objective.name local callback = Token.get(objective.token) - local _, _, objective_locale_right = callback() + local _, _, objective_locale_right, _, objective_tooltip_right = callback() if name == objective_name and frame and frame.valid then frame.caption = objective_locale_right + frame.tooltip = objective_tooltip_right end end end diff --git a/maps/mountain_fortress_v3/stateful/main.lua b/maps/mountain_fortress_v3/stateful/main.lua index d2ad067b..943e23c7 100644 --- a/maps/mountain_fortress_v3/stateful/main.lua +++ b/maps/mountain_fortress_v3/stateful/main.lua @@ -29,7 +29,7 @@ Event.add( end if name == objectives.research_level_selection.name then - objectives.research_level_count = objectives.research_level_count + 1 + objectives.research_level_selection.research_count = objectives.research_level_selection.research_count + 1 end end ) @@ -111,5 +111,6 @@ Event.on_nth_tick( ) Event.add(defines.events.on_pre_player_died, Public.on_pre_player_died) +Event.add(Public.events.on_market_item_purchased, Public.on_market_item_purchased) return Public diff --git a/maps/mountain_fortress_v3/stateful/table.lua b/maps/mountain_fortress_v3/stateful/table.lua index e3f7aeab..b77e4faa 100644 --- a/maps/mountain_fortress_v3/stateful/table.lua +++ b/maps/mountain_fortress_v3/stateful/table.lua @@ -321,6 +321,19 @@ local function on_pre_player_died(event) Task.set_timeout_in_ticks(5, search_corpse_token, {player_index = player.index}) end +local function on_market_item_purchased(event) + if not event.cost then + return + end + + local coins = this.objectives.locomotive_market_coins_spent + if not coins then + return + end + + coins.spent = coins.spent + event.cost +end + local empty_token = Token.register( function() @@ -331,19 +344,20 @@ local empty_token = local killed_enemies_token = Token.register( function() - local enemies_killed = Public.get_killed_enemies_count('biter', 'spitter') - if enemies_killed >= this.objectives.killed_enemies then - return true, {'stateful.enemies_killed'}, {'stateful.done', format_number(this.objectives.killed_enemies, true), format_number(this.objectives.killed_enemies)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} + local actual = Public.get_killed_enemies_count('biter', 'spitter') + local expected = this.objectives.killed_enemies + if actual >= expected then + return true, {'stateful.enemies_killed'}, {'stateful.done', format_number(expected, true), format_number(expected)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} end - return false, {'stateful.enemies_killed'}, {'stateful.not_done', format_number(enemies_killed, true), format_number(this.objectives.killed_enemies, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} + return false, {'stateful.enemies_killed'}, {'stateful.not_done', format_number(actual, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} end ) local research_level_selection_token = Token.register( function() - local actual = this.objectives.research_level_count + local actual = this.objectives.research_level_selection.research_count local expected = this.objectives.research_level_selection.count if actual >= expected then return true, {'stateful.research', this.objectives.research_level_selection.name}, {'stateful.done', expected, expected}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} @@ -368,33 +382,36 @@ local locomotive_market_coins_spent_token = local trees_farmed_token = Token.register( function() - local trees = get_entity_mined_count('tree') - if trees >= this.objectives.trees_farmed then - return true, {'stateful.trees_mined'}, {'stateful.done', format_number(this.objectives.trees_farmed, true), format_number(this.objectives.trees_farmed, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} + local actual = get_entity_mined_count('tree') + local expected = this.objectives.trees_farmed + if actual >= expected then + return true, {'stateful.trees_mined'}, {'stateful.done', format_number(expected, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} end - return false, {'stateful.trees_mined'}, {'stateful.not_done', format_number(trees, true), format_number(this.objectives.trees_farmed, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} + return false, {'stateful.trees_mined'}, {'stateful.not_done', format_number(actual, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} end ) local rocks_farmed_token = Token.register( function() - local rocks = get_entity_mined_count('rock') - if rocks >= this.objectives.rocks_farmed then - return true, {'stateful.rocks_mined'}, {'stateful.done', format_number(this.objectives.rocks_farmed, true), format_number(this.objectives.rocks_farmed, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} + local actual = get_entity_mined_count('rock') + local expected = this.objectives.rocks_farmed + if actual >= expected then + return true, {'stateful.rocks_mined'}, {'stateful.done', format_number(expected, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} end - return false, {'stateful.rocks_mined'}, {'stateful.not_done', format_number(rocks, true), format_number(this.objectives.rocks_farmed, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} + return false, {'stateful.rocks_mined'}, {'stateful.not_done', format_number(actual, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} end ) local rockets_launched_token = Token.register( function() - local launched = game.forces.player.rockets_launched - if launched >= this.objectives.rockets_launched then - return true, {'stateful.launch_rockets'}, {'stateful.done', format_number(this.objectives.rockets_launched, true), format_number(this.objectives.rockets_launched, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} + local actual = game.forces.player.rockets_launched + local expected = this.objectives.rockets_launched + if actual >= expected then + return true, {'stateful.launch_rockets'}, {'stateful.done', format_number(expected, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_completed'} end - return false, {'stateful.launch_rockets'}, {'stateful.not_done', format_number(launched, true), format_number(this.objectives.rockets_launched, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} + return false, {'stateful.launch_rockets'}, {'stateful.not_done', format_number(actual, true), format_number(expected, true)}, {'stateful.generic_tooltip'}, {'stateful.tooltip_not_completed'} end ) @@ -479,10 +496,10 @@ local function get_random_research_recipe() shuffle(research_level_list) if this.test_mode then - return {name = research_level_list[1], count = 1} + return {name = research_level_list[1], count = 1, research_count = 0} end - return {name = research_level_list[1], count = scale(2, 40, 1.08)} + return {name = research_level_list[1], count = scale(2, 40, 1.08), research_count = 0} end local function get_random_objectives() @@ -734,7 +751,6 @@ function Public.reset_stateful(refresh_gui) single_item = get_random_item(), killed_enemies = 10, research_level_selection = get_random_research_recipe(), - research_level_count = 0, locomotive_market_coins_spent = 0, locomotive_market_coins_spent_required = 1, trees_farmed = 10, @@ -749,10 +765,9 @@ function Public.reset_stateful(refresh_gui) single_item = get_random_item(), killed_enemies = random(scale(80000, 10000000), scale(100000, 10000000)), research_level_selection = get_random_research_recipe(), - research_level_count = 0, locomotive_market_coins_spent = { spent = 0, - required = random(scale(10000, 400000), scale(15000, 400000)) + required = random(scale(50000), scale(100000)) }, trees_farmed = random(scale(9500, 400000), scale(10500, 400000)), rocks_farmed = random(scale(45000, 4000000), scale(55000, 4000000)), @@ -771,8 +786,7 @@ function Public.reset_stateful(refresh_gui) local t = { ['randomized_zone'] = this.objectives.randomized_zone, - ['randomized_wave'] = this.objectives.randomized_wave, - ['research_level_count'] = this.objectives.research_level_count + ['randomized_wave'] = this.objectives.randomized_wave } for index = 1, #this.selected_objectives do local objective = this.selected_objectives[index] @@ -1014,5 +1028,6 @@ 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 +Public.on_market_item_purchased = on_market_item_purchased return Public diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index a58634ec..6886f525 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -17,7 +17,8 @@ local random = math.random Public.events = { reset_map = Event.generate_event_name('reset_map'), - on_entity_mined = Event.generate_event_name('on_entity_mined') + on_entity_mined = Event.generate_event_name('on_entity_mined'), + on_market_item_purchased = Event.generate_event_name('on_market_item_purchased') } Global.register( diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index 98f573c7..5411b89d 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -282,7 +282,7 @@ local function place_wagon(data, adjusted_zones) end local surface = data.surface - local tiles = data.hidden_tiles + local tiles = data.tiles local entities = data.entities local top_y = data.top_y local position = {x = data.x, y = top_y + random(4, 12) * 2}