1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/modules/explosive_biters.lua

42 lines
1.4 KiB
Lua
Raw Normal View History

2018-12-31 02:55:18 +02:00
-- biters explode -- by mewmew
local event = require 'utils.event'
local biter_values = {
2019-02-20 12:43:29 +02:00
["medium-biter"] = {"blood-explosion-big", 20, 1.5},
["big-biter"] = {"blood-explosion-huge", 40, 2},
["behemoth-biter"] = {"blood-explosion-huge", 60, 2.5}
2018-12-31 02:55:18 +02:00
}
local function damage_entities_in_radius(surface, position, radius, damage)
local entities_to_damage = surface.find_entities_filtered({area = {{position.x - radius, position.y - radius},{position.x + radius, position.y + radius}}})
for _, entity in pairs(entities_to_damage) do
if entity.health and entity.name ~= "land-mine" then
if entity.force.name ~= "enemy" then
if entity.name == "character" then
2018-12-31 02:55:18 +02:00
entity.damage(damage, "enemy")
else
2019-02-20 12:43:29 +02:00
entity.health = entity.health - damage
2018-12-31 02:55:18 +02:00
if entity.health <= 0 then entity.die("enemy") end
end
end
end
end
end
2019-02-09 12:42:02 +02:00
local function on_entity_died(event)
if not event.entity.valid then return end
2018-12-31 02:55:18 +02:00
if biter_values[event.entity.name] then
local entity = event.entity
entity.surface.create_entity({name = biter_values[entity.name][1], position = entity.position})
2019-02-20 12:43:29 +02:00
damage_entities_in_radius(
entity.surface,
entity.position,
biter_values[entity.name][3],
math.random(math.ceil(biter_values[entity.name][2] * 0.75), math.ceil(biter_values[entity.name][2] * 1.25))
)
2018-12-31 02:55:18 +02:00
end
end
event.add(defines.events.on_entity_died, on_entity_died)