1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-28 23:06:38 +02:00
ComfyFactorio/maps/mountain_fortress_v3/traps.lua

140 lines
4.0 KiB
Lua
Raw Normal View History

2020-06-05 18:01:32 +02:00
local Event = require 'utils.event'
local WPT = require 'maps.mountain_fortress_v3.table'
2020-08-09 20:22:33 +02:00
local random = math.random
2020-08-26 12:09:06 +02:00
local tick_tacks = {'*tick*', '*tick*', '*tack*', '*tak*', '*tik*', '*tok*', 'OOF'}
2020-06-05 18:01:32 +02:00
local kaboom_weights = {
{name = 'grenade', chance = 7},
{name = 'cluster-grenade', chance = 1},
{name = 'destroyer-capsule', chance = 1},
{name = 'defender-capsule', chance = 4},
{name = 'distractor-capsule', chance = 2},
{name = 'poison-capsule', chance = 2},
{name = 'explosive-uranium-cannon-projectile', chance = 3},
{name = 'explosive-cannon-projectile', chance = 5}
}
local kabooms = {}
for _, t in pairs(kaboom_weights) do
2020-06-25 17:59:16 +02:00
for _ = 1, t.chance, 1 do
kabooms[#kabooms + 1] = t.name
2020-06-05 18:01:32 +02:00
end
end
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}
}
)
surface.play_sound({path = 'utility/armor_insert', position = position, volume_modifier = 0.75})
end
local function create_kaboom(surface, position, name)
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'})
if nearest_player_unit then
target = nearest_player_unit.position
end
speed = 0.001
end
surface.create_entity(
{
name = name,
position = position,
force = 'enemy',
target = target,
speed = speed
}
)
end
local function tick_tack_trap(surface, position)
if not surface then
return
end
if not surface.valid then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local traps = WPT.get('traps')
2020-08-09 20:22:33 +02:00
local tick_tack_count = random(5, 9)
2020-06-05 18:01:32 +02:00
for t = 60, tick_tack_count * 60, 60 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
end
if t < tick_tack_count * 60 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_flying_text',
2020-08-09 20:22:33 +02:00
params = {surface, {x = position.x, y = position.y}, tick_tacks[random(1, #tick_tacks)]}
2020-06-05 18:01:32 +02:00
}
else
2020-08-09 20:22:33 +02:00
if random(1, 10) == 1 then
2020-06-05 18:01:32 +02:00
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, '( ͡° ͜ʖ ͡°)'}
}
else
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_kaboom',
2020-08-09 20:22:33 +02:00
params = {surface, {x = position.x, y = position.y}, kabooms[random(1, #kabooms)]}
2020-06-05 18:01:32 +02:00
}
end
end
end
end
local function on_tick()
local traps = WPT.get('traps')
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'create_kaboom' then
create_kaboom(params[1], params[2], params[3])
elseif callback == 'create_flying_text' then
create_flying_text(params[1], params[2], params[3])
end
end
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
return tick_tack_trap