1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-16 02:47:48 +02:00
ComfyFactorio/maps/mountain_fortress_v3/breached_wall.lua

126 lines
4.1 KiB
Lua
Raw Normal View History

2020-05-23 21:18:18 +02:00
local Collapse = require 'modules.collapse'
local Terrain = require 'maps.mountain_fortress_v3.terrain'
local Balance = require 'maps.mountain_fortress_v3.balance'
2020-07-25 17:22:04 +02:00
local RPG_Settings = require 'modules.rpg.table'
local RPG = require 'modules.rpg.main'
local WD = require 'modules.wave_defense.table'
2020-06-03 20:09:00 +02:00
local WPT = require 'maps.mountain_fortress_v3.table'
2020-06-07 13:33:24 +02:00
local Alert = require 'utils.alert'
2020-05-23 21:18:18 +02:00
local Event = require 'utils.event'
2020-06-05 23:53:58 +02:00
local Task = require 'utils.task'
local Token = require 'utils.token'
2020-05-23 21:18:18 +02:00
local raise_event = script.raise_event
local floor = math.floor
local sqrt = math.sqrt
2020-06-05 23:53:58 +02:00
local concat = table.concat
2020-05-23 21:18:18 +02:00
2020-06-05 23:53:58 +02:00
local keeper = '[color=blue]Mapkeeper:[/color] \n'
local collapse_message =
Token.register(
function(data)
local pos = data.position
local message = keeper .. 'Warning, collapse has begun!'
local collapse_position = {
position = pos
}
Alert.alert_all_players_location(collapse_position, message)
end
)
local zone_complete =
Token.register(
function(data)
local bonus = data.bonus
local player = data.player
local message = keeper .. 'Survivor! Well done. You have completed zone: ' .. bonus
2020-06-07 13:33:24 +02:00
Alert.alert_player_warning(player, 10, message)
2020-06-05 23:53:58 +02:00
end
)
local first_player_to_zone =
Token.register(
function(data)
local player = data.player
local breached_wall = data.breached_wall
local message = concat {keeper .. player.name .. ' was the first to reach zone ' .. breached_wall .. '.'}
Alert.alert_all_players(10, message)
end
)
local artillery_warning =
Token.register(
function()
local message = keeper .. 'Warning, Artillery have been spotted north!'
Alert.alert_all_players(10, message)
end
)
2020-06-03 20:09:00 +02:00
2020-05-23 21:18:18 +02:00
local function distance(player)
2020-07-25 17:22:04 +02:00
local rpg_t = RPG_Settings.get('rpg_t')
local rpg_extra = RPG_Settings.get('rpg_extra')
2020-06-03 20:09:00 +02:00
local bonus = rpg_t[player.index].bonus
2020-05-23 21:18:18 +02:00
local breached_wall = WPT.get('breached_wall')
2020-07-06 15:45:09 +02:00
local bonus_xp_on_join = WPT.get('bonus_xp_on_join')
2020-06-03 20:09:00 +02:00
2020-05-23 21:18:18 +02:00
local distance_to_center = floor(sqrt(player.position.x ^ 2 + player.position.y ^ 2))
local location = distance_to_center
2020-06-03 20:09:00 +02:00
if location < Terrain.level_depth * bonus - 10 then
2020-05-23 21:18:18 +02:00
return
end
2020-06-03 20:09:00 +02:00
local max = Terrain.level_depth * bonus
local breach_max = Terrain.level_depth * breached_wall
local breach_max_times = location >= breach_max
local max_times = location >= max
if max_times then
if breach_max_times then
2020-05-23 21:18:18 +02:00
rpg_extra.breached_walls = rpg_extra.breached_walls + 1
2020-07-06 15:45:09 +02:00
rpg_extra.reward_new_players = bonus_xp_on_join * rpg_extra.breached_walls
2020-07-14 21:50:56 +02:00
WPT.set().breached_wall = breached_wall + 1
WPT.set().placed_trains_in_zone.placed = 0
2020-07-22 18:58:42 +02:00
WPT.set().placed_trains_in_zone.randomized = false
2020-07-14 21:50:56 +02:00
WPT.set().placed_trains_in_zone.positions = {}
2020-05-23 21:18:18 +02:00
raise_event(Balance.events.breached_wall, {})
2020-06-05 23:53:58 +02:00
local data = {
player = player,
breached_wall = breached_wall
}
Task.set_timeout_in_ticks(360, first_player_to_zone, data)
2020-06-03 20:09:00 +02:00
if breached_wall == 5 then
2020-06-05 23:53:58 +02:00
Task.set_timeout_in_ticks(360, artillery_warning)
2020-06-03 20:09:00 +02:00
end
end
if not Collapse.start_now() then
Collapse.start_now(true)
2020-06-05 23:53:58 +02:00
local data = {
position = Collapse.get_position()
}
Task.set_timeout_in_ticks(550, collapse_message, data)
2020-05-23 21:18:18 +02:00
end
2020-06-03 20:09:00 +02:00
rpg_t[player.index].bonus = bonus + 1
2020-06-05 23:53:58 +02:00
local data = {
player = player,
bonus = bonus
}
Task.set_timeout_in_ticks(1, zone_complete, data)
2020-07-06 15:45:09 +02:00
RPG.gain_xp(player, bonus_xp_on_join * bonus)
2020-05-23 21:18:18 +02:00
return
end
end
local function on_player_changed_position(event)
local player = game.players[event.player_index]
local map_name = 'mountain_fortress_v3'
if string.sub(player.surface.name, 0, #map_name) ~= map_name then
return
end
distance(player)
end
Event.add(defines.events.on_player_changed_position, on_player_changed_position)