mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-17 21:08:08 +02:00
apocalypse fix
This commit is contained in:
parent
da4827ea98
commit
6f944fc3ec
@ -357,7 +357,9 @@ global.config = {
|
||||
},
|
||||
-- enables a command which allows for an end-game event
|
||||
apocalypse = {
|
||||
enabled = true
|
||||
enabled = true,
|
||||
-- chance behemoth biters and spitters will double on death.
|
||||
duplicate_chance = 0.05
|
||||
},
|
||||
-- gradually informs players of features such as chat, toasts, etc.
|
||||
player_onboarding = {
|
||||
|
@ -5,15 +5,13 @@ local Global = require 'utils.global'
|
||||
local Command = require 'utils.command'
|
||||
local Toast = require 'features.gui.toast'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local HailHydra = require 'map_gen.shared.hail_hydra'
|
||||
local Color = require 'resources.color_presets'
|
||||
local Ranks = require 'resources.ranks'
|
||||
local Event = require 'utils.event'
|
||||
local random = math.random
|
||||
local Config = require 'config'
|
||||
|
||||
-- Constants
|
||||
local hail_hydra_data = {
|
||||
['behemoth-spitter'] = {['behemoth-spitter'] = 0.01},
|
||||
['behemoth-biter'] = {['behemoth-biter'] = 0.01}
|
||||
}
|
||||
local duplicate_chance = Config.apocalypse.duplicate_chance
|
||||
|
||||
-- Local var
|
||||
local Public = {}
|
||||
@ -35,6 +33,54 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
local name_map = {['behemoth-biter'] = true, ['behemoth-spitter'] = true}
|
||||
|
||||
local biter_died_token =
|
||||
Token.register(
|
||||
function(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local name = entity.name
|
||||
if not name_map[name] then
|
||||
return
|
||||
end
|
||||
|
||||
local force_name = entity.force.name
|
||||
if force_name ~= 'enemy' then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = entity.surface
|
||||
local create_entity = surface.create_entity
|
||||
local position = entity.position
|
||||
local spawn = {name = entity.name, force = 'enemy', position = position}
|
||||
|
||||
create_entity(spawn)
|
||||
|
||||
if random() > duplicate_chance then
|
||||
return
|
||||
end
|
||||
|
||||
local spawn_position = surface.find_non_colliding_position(name, position, 8, 1)
|
||||
if not spawn_position then
|
||||
return
|
||||
end
|
||||
|
||||
spawn.position = spawn_position
|
||||
create_entity(spawn)
|
||||
end
|
||||
)
|
||||
|
||||
local aliens = {
|
||||
'behemoth-biter',
|
||||
'behemoth-biter',
|
||||
'behemoth-spitter',
|
||||
'behemoth-spitter'
|
||||
}
|
||||
|
||||
local biter_spawn_token =
|
||||
Token.register(
|
||||
function()
|
||||
@ -45,9 +91,6 @@ local biter_spawn_token =
|
||||
surface = RS.get_surface()
|
||||
player_force = game.forces.player
|
||||
|
||||
HailHydra.set_hydras(hail_hydra_data)
|
||||
HailHydra.set_evolution_scale(1)
|
||||
HailHydra.enable_hail_hydra()
|
||||
enemy_force.evolution_factor = 1
|
||||
|
||||
local p_spawn = player_force.get_spawn_position(surface)
|
||||
@ -55,13 +98,6 @@ local biter_spawn_token =
|
||||
|
||||
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
|
||||
@ -72,6 +108,8 @@ local biter_spawn_token =
|
||||
|
||||
group.set_command({type = defines.command.attack_area, destination = {0, 0}, radius = 500})
|
||||
Toast.toast_all_players(500, {'apocalypse.toast_message'})
|
||||
|
||||
Event.add_removable(defines.events.on_entity_died, biter_died_token)
|
||||
end
|
||||
)
|
||||
|
||||
@ -97,7 +135,7 @@ function Public.begin_apocalypse(_, player)
|
||||
|
||||
primitives.apocalypse_now = true
|
||||
game.print({'apocalypse.apocalypse_begins'}, Color.pink)
|
||||
Task.set_timeout(15, biter_spawn_token, {})
|
||||
Task.set_timeout(1, biter_spawn_token, {})
|
||||
end
|
||||
|
||||
Command.add(
|
||||
|
Loading…
x
Reference in New Issue
Block a user