mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
commit
16c119096f
@ -3,6 +3,7 @@ local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Report = require 'features.report'
|
||||
local Apocalypse = require 'features.apocalypse'
|
||||
local Utils = require 'utils.core'
|
||||
local Game = require 'utils.game'
|
||||
local Event = require 'utils.event'
|
||||
@ -485,3 +486,16 @@ Command.add(
|
||||
},
|
||||
revive_ghosts
|
||||
)
|
||||
|
||||
-- Commands with no functions, only calls to other modules
|
||||
|
||||
Command.add(
|
||||
'apocalypse',
|
||||
{
|
||||
description = "Calls for the endtimes. This really ends the map, so you must use '/apocalypse end this map'",
|
||||
arguments = {'confirmation'},
|
||||
capture_excess_arguments = true,
|
||||
required_rank = Ranks.admin,
|
||||
},
|
||||
Apocalypse.begin_apocalypse
|
||||
)
|
||||
|
94
features/apocalypse.lua
Normal file
94
features/apocalypse.lua
Normal file
@ -0,0 +1,94 @@
|
||||
local table = require 'utils.table'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Game = require 'utils.game'
|
||||
local Toast = require 'features.gui.toast'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local HailHydra = require 'map_gen.shared.hail_hydra'
|
||||
|
||||
local clear_table = table.clear_table
|
||||
|
||||
local Public = {}
|
||||
|
||||
local hydra_config = {
|
||||
['behemoth-spitter'] = {['behemoth-spitter'] = 0.01},
|
||||
['behemoth-biter'] = {['behemoth-biter'] = 0.01}
|
||||
}
|
||||
|
||||
local biter_spawn_token =
|
||||
Token.register(
|
||||
function(data)
|
||||
local surface = data.surface
|
||||
local group = data.group
|
||||
local p_spawn = data.p_spawn
|
||||
|
||||
local create_entity = surface.create_entity
|
||||
|
||||
local aliens = {
|
||||
'behemoth-biter',
|
||||
'behemoth-biter',
|
||||
'behemoth-spitter',
|
||||
'behemoth-spitter'
|
||||
}
|
||||
|
||||
for i = 1, #aliens do
|
||||
local spawn_pos = surface.find_non_colliding_position('behemoth-biter', p_spawn, 300, 1)
|
||||
if spawn_pos then
|
||||
local biter = create_entity {name = aliens[i], position = spawn_pos}
|
||||
group.add_member(biter)
|
||||
end
|
||||
end
|
||||
|
||||
group.set_command({type = defines.command.attack_area, destination = {0, 0}, radius = 500})
|
||||
Toast.toast_all_players(500, 'The end times are here. The four biters of the apocalypse have been summoned. Repent as the aliens take back what is theirs.')
|
||||
end
|
||||
)
|
||||
|
||||
function Public.begin_apocalypse(args, player)
|
||||
if args.confirmation ~= 'end this map' then
|
||||
Game.player_print('You must use /apocalypse end this map')
|
||||
return
|
||||
end
|
||||
|
||||
if global.apocalypse_now then
|
||||
return
|
||||
end
|
||||
game.server_save('pre-apocalypse')
|
||||
global.apocalypse_now = true
|
||||
local surface
|
||||
local player_force
|
||||
local enemy_force = game.forces.enemy
|
||||
|
||||
if player and player.valid then
|
||||
surface = player.surface
|
||||
player_force = player.force
|
||||
else
|
||||
surface = RS.get_surface()
|
||||
player_force = game.forces.player
|
||||
end
|
||||
|
||||
local hydras = global.config.hail_hydra.hydras
|
||||
clear_table(hydras)
|
||||
for k, v in pairs(hydra_config) do
|
||||
hydras[k] = v
|
||||
end
|
||||
HailHydra.enable_hail_hydra()
|
||||
enemy_force.evolution_factor = 1
|
||||
|
||||
local p_spawn = player_force.get_spawn_position(surface)
|
||||
local group = surface.create_unit_group {position = p_spawn}
|
||||
|
||||
game.print('The ground begins to rumble. It seems as if the world itself is coming to an end.')
|
||||
|
||||
Task.set_timeout(
|
||||
60,
|
||||
biter_spawn_token,
|
||||
{
|
||||
p_spawn = p_spawn,
|
||||
group = group,
|
||||
surface = surface
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
return Public
|
@ -3,7 +3,7 @@ local Global = require 'utils.global'
|
||||
local Token = require 'utils.token'
|
||||
local Command = require 'utils.command'
|
||||
local Event = require 'utils.event'
|
||||
local Ranks = require 'utils.ranks'
|
||||
local Ranks = require 'resources.ranks'
|
||||
local random = math.random
|
||||
local ceil = math.ceil
|
||||
local floor = math.floor
|
||||
|
@ -1,6 +1,9 @@
|
||||
-- Cut off a limb, and two more shall take its place!
|
||||
local Event = require 'utils.event'
|
||||
local CreateParticles = require 'features.create_particles'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
@ -13,68 +16,111 @@ local config = global.config.hail_hydra
|
||||
local evolution_scale = config.evolution_scale
|
||||
local hydras = config.hydras
|
||||
|
||||
local primitives = {enabled = nil}
|
||||
|
||||
Global.register(
|
||||
{
|
||||
primitives = primitives
|
||||
},
|
||||
function(tbl)
|
||||
primitives = tbl.primitives
|
||||
end
|
||||
)
|
||||
|
||||
local Public = {}
|
||||
|
||||
local function create_attack_command(position, target)
|
||||
local command = {type = attack_area, destination = position, radius = 10}
|
||||
if target then
|
||||
command = {type = compound, structure_type = logical_or, commands = {
|
||||
{type = attack, target = target},
|
||||
command,
|
||||
}}
|
||||
command = {
|
||||
type = compound,
|
||||
structure_type = logical_or,
|
||||
commands = {
|
||||
{type = attack, target = target},
|
||||
command
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
return command
|
||||
end
|
||||
|
||||
local on_died =
|
||||
Token.register(
|
||||
function(event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
|
||||
Event.add(defines.events.on_entity_died, function (event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
local hydra = hydras[name]
|
||||
if not hydra then
|
||||
return
|
||||
end
|
||||
|
||||
local hydra = hydras[name]
|
||||
if not hydra then
|
||||
return
|
||||
end
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
local evolution_factor = force.evolution_factor * evolution_scale
|
||||
local cause = event.cause
|
||||
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
local evolution_factor = force.evolution_factor * evolution_scale
|
||||
local cause = event.cause
|
||||
local surface = entity.surface
|
||||
local create_entity = surface.create_entity
|
||||
local find_non_colliding_position = surface.find_non_colliding_position
|
||||
|
||||
local surface = entity.surface
|
||||
local create_entity = surface.create_entity
|
||||
local find_non_colliding_position = surface.find_non_colliding_position
|
||||
local command = create_attack_command(position, cause)
|
||||
|
||||
local command = create_attack_command(position, cause)
|
||||
for hydra_spawn, amount in pairs(hydra) do
|
||||
amount = amount + evolution_factor
|
||||
|
||||
for hydra_spawn, amount in pairs(hydra) do
|
||||
amount = amount + evolution_factor
|
||||
local extra_chance = amount % 1
|
||||
if extra_chance > 0 then
|
||||
if random() <= extra_chance then
|
||||
amount = ceil(amount)
|
||||
else
|
||||
amount = floor(amount)
|
||||
end
|
||||
end
|
||||
local particle_count
|
||||
|
||||
local extra_chance = amount % 1
|
||||
if extra_chance > 0 then
|
||||
if random() <= extra_chance then
|
||||
amount = ceil(amount)
|
||||
if amount > 4 then
|
||||
particle_count = 60
|
||||
else
|
||||
amount = floor(amount)
|
||||
particle_count = amount * 15
|
||||
end
|
||||
end
|
||||
local particle_count
|
||||
|
||||
if amount > 4 then
|
||||
particle_count = 60
|
||||
else
|
||||
particle_count = amount * 15
|
||||
end
|
||||
CreateParticles.blood_explosion(create_entity, particle_count, position)
|
||||
|
||||
CreateParticles.blood_explosion(create_entity, particle_count, position)
|
||||
|
||||
for _ = amount, 1, -1 do
|
||||
position = find_non_colliding_position(hydra_spawn, position, 2, 0.4) or position
|
||||
local spawned = create_entity({name = hydra_spawn, force = force, position = position})
|
||||
if spawned and spawned.type == 'unit' then
|
||||
spawned.set_command(command)
|
||||
elseif spawned and cause and cause.valid and cause.force then
|
||||
spawned.shooting_target = cause
|
||||
for _ = amount, 1, -1 do
|
||||
position = find_non_colliding_position(hydra_spawn, position, 2, 0.4) or position
|
||||
local spawned = create_entity({name = hydra_spawn, force = force, position = position})
|
||||
if spawned and spawned.type == 'unit' then
|
||||
spawned.set_command(command)
|
||||
elseif spawned and cause and cause.valid and cause.force then
|
||||
spawned.shooting_target = cause
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
)
|
||||
|
||||
local function register_event()
|
||||
if not primitives.enabled then
|
||||
Event.add_removable(defines.events.on_entity_died, on_died)
|
||||
primitives.enabled = true
|
||||
end
|
||||
end
|
||||
|
||||
if config.enabled then
|
||||
register_event()
|
||||
end
|
||||
|
||||
function Public.enable_hail_hydra()
|
||||
register_event()
|
||||
end
|
||||
|
||||
function Public.disable_hail_hydra()
|
||||
if primitives.enabled then
|
||||
Event.remove_removable(defines.events.on_entity_died, on_died)
|
||||
primitives.enabled = nil
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
||||
|
Loading…
Reference in New Issue
Block a user