1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00
ComfyFactorio/maps/fish_defender_v2/explosive_gun_bullets.lua

50 lines
1.8 KiB
Lua
Raw Normal View History

2021-11-26 13:48:49 +01:00
local Public = require 'maps.fish_defender_v2.table'
2020-07-12 20:54:44 +02:00
local radius = 3
2021-11-26 13:48:49 +01:00
local random = math.random
local floor = math.floor
local sqrt = math.sqrt
2020-07-12 20:54:44 +02:00
local function splash_damage(surface, position, final_damage_amount)
2021-11-26 13:48:49 +01:00
local damage = random(floor(final_damage_amount * 3), floor(final_damage_amount * 4))
2021-03-24 16:46:00 +01:00
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - radius, position.y - radius}, {position.x + radius, position.y + radius}}})) do
2020-07-12 20:54:44 +02:00
if e.valid and e.health then
2021-11-26 13:48:49 +01:00
local distance_from_center = sqrt((e.position.x - position.x) ^ 2 + (e.position.y - position.y) ^ 2)
2020-07-12 20:54:44 +02:00
if distance_from_center <= radius then
local damage_distance_modifier = 1 - distance_from_center / radius
if damage > 0 then
2021-11-26 13:48:49 +01:00
if random(1, 3) == 1 then
2020-07-12 20:54:44 +02:00
surface.create_entity({name = 'explosion', position = e.position})
end
e.damage(damage * damage_distance_modifier, 'player', 'explosion')
end
end
end
end
end
2021-11-26 13:48:49 +01:00
function Public.explosive_bullets(event)
if random(1, 3) ~= 1 then
2020-07-12 20:54:44 +02:00
return false
end
2021-11-26 13:48:49 +01:00
local damage_type = event.damage_type
if damage_type.name ~= 'physical' then
2020-07-12 20:54:44 +02:00
return false
end
2021-11-26 13:48:49 +01:00
local cause = event.cause
local entity = event.entity
if cause.shooting_state.state == defines.shooting.not_shooting then
2020-07-12 20:54:44 +02:00
return false
end
2021-11-26 13:48:49 +01:00
local selected_weapon = cause.get_inventory(defines.inventory.character_guns)[cause.selected_gun_index]
2020-07-12 20:54:44 +02:00
if selected_weapon.name ~= 'submachine-gun' and selected_weapon.name ~= 'pistol' then
return false
end
2021-11-26 13:48:49 +01:00
cause.surface.create_entity({name = 'explosion', position = entity.position})
2020-07-12 20:54:44 +02:00
2021-11-26 13:48:49 +01:00
splash_damage(cause.surface, entity.position, event.final_damage_amount)
2020-07-12 20:54:44 +02:00
end
2021-11-26 13:48:49 +01:00
return Public