mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-28 03:57:22 +02:00
Merge pull request #2 from Gerkiz/utils-traps-update
utils - traps fixed and added optional force parameter
This commit is contained in:
commit
a8c343042d
@ -3,6 +3,7 @@
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local FT = require 'utils.functions.flying_texts'
|
||||
|
||||
local traps = {}
|
||||
|
||||
@ -26,6 +27,11 @@ local kaboom_weights = {
|
||||
{name = 'explosive-cannon-projectile', chance = 5}
|
||||
}
|
||||
|
||||
local colors = {
|
||||
trap = {r = 0.75, g = 0.75, b = 0.75},
|
||||
sentries = {r = 0.8, g = 0.0, b = 0.0},
|
||||
}
|
||||
|
||||
local kabooms = {}
|
||||
for _, t in pairs(kaboom_weights) do
|
||||
for _ = 1, t.chance, 1 do
|
||||
@ -37,36 +43,27 @@ local function create_flying_text(surface, position, text)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = position,
|
||||
text = text,
|
||||
color = {r = 0.75, g = 0.75, b = 0.75}
|
||||
}
|
||||
)
|
||||
FT.flying_text(nil, surface, position, text, colors.trap)
|
||||
if text == '...' then
|
||||
return
|
||||
end
|
||||
surface.play_sound({path = 'utility/armor_insert', position = position, volume_modifier = 0.75})
|
||||
end
|
||||
|
||||
local function create_kaboom(surface, position, name)
|
||||
---Creates actual final effect
|
||||
---@param surface LuaSurface
|
||||
---@param position MapPosition
|
||||
---@param name EntityID
|
||||
---@param force LuaForce
|
||||
local function create_kaboom(surface, position, name, force)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
local target = position
|
||||
local speed = 0.5
|
||||
if name == 'defender-capsule' or name == 'destroyer-capsule' or name == 'distractor-capsule' then
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = position,
|
||||
text = '(((Sentries Engaging Target)))',
|
||||
color = {r = 0.8, g = 0.0, b = 0.0}
|
||||
}
|
||||
)
|
||||
local nearest_player_unit = surface.find_nearest_enemy({position = position, max_distance = 128, force = 'enemy'})
|
||||
FT.flying_text(nil, surface, position, '(((Sentries Engaging Target)))', colors.sentries)
|
||||
local nearest_player_unit = surface.find_nearest_enemy({position = position, max_distance = 128, force = force})
|
||||
if nearest_player_unit then
|
||||
target = nearest_player_unit.position
|
||||
end
|
||||
@ -76,14 +73,18 @@ local function create_kaboom(surface, position, name)
|
||||
{
|
||||
name = name,
|
||||
position = position,
|
||||
force = 'enemy',
|
||||
force = force,
|
||||
target = target,
|
||||
speed = speed
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local function tick_tack_trap(surface, position)
|
||||
---Create Tick Tack Trap
|
||||
---@param surface LuaSurface
|
||||
---@param position MapPosition
|
||||
---@param force LuaForce|nil #optional, if nil, uses enemy force
|
||||
local function tick_tack_trap(surface, position, force)
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
@ -99,6 +100,9 @@ local function tick_tack_trap(surface, position)
|
||||
if not position.y then
|
||||
return
|
||||
end
|
||||
if not force or not force.valid then
|
||||
force = game.forces.enemy
|
||||
end
|
||||
local tick_tack_count = math.random(5, 9)
|
||||
for t = 60, tick_tack_count * 60, 60 do
|
||||
local tick = game.tick - (game.tick % 10) + t
|
||||
@ -120,7 +124,7 @@ local function tick_tack_trap(surface, position)
|
||||
else
|
||||
traps[tick][#traps[tick] + 1] = {
|
||||
callback = 'create_kaboom',
|
||||
params = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)]}
|
||||
params = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)], force}
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -135,7 +139,7 @@ local function on_tick()
|
||||
local callback = token.callback
|
||||
local params = token.params
|
||||
if callback == 'create_kaboom' then
|
||||
create_kaboom(params[1], params[2], params[3])
|
||||
create_kaboom(params[1], params[2], params[3], params[4])
|
||||
elseif callback == 'create_flying_text' then
|
||||
create_flying_text(params[1], params[2], params[3])
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ local function create_particles(surface, position, amount)
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_biter(surface, position, evolution)
|
||||
local function spawn_biter(surface, position, evolution, force)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
@ -69,13 +69,19 @@ local function spawn_biter(surface, position, evolution)
|
||||
if not p then
|
||||
return
|
||||
end
|
||||
surface.create_entity({name = biter_name, position = p, force = 'enemy'})
|
||||
surface.create_entity({name = biter_name, position = p, force = force})
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function unearthing_biters(surface, position, amount, relative_evolution)
|
||||
---Creates unearthing biters
|
||||
---@param surface LuaSurface
|
||||
---@param position MapPosition
|
||||
---@param amount number
|
||||
---@param relative_evolution number|nil #if supplied, overwrites the evolution_factor of this force
|
||||
---@param force LuaForce|nil #optional, if nil, uses enemy force
|
||||
local function unearthing_biters(surface, position, amount, relative_evolution, force)
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
@ -91,8 +97,11 @@ local function unearthing_biters(surface, position, amount, relative_evolution)
|
||||
if not position.y then
|
||||
return
|
||||
end
|
||||
if not force or not force.valid then
|
||||
force = game.forces.enemy
|
||||
end
|
||||
|
||||
local evolution = game.forces.enemy.get_evolution_factor(surface)
|
||||
local evolution = force.get_evolution_factor(surface)
|
||||
|
||||
if relative_evolution then
|
||||
evolution = relative_evolution
|
||||
@ -115,7 +124,7 @@ local function unearthing_biters(surface, position, amount, relative_evolution)
|
||||
if t % 40 == 36 then
|
||||
traps[tick][#traps[tick] + 1] = {
|
||||
callback = 'spawn_biter',
|
||||
params = {surface, {x = position.x, y = position.y}, evolution, relative_evolution}
|
||||
params = {surface, {x = position.x, y = position.y}, evolution, force}
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -132,7 +141,7 @@ local function on_tick()
|
||||
if callback == 'create_particles' then
|
||||
create_particles(params[1], params[2], params[3])
|
||||
elseif callback == 'spawn_biter' then
|
||||
spawn_biter(params[1], params[2], params[3])
|
||||
spawn_biter(params[1], params[2], params[3], params[4])
|
||||
end
|
||||
end
|
||||
traps[game.tick] = nil
|
||||
|
@ -35,7 +35,7 @@ local function create_particles(surface, position, amount)
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_worm(surface, position, evolution_index)
|
||||
local function spawn_worm(surface, position, evolution_index, force)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
@ -123,10 +123,15 @@ local function spawn_worm(surface, position, evolution_index)
|
||||
}
|
||||
local raffle = worm_raffle_table[evolution_index]
|
||||
local worm_name = raffle[math.random(1, #raffle)]
|
||||
surface.create_entity({name = worm_name, position = position})
|
||||
surface.create_entity({name = worm_name, position = position, force = force})
|
||||
end
|
||||
|
||||
local function unearthing_worm(surface, position, relative_evolution)
|
||||
---Creates unearthing worms
|
||||
---@param surface LuaSurface
|
||||
---@param position MapPosition
|
||||
---@param relative_evolution number|nil #if supplied, overwrites the evolution_factor of this force
|
||||
---@param force LuaForce|nil #optional, if nil, uses enemy force
|
||||
local function unearthing_worm(surface, position, relative_evolution, force)
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
@ -142,7 +147,10 @@ local function unearthing_worm(surface, position, relative_evolution)
|
||||
if not position.y then
|
||||
return
|
||||
end
|
||||
local evolution_index = math.ceil(game.forces.enemy.get_evolution_factor(surface) * 10)
|
||||
if not force or not force.valid then
|
||||
force = game.forces.enemy
|
||||
end
|
||||
local evolution_index = math.ceil(force.get_evolution_factor(surface) * 10)
|
||||
|
||||
if relative_evolution then
|
||||
evolution_index = math.ceil(relative_evolution * 10)
|
||||
@ -165,7 +173,7 @@ local function unearthing_worm(surface, position, relative_evolution)
|
||||
if t == 340 then
|
||||
traps[tick][#traps[tick] + 1] = {
|
||||
callback = 'spawn_worm',
|
||||
params = {surface, {x = position.x, y = position.y}, evolution_index}
|
||||
params = {surface, {x = position.x, y = position.y}, evolution_index, force}
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -181,7 +189,7 @@ local function on_tick()
|
||||
if callback == 'create_particles' then
|
||||
create_particles(params[1], params[2], params[3])
|
||||
elseif callback == 'spawn_worm' then
|
||||
spawn_worm(params[1], params[2], params[3])
|
||||
spawn_worm(params[1], params[2], params[3], params[4])
|
||||
end
|
||||
end
|
||||
traps[game.tick] = nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user