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

41 lines
1.1 KiB
Lua
Raw Normal View History

2019-04-14 21:14:08 +02:00
-- biters and their buildings gain pseudo hp increase through the means of evasion mechanics -- by mewmew
-- use global.biter_evasion_health_increase_factor to modify their health
2021-03-24 21:14:55 +02:00
local Event = require 'utils.event'
2019-04-14 21:14:08 +02:00
local random_max = 1000000
local types = {
2021-03-24 17:46:00 +02:00
['unit'] = true,
['unit-spawner'] = true,
['turret'] = true
2019-04-14 21:14:08 +02:00
}
2021-03-24 17:46:00 +02:00
local function get_evade_chance()
return random_max - (random_max / global.biter_evasion_health_increase_factor)
2019-04-14 21:14:08 +02:00
end
local function on_entity_damaged(event)
2021-03-24 17:46:00 +02:00
if global.biter_evasion_health_increase_factor == 1 then
return
end
if not event.entity.valid then
return
end
if not types[event.entity.type] then
return
end
if event.final_damage_amount > event.entity.prototype.max_health * global.biter_evasion_health_increase_factor then
return
end
if math.random(1, random_max) > get_evade_chance() then
return
end
event.entity.health = event.entity.health + event.final_damage_amount
2019-04-14 21:14:08 +02:00
end
local function on_init()
2021-03-24 17:46:00 +02:00
global.biter_evasion_health_increase_factor = 1
2019-04-14 21:14:08 +02:00
end
2021-03-24 21:14:55 +02:00
Event.on_init(on_init)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)