1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/biter_battles_v2/game_over.lua

374 lines
14 KiB
Lua
Raw Normal View History

2020-01-02 17:09:24 +02:00
local Public = {}
2019-10-28 18:38:36 +02:00
local Server = require 'utils.server'
2019-03-14 05:25:54 +02:00
2019-03-16 08:31:34 +02:00
local gui_values = {
["north"] = {c1 = "Team North", color1 = {r = 0.55, g = 0.55, b = 0.99}},
["south"] = {c1 = "Team South", color1 = {r = 0.99, g = 0.33, b = 0.33}}
}
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
2019-03-17 03:35:58 +02:00
local rand = math.random(size)
2019-03-16 08:31:34 +02:00
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
2020-01-02 17:09:24 +02:00
function Public.reveal_map()
for _, f in pairs({"north", "south", "player", "spectator"}) do
local r = 768
game.forces[f].chart(game.surfaces["biter_battles"], {{r * -1, r * -1}, {r, r}})
end
end
2019-03-16 08:31:34 +02:00
local function create_victory_gui(player)
local values = gui_values[global.bb_game_won_by_team]
local c = values.c1
if global.tm_custom_name[global.bb_game_won_by_team] then c = global.tm_custom_name[global.bb_game_won_by_team] end
2019-10-06 21:30:03 +02:00
local frame = player.gui.left.add {type = "frame", name = "bb_victory_gui", direction = "vertical", caption = c .. " won!" }
2019-03-16 08:31:34 +02:00
frame.style.font = "heading-1"
2019-03-24 06:21:55 +02:00
frame.style.font_color = values.color1
local l = frame.add {type = "label", caption = global.victory_time}
l.style.font = "heading-2"
l.style.font_color = {r = 0.77, g = 0.77, b = 0.77}
2019-03-16 08:31:34 +02:00
end
local function destroy_entity(e)
if not e.valid then return end
local names = {"big-artillery-explosion", "big-explosion", "big-explosion", "big-explosion", "fire-flame", "massive-explosion"}
e.surface.create_entity({name = names[math.random(1,#names)], position = e.position})
e.die()
end
2019-03-21 11:06:12 +02:00
local function create_kaboom(surface, pos)
surface.create_entity({
name = "explosive-cannon-projectile",
position = pos,
force = "enemy",
target = pos,
speed = 1
})
end
local function annihilate_base_v2(center_pos, surface, force_name)
local positions = {}
for x = -80, 80, 1 do
for y = -80, 80, 1 do
local pos = {x = center_pos.x + x, y = center_pos.y + y}
local distance_to_center = math.ceil(math.sqrt((pos.x - center_pos.x)^2 + (pos.y - center_pos.y)^2))
2019-09-14 03:00:43 +02:00
if distance_to_center < 35 and math.random(1,7) == 1 then
2019-03-21 11:06:12 +02:00
if not positions[distance_to_center] then positions[distance_to_center] = {} end
positions[distance_to_center][#positions[distance_to_center] + 1] = pos
end
end
end
if #positions == 0 then return end
local t = 1
for i1, pos_list in pairs(positions) do
for i2, pos in pairs(pos_list) do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_kaboom,
args = {surface, pos}
}
end
t = t + 4
end
end
2019-03-18 11:15:51 +02:00
local function annihilate_base(center_pos, surface, force_name)
local entities = {}
2019-03-19 23:48:29 +02:00
for _, e in pairs(surface.find_entities_filtered({force = force_name, area = {{center_pos.x - 64, center_pos.y - 64},{center_pos.x + 64, center_pos.y + 64}}})) do
if e.name ~= "character" then
2019-03-18 11:15:51 +02:00
if e.valid then
local distance_to_center = math.ceil(math.sqrt((e.position.x - center_pos.x)^2 + (e.position.y - center_pos.y)^2))
if not entities[distance_to_center] then entities[distance_to_center] = {} end
entities[distance_to_center][#entities[distance_to_center] + 1] = e
end
end
end
if #entities == 0 then return end
local t = 1
for i1, entity_list in pairs(entities) do
for i2, e in pairs(entity_list) do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = destroy_entity,
args = {e}
}
t = t + 3
end
end
end
2019-03-14 05:25:54 +02:00
local function create_fireworks_rocket(surface, position)
2019-03-16 08:31:34 +02:00
local particles = {"coal-particle", "copper-ore-particle", "iron-ore-particle", "stone-particle"}
2019-03-17 03:35:58 +02:00
local particle = particles[math.random(1, #particles)]
local m = math.random(16, 36)
2019-03-14 05:25:54 +02:00
local m2 = m * 0.005
2019-03-16 08:31:34 +02:00
for i = 1, 60, 1 do
2020-01-29 06:55:30 +02:00
surface.create_particle({
2019-03-14 05:25:54 +02:00
name = particle,
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
2019-03-17 03:35:58 +02:00
movement = {m2 - (math.random(0, m) * 0.01), m2 - (math.random(0, m) * 0.01)}
2019-03-14 05:25:54 +02:00
})
end
2019-03-24 06:21:55 +02:00
if math.random(1,10) ~= 1 then return end
2019-03-14 05:25:54 +02:00
surface.create_entity({name = "explosion", position = position})
end
local function fireworks(surface)
2019-03-27 04:58:22 +02:00
local radius = 48
local center_pos = global.rocket_silo[global.bb_game_won_by_team].position
local positions = {}
for x = -80, 80, 1 do
for y = -80, 80, 1 do
local pos = {x = center_pos.x + x, y = center_pos.y + y}
local distance_to_center = math.sqrt((pos.x - center_pos.x)^2 + (pos.y - center_pos.y)^2)
if distance_to_center <= radius then
positions[#positions + 1] = pos
end
end
end
if #positions == 0 then return end
for t = 1, 7200, 1 do
if t % 2 == 0 then
2019-03-16 10:14:41 +02:00
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
2019-03-27 04:58:22 +02:00
local pos = positions[math.random(1, #positions)]
2019-03-14 05:25:54 +02:00
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_fireworks_rocket,
2019-03-16 08:31:34 +02:00
args = {
surface,
2019-03-27 04:58:22 +02:00
{x = pos.x, y = pos.y}
2019-03-16 08:31:34 +02:00
}
}
2019-03-14 05:25:54 +02:00
end
end
end
2019-03-14 23:50:09 +02:00
local function get_sorted_list(column_name, score_list)
for x = 1, #score_list, 1 do
for y = 1, #score_list, 1 do
if not score_list[y + 1] then break end
if score_list[y][column_name] < score_list[y + 1][column_name] then
local key = score_list[y]
score_list[y] = score_list[y + 1]
score_list[y + 1] = key
end
end
end
return score_list
end
local function get_mvps(force)
if not global.score[force] then return false end
local score = global.score[force]
local score_list = {}
for _, p in pairs(game.players) do
if score.players[p.name] then
local killscore = 0
if score.players[p.name].killscore then killscore = score.players[p.name].killscore end
local deaths = 0
if score.players[p.name].deaths then deaths = score.players[p.name].deaths end
local built_entities = 0
if score.players[p.name].built_entities then built_entities = score.players[p.name].built_entities end
local mined_entities = 0
if score.players[p.name].mined_entities then mined_entities = score.players[p.name].mined_entities end
table.insert(score_list, {name = p.name, killscore = killscore, deaths = deaths, built_entities = built_entities, mined_entities = mined_entities})
end
end
local mvp = {}
score_list = get_sorted_list("killscore", score_list)
mvp.killscore = {name = score_list[1].name, score = score_list[1].killscore}
score_list = get_sorted_list("deaths", score_list)
mvp.deaths = {name = score_list[1].name, score = score_list[1].deaths}
score_list = get_sorted_list("built_entities", score_list)
mvp.built_entities = {name = score_list[1].name, score = score_list[1].built_entities}
return mvp
end
local function show_mvps(player)
if not global.score then return end
if player.gui.left["mvps"] then return end
local frame = player.gui.left.add({type = "frame", name = "mvps", direction = "vertical"})
local l = frame.add({type = "label", caption = "MVPs - North:"})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.55, g = 0.55, b = 0.99}
local t = frame.add({type = "table", column_count = 2})
local mvp = get_mvps("north")
if mvp then
local l = t.add({type = "label", caption = "Defender >> "})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local l = t.add({type = "label", caption = mvp.killscore.name .. " with a score of " .. mvp.killscore.score})
l.style.font = "default-bold"
l.style.font_color = {r=0.33, g=0.66, b=0.9}
local l = t.add({type = "label", caption = "Builder >> "})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local l = t.add({type = "label", caption = mvp.built_entities.name .. " built " .. mvp.built_entities.score .. " things"})
l.style.font = "default-bold"
l.style.font_color = {r=0.33, g=0.66, b=0.9}
local l = t.add({type = "label", caption = "Deaths >> "})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local l = t.add({type = "label", caption = mvp.deaths.name .. " died " .. mvp.deaths.score .. " times"})
l.style.font = "default-bold"
l.style.font_color = {r=0.33, g=0.66, b=0.9}
if not global.results_sent_north then
local result = {}
2019-03-16 08:31:34 +02:00
table.insert(result, 'NORTH: \\n')
table.insert(result, 'MVP Defender: \\n')
table.insert(result, mvp.killscore.name .. " with a score of " .. mvp.killscore.score .. "\\n" )
table.insert(result, '\\n')
table.insert(result, 'MVP Builder: \\n')
table.insert(result, mvp.built_entities.name .. " built " .. mvp.built_entities.score .. " things\\n" )
table.insert(result, '\\n')
table.insert(result, 'MVP Deaths: \\n')
table.insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" )
2019-03-14 23:50:09 +02:00
local message = table.concat(result)
2019-10-28 18:38:36 +02:00
Server.to_discord_embed(message)
2019-03-14 23:50:09 +02:00
global.results_sent_north = true
end
end
local l = frame.add({type = "label", caption = "MVPs - South:"})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.99, g = 0.33, b = 0.33}
local t = frame.add({type = "table", column_count = 2})
local mvp = get_mvps("south")
if mvp then
local l = t.add({type = "label", caption = "Defender >> "})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local l = t.add({type = "label", caption = mvp.killscore.name .. " with a score of " .. mvp.killscore.score})
l.style.font = "default-bold"
l.style.font_color = {r=0.33, g=0.66, b=0.9}
local l = t.add({type = "label", caption = "Builder >> "})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local l = t.add({type = "label", caption = mvp.built_entities.name .. " built " .. mvp.built_entities.score .. " things"})
l.style.font = "default-bold"
l.style.font_color = {r=0.33, g=0.66, b=0.9}
local l = t.add({type = "label", caption = "Deaths >> "})
l.style.font = "default-listbox"
l.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local l = t.add({type = "label", caption = mvp.deaths.name .. " died " .. mvp.deaths.score .. " times"})
l.style.font = "default-bold"
l.style.font_color = {r=0.33, g=0.66, b=0.9}
if not global.results_sent_south then
local result = {}
2019-03-16 08:31:34 +02:00
table.insert(result, 'SOUTH: \\n')
table.insert(result, 'MVP Defender: \\n')
table.insert(result, mvp.killscore.name .. " with a score of " .. mvp.killscore.score .. "\\n" )
table.insert(result, '\\n')
table.insert(result, 'MVP Builder: \\n')
table.insert(result, mvp.built_entities.name .. " built " .. mvp.built_entities.score .. " things\\n" )
table.insert(result, '\\n')
table.insert(result, 'MVP Deaths: \\n')
table.insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" )
2019-03-14 23:50:09 +02:00
local message = table.concat(result)
2019-10-28 18:38:36 +02:00
Server.to_discord_embed(message)
2019-03-14 23:50:09 +02:00
global.results_sent_south = true
end
end
end
2019-03-16 08:31:34 +02:00
local enemy_team_of = {
["north"] = "south",
["south"] = "north"
}
2020-01-02 17:09:24 +02:00
function Public.server_restart()
2019-03-18 02:30:41 +02:00
if not global.server_restart_timer then return end
global.server_restart_timer = global.server_restart_timer - 5
if global.server_restart_timer == 180 then return end
if global.server_restart_timer == 0 then
game.print("Map is restarting!", {r=0.22, g=0.88, b=0.22})
local message = 'Map is restarting! '
2019-10-28 18:38:36 +02:00
Server.to_discord_bold(table.concat{'*** ', message, ' ***'})
Server.start_scenario('Biter_Battles')
2019-03-18 02:30:41 +02:00
global.server_restart_timer = nil
return
end
if global.server_restart_timer % 30 == 0 then
game.print("Map will restart in " .. global.server_restart_timer .. " seconds!", {r=0.22, g=0.88, b=0.22})
end
end
2020-01-02 17:09:24 +02:00
function Public.restart_idle_map()
if game.tick < 432000 then return end
if #game.connected_players ~= 0 then global.restart_idle_map_countdown = 2 return end
if not global.restart_idle_map_countdown then global.restart_idle_map_countdown = 2 end
global.restart_idle_map_countdown = global.restart_idle_map_countdown - 1
if global.restart_idle_map_countdown ~= 0 then return end
Server.start_scenario('Biter_Battles')
end
2019-03-24 06:21:55 +02:00
local function set_victory_time()
local minutes = game.tick % 216000
local hours = game.tick - minutes
minutes = math.floor(minutes / 3600)
hours = math.floor(hours / 216000)
if hours > 0 then hours = hours .. " hours and " else hours = "" end
global.victory_time = "Time - " .. hours
global.victory_time = global.victory_time .. minutes
global.victory_time = global.victory_time .. " minutes"
end
2020-01-02 17:09:24 +02:00
function Public.silo_death(event)
2019-03-14 05:25:54 +02:00
if not event.entity.valid then return end
2019-03-18 02:30:41 +02:00
if event.entity.name ~= "rocket-silo" then return end
if global.bb_game_won_by_team then return end
2019-03-16 08:31:34 +02:00
if event.entity == global.rocket_silo.south or event.entity == global.rocket_silo.north then
global.bb_game_won_by_team = enemy_team_of[event.entity.force.name]
2019-03-24 06:21:55 +02:00
set_victory_time()
2019-03-14 05:25:54 +02:00
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/game_won", volume_modifier=1}
2019-03-15 02:39:49 +02:00
if player.gui.left["bb_main_gui"] then player.gui.left["bb_main_gui"].destroy() end
2019-03-16 08:31:34 +02:00
create_victory_gui(player)
show_mvps(player)
2019-03-16 08:31:34 +02:00
end
game.forces["north_biters"].set_friend("north", true)
game.forces["north"].set_friend("north_biters", true)
game.forces["south_biters"].set_friend("south", true)
game.forces["south"].set_friend("south_biters", true)
2019-03-18 04:24:13 +02:00
global.spy_fish_timeout["north"] = game.tick + 999999
global.spy_fish_timeout["south"] = game.tick + 999999
2019-03-24 06:21:55 +02:00
global.server_restart_timer = 180
local c = gui_values[global.bb_game_won_by_team].c1
if global.tm_custom_name[global.bb_game_won_by_team] then c = global.tm_custom_name[global.bb_game_won_by_team] end
2019-10-28 18:38:36 +02:00
Server.to_discord_embed(c .. " has won!")
Server.to_discord_embed(global.victory_time)
2019-03-24 06:21:55 +02:00
2020-01-29 06:55:30 +02:00
fireworks(event.entity.surface)
annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name)
2019-03-16 08:31:34 +02:00
end
2019-03-14 05:25:54 +02:00
end
2020-01-02 17:09:24 +02:00
return Public