1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/modules/railgun_enhancer.lua

96 lines
4.2 KiB
Lua
Raw Normal View History

2018-12-19 16:59:31 +02:00
-- improves the damage of the railgun and adds visual effects -- by mewmew
2018-12-20 08:08:36 +02:00
-- laser turret research will increase it´s damage even further --
2018-12-19 16:59:31 +02:00
local event = require 'utils.event'
2018-12-20 08:08:36 +02:00
local damage_min = 400
local damage_max = 800
2018-12-19 16:59:31 +02:00
local math_random = math.random
local additional_visual_effects = true
local do_splash_damage = true
local biological_target_types = {
["unit"] = true,
["player"] = true,
["turret"] = true,
["unit-spawner"] = true
}
local function create_visuals(source_entity, target_entity)
2018-12-20 08:08:36 +02:00
if not additional_visual_effects then return end
local surface = target_entity.surface
surface.create_entity({name = "water-splash", position = target_entity.position})
if biological_target_types[target_entity.type] then
surface.create_entity({name = "blood-explosion-big", position = target_entity.position})
for x = -8, 8, 1 do
for y = -8, 8, 1 do
if math_random(1, 16) == 1 then
surface.create_entity({name = "blood-fountain", position = {target_entity.position.x + (x * 0.1), target_entity.position.y + (y * 0.1)}})
surface.create_entity({name = "blood-fountain-big", position = {target_entity.position.x + (x * 0.1), target_entity.position.y + (y * 0.1)}})
2018-12-19 16:59:31 +02:00
end
end
2018-12-20 08:08:36 +02:00
end
else
if math_random(1, 3) ~= 1 then
surface.create_entity({name = "fire-flame", position = target_entity.position})
end
for x = -3, 3, 1 do
for y = -3, 3, 1 do
if math_random(1, 3) == 1 then
surface.create_trivial_smoke({name="smoke-fast", position={target_entity.position.x + (x * 0.35), target_entity.position.y + (y * 0.35)}})
end
if math_random(1, 5) == 1 then
surface.create_trivial_smoke({name="train-smoke", position={target_entity.position.x + (x * 0.35), target_entity.position.y + (y * 0.35)}})
2018-12-19 16:59:31 +02:00
end
end
2018-12-20 08:08:36 +02:00
end
end
2018-12-19 16:59:31 +02:00
end
2018-12-20 08:08:36 +02:00
local function do_splash_damage_around_entity(source_entity, player)
2018-12-19 16:59:31 +02:00
if not do_splash_damage then return end
2018-12-20 08:08:36 +02:00
local research_damage_bonus = player.force.get_ammo_damage_modifier("laser-turret") + 1
local research_splash_radius_bonus = player.force.get_ammo_damage_modifier("laser-turret") * 0.5
local splash_area = {
{source_entity.position.x - (2.5 + research_splash_radius_bonus), source_entity.position.y - (2.5 + research_splash_radius_bonus)},
{source_entity.position.x + (2.5 + research_splash_radius_bonus), source_entity.position.y + (2.5 + research_splash_radius_bonus)}
}
local entities = source_entity.surface.find_entities_filtered({area = splash_area})
2018-12-19 16:59:31 +02:00
for _, entity in pairs(entities) do
2018-12-20 08:08:36 +02:00
if entity.health and entity ~= source_entity and entity ~= player then
2018-12-19 17:26:29 +02:00
if additional_visual_effects then
local surface = entity.surface
surface.create_entity({name = "railgun-beam", position = source_entity.position, source = source_entity.position, target = entity.position})
surface.create_entity({name = "water-splash", position = entity.position})
if biological_target_types[entity.type] then
surface.create_entity({name = "blood-fountain", position = entity.position})
end
2018-12-20 08:08:36 +02:00
end
2018-12-23 10:46:10 +02:00
local damage = math_random(math.ceil((damage_min * research_damage_bonus) / 16), math.ceil((damage_max * research_damage_bonus) / 16))
2018-12-20 08:08:36 +02:00
entity.damage(damage, player.force, "physical")
2018-12-19 16:59:31 +02:00
end
end
end
local function on_entity_damaged(event)
if not event.cause then return end
if event.cause.name ~= "player" then return end
if event.damage_type.name ~= "physical" then return end
if event.original_damage_amount ~= 100 then return end
local player = event.cause
if player.shooting_state.state == defines.shooting.not_shooting then return end
local selected_weapon = player.get_inventory(defines.inventory.character_guns)[player.selected_gun_index]
2018-12-19 16:59:31 +02:00
if selected_weapon.name ~= "railgun" then return end
create_visuals(event.cause, event.entity)
2018-12-19 17:26:29 +02:00
2018-12-20 08:08:36 +02:00
do_splash_damage_around_entity(event.entity, player)
2018-12-19 16:59:31 +02:00
event.entity.health = event.entity.health + event.final_damage_amount
2018-12-20 08:08:36 +02:00
local research_damage_bonus = player.force.get_ammo_damage_modifier("laser-turret") + 1
local damage = math_random(math.ceil(damage_min * research_damage_bonus), math.ceil(damage_max * research_damage_bonus))
event.entity.damage(damage, player.force, "physical")
2018-12-19 16:59:31 +02:00
end
event.add(defines.events.on_entity_damaged, on_entity_damaged)