mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-17 20:58:13 +02:00
wave defense - fixes
This commit is contained in:
parent
e2f7c5488d
commit
e50243a20b
@ -3,7 +3,7 @@ local Public = require 'modules.wave_defense.table'
|
||||
function Public.wave_defense_roll_biter_name()
|
||||
local biter_raffle = Public.get('biter_raffle')
|
||||
local max_chance = 0
|
||||
for k, v in pairs(biter_raffle) do
|
||||
for _, v in pairs(biter_raffle) do
|
||||
max_chance = max_chance + v
|
||||
end
|
||||
local r = math.random(0, math.floor(max_chance))
|
||||
@ -19,7 +19,7 @@ end
|
||||
function Public.wave_defense_roll_spitter_name()
|
||||
local spitter_raffle = Public.get('spitter_raffle')
|
||||
local max_chance = 0
|
||||
for k, v in pairs(spitter_raffle) do
|
||||
for _, v in pairs(spitter_raffle) do
|
||||
max_chance = max_chance + v
|
||||
end
|
||||
local r = math.random(0, math.floor(max_chance))
|
||||
@ -80,7 +80,7 @@ end
|
||||
function Public.wave_defense_roll_worm_name()
|
||||
local worm_raffle = Public.get('worm_raffle')
|
||||
local max_chance = 0
|
||||
for k, v in pairs(worm_raffle) do
|
||||
for _, v in pairs(worm_raffle) do
|
||||
max_chance = max_chance + v
|
||||
end
|
||||
local r = math.random(0, math.floor(max_chance))
|
||||
|
@ -2,14 +2,13 @@ local Public = require 'modules.wave_defense.table'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
||||
local Diff = require 'modules.difficulty_vote_by_amount'
|
||||
|
||||
local traps = {}
|
||||
local this = {}
|
||||
|
||||
Global.register(
|
||||
traps,
|
||||
this,
|
||||
function(t)
|
||||
traps = t
|
||||
this = t
|
||||
end
|
||||
)
|
||||
|
||||
@ -29,7 +28,7 @@ local random_particles = {
|
||||
'coal-particle'
|
||||
}
|
||||
|
||||
local s_random_particles = #random_particles
|
||||
local size_random_particles = #random_particles
|
||||
|
||||
local function create_particles(data)
|
||||
local surface = data.surface
|
||||
@ -39,13 +38,13 @@ local function create_particles(data)
|
||||
if not surface or not surface.valid then
|
||||
return
|
||||
end
|
||||
for i = 1, amount, 1 do
|
||||
for _ = 1, amount, 1 do
|
||||
local m = random(6, 12)
|
||||
local m2 = m * 0.005
|
||||
|
||||
surface.create_particle(
|
||||
{
|
||||
name = random_particles[random(1, s_random_particles)],
|
||||
name = random_particles[random(1, size_random_particles)],
|
||||
position = position,
|
||||
frame_speed = 0.1,
|
||||
vertical_speed = 0.1,
|
||||
@ -60,8 +59,6 @@ local function spawn_biters(data)
|
||||
local surface = data.surface
|
||||
local position = data.position
|
||||
local h = floor(abs(position.y))
|
||||
local wave_number = Public.get('wave_number')
|
||||
local d = Diff.get()
|
||||
|
||||
if not position then
|
||||
position = surface.find_non_colliding_position('small-biter', position, 10, 1)
|
||||
@ -70,64 +67,44 @@ local function spawn_biters(data)
|
||||
end
|
||||
end
|
||||
|
||||
local m = 0.0015
|
||||
if d.difficulty_vote_index then
|
||||
if not d.strength_modifier then
|
||||
m = m * 1.05
|
||||
else
|
||||
m = m * d.strength_modifier
|
||||
end
|
||||
local unit_to_create
|
||||
|
||||
if random(1, 3) == 1 then
|
||||
unit_to_create = Public.wave_defense_roll_spitter_name()
|
||||
else
|
||||
unit_to_create = Public.wave_defense_roll_biter_name()
|
||||
end
|
||||
|
||||
local boosted_health = 1 + (wave_number * (m * 2))
|
||||
|
||||
if wave_number >= 100 then
|
||||
boosted_health = boosted_health * 2
|
||||
end
|
||||
local modified_unit_health = Public.get('modified_unit_health')
|
||||
local modified_boss_unit_health = Public.get('modified_boss_unit_health')
|
||||
|
||||
Public.wave_defense_set_unit_raffle(h * 0.20)
|
||||
|
||||
local unit
|
||||
if random(1, 3) == 1 then
|
||||
unit = surface.create_entity({name = Public.wave_defense_roll_spitter_name(), position = position})
|
||||
else
|
||||
unit = surface.create_entity({name = Public.wave_defense_roll_biter_name(), position = position})
|
||||
end
|
||||
local unit = surface.create_entity({name = unit_to_create, position = position})
|
||||
|
||||
if random(1, 45) == 1 then
|
||||
BiterHealthBooster.add_unit(unit, boosted_health)
|
||||
elseif random(1, 64) == 1 then
|
||||
BiterHealthBooster.add_boss_unit(unit, boosted_health, 0.38)
|
||||
if random(1, 30) == 1 then
|
||||
BiterHealthBooster.add_boss_unit(unit, modified_boss_unit_health.current_value, 0.38)
|
||||
else
|
||||
BiterHealthBooster.add_unit(unit, modified_unit_health.current_value * 2)
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_worms(data)
|
||||
local wave_number = Public.get('wave_number')
|
||||
local d = Diff.get()
|
||||
local m = 0.0015
|
||||
if d.difficulty_vote_index then
|
||||
if not d.strength_modifier then
|
||||
m = m * 1.05
|
||||
else
|
||||
m = m * d.strength_modifier
|
||||
end
|
||||
end
|
||||
|
||||
local boosted_health = 1 + (wave_number * (m * 2))
|
||||
|
||||
if wave_number >= 100 then
|
||||
boosted_health = boosted_health * 2
|
||||
end
|
||||
local modified_unit_health = Public.get('modified_unit_health')
|
||||
local modified_boss_unit_health = Public.get('modified_boss_unit_health')
|
||||
|
||||
local surface = data.surface
|
||||
local position = data.position
|
||||
Public.wave_defense_set_worm_raffle(sqrt(position.x ^ 2 + position.y ^ 2) * 0.20)
|
||||
local unit = surface.create_entity({name = Public.wave_defense_roll_worm_name(), position = position})
|
||||
|
||||
if random(1, 45) == 1 then
|
||||
BiterHealthBooster.add_unit(unit, boosted_health)
|
||||
elseif random(1, 64) == 1 then
|
||||
BiterHealthBooster.add_boss_unit(unit, boosted_health, 0.38)
|
||||
local unit_to_create = Public.wave_defense_roll_worm_name(sqrt(position.x ^ 2 + position.y ^ 2) * 0.20)
|
||||
|
||||
local unit = surface.create_entity({name = unit_to_create, position = position})
|
||||
|
||||
if random(1, 30) == 1 then
|
||||
BiterHealthBooster.add_boss_unit(unit, modified_boss_unit_health.current_value, 0.38)
|
||||
else
|
||||
BiterHealthBooster.add_unit(unit, modified_unit_health.current_value * 2)
|
||||
end
|
||||
end
|
||||
|
||||
@ -155,11 +132,11 @@ function Public.buried_biter(surface, position, max)
|
||||
local ticks = amount * 30
|
||||
ticks = ticks + 90
|
||||
for t = 1, ticks, 1 do
|
||||
if not traps[game.tick + t] then
|
||||
traps[game.tick + t] = {}
|
||||
if not this[game.tick + t] then
|
||||
this[game.tick + t] = {}
|
||||
end
|
||||
|
||||
traps[game.tick + t][#traps[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
callback = 'create_particles',
|
||||
data = {surface = surface, position = {x = position.x, y = position.y}, amount = 4}
|
||||
}
|
||||
@ -167,7 +144,7 @@ function Public.buried_biter(surface, position, max)
|
||||
if t > 90 then
|
||||
if t % 30 == 29 then
|
||||
a = a + 1
|
||||
traps[game.tick + t][#traps[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
callback = 'spawn_biters',
|
||||
data = {surface = surface, position = {x = position.x, y = position.y}}
|
||||
}
|
||||
@ -202,17 +179,17 @@ function Public.buried_worm(surface, position)
|
||||
ticks = ticks + 90
|
||||
local a = false
|
||||
for t = 1, ticks, 1 do
|
||||
if not traps[game.tick + t] then
|
||||
traps[game.tick + t] = {}
|
||||
if not this[game.tick + t] then
|
||||
this[game.tick + t] = {}
|
||||
end
|
||||
|
||||
traps[game.tick + t][#traps[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
callback = 'create_particles',
|
||||
data = {surface = surface, position = {x = position.x, y = position.y}, amount = 4}
|
||||
}
|
||||
|
||||
if not a then
|
||||
traps[game.tick + t][#traps[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
callback = 'spawn_worms',
|
||||
data = {surface = surface, position = {x = position.x, y = position.y}}
|
||||
}
|
||||
@ -229,10 +206,10 @@ local callbacks = {
|
||||
|
||||
local function on_tick()
|
||||
local t = game.tick
|
||||
if not traps[t] then
|
||||
if not this[t] then
|
||||
return
|
||||
end
|
||||
for _, token in pairs(traps[t]) do
|
||||
for _, token in pairs(this[t]) do
|
||||
local callback = token.callback
|
||||
local data = token.data
|
||||
local cbl = callbacks[callback]
|
||||
@ -240,7 +217,7 @@ local function on_tick()
|
||||
cbl(data)
|
||||
end
|
||||
end
|
||||
traps[t] = nil
|
||||
this[t] = nil
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
@ -1,44 +1,49 @@
|
||||
local Public = require 'modules.wave_defense.table'
|
||||
|
||||
if _DEBUG then
|
||||
commands.add_command(
|
||||
'wd_debug_module',
|
||||
'',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
local param = tostring(cmd.parameter)
|
||||
if param == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
|
||||
if not player.admin then
|
||||
return
|
||||
end
|
||||
|
||||
if param == 'spawn_wave' then
|
||||
return Public.spawn_unit_group(true, true)
|
||||
end
|
||||
|
||||
if param == 'log_all' then
|
||||
return Public.toggle_debug()
|
||||
end
|
||||
|
||||
if param == 'debug_health' then
|
||||
local this = Public.get()
|
||||
|
||||
Public.toggle_debug_health()
|
||||
|
||||
this.next_wave = 1000
|
||||
this.wave_interval = 200
|
||||
this.wave_enforced = true
|
||||
this.debug_only_on_wave_500 = true
|
||||
end
|
||||
commands.add_command(
|
||||
'wd_debug_module',
|
||||
'',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
local param = tostring(cmd.parameter)
|
||||
if param == nil then
|
||||
return
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
|
||||
if not player.admin then
|
||||
return
|
||||
end
|
||||
|
||||
if param == 'spawn_wave' then
|
||||
return Public.spawn_unit_group(true, true)
|
||||
end
|
||||
|
||||
if param == 'set_next_wave' then
|
||||
for _ = 1, 100 do
|
||||
Public.set_next_wave()
|
||||
end
|
||||
return Public.spawn_unit_group(true, true)
|
||||
end
|
||||
|
||||
if param == 'log_all' then
|
||||
return Public.toggle_debug()
|
||||
end
|
||||
|
||||
if param == 'debug_health' then
|
||||
local this = Public.get()
|
||||
|
||||
Public.toggle_debug_health()
|
||||
|
||||
this.next_wave = 1000
|
||||
this.wave_interval = 200
|
||||
this.wave_enforced = true
|
||||
this.debug_only_on_wave_500 = true
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
||||
|
@ -118,7 +118,7 @@ local function remove_trees(entity)
|
||||
local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}
|
||||
local trees = surface.find_entities_filtered {area = area, type = 'tree'}
|
||||
if #trees > 0 then
|
||||
for i, tree in pairs(trees) do
|
||||
for _, tree in pairs(trees) do
|
||||
if tree and tree.valid then
|
||||
tree.destroy()
|
||||
end
|
||||
@ -136,7 +136,7 @@ local function remove_rocks(entity)
|
||||
local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}
|
||||
local rocks = surface.find_entities_filtered {area = area, type = 'simple-entity'}
|
||||
if #rocks > 0 then
|
||||
for i, rock in pairs(rocks) do
|
||||
for _, rock in pairs(rocks) do
|
||||
if rock and rock.valid then
|
||||
rock.destroy()
|
||||
end
|
||||
@ -1113,10 +1113,10 @@ Event.on_nth_tick(
|
||||
local t2 = tick % 18000
|
||||
|
||||
if tick_tasks[t] then
|
||||
tick_tasks[t](true)
|
||||
tick_tasks[t]()
|
||||
end
|
||||
if tick_tasks[t2] then
|
||||
tick_tasks[t2](true)
|
||||
tick_tasks[t2]()
|
||||
end
|
||||
|
||||
local resolve_pathing = Public.get('resolve_pathing')
|
||||
@ -1163,4 +1163,6 @@ Event.on_nth_tick(
|
||||
end
|
||||
)
|
||||
|
||||
Public.set_next_wave = set_next_wave
|
||||
|
||||
return Public
|
||||
|
@ -109,7 +109,7 @@ local function place_nest_near_unit_group()
|
||||
Task.set_timeout_in_ticks(200, immunity_spawner, {entity = spawner})
|
||||
|
||||
if boss then
|
||||
BiterHealthBooster.add_boss_unit(spawner, modified_boss_unit_health.current_value)
|
||||
BiterHealthBooster.add_boss_unit(spawner, modified_boss_unit_health.current_value, 0.5)
|
||||
else
|
||||
BiterHealthBooster.add_unit(spawner, modified_unit_health.current_value)
|
||||
end
|
||||
@ -206,7 +206,7 @@ function Public.build_worm()
|
||||
local modified_boss_unit_health = Public.get('modified_boss_unit_health')
|
||||
|
||||
if boss then
|
||||
BiterHealthBooster.add_boss_unit(u, modified_boss_unit_health.current_value)
|
||||
BiterHealthBooster.add_boss_unit(u, modified_boss_unit_health.current_value, 0.5)
|
||||
else
|
||||
local final_health = round(modified_unit_health.current_value * worm_unit_settings.scale_units_by_health[worm], 3)
|
||||
if final_health < 1 then
|
||||
|
Loading…
x
Reference in New Issue
Block a user