25 lines
1.0 KiB
GDScript
25 lines
1.0 KiB
GDScript
class_name HealthRegeneration
|
|
extends RefCounted
|
|
|
|
const ENDURANCE_DIVISOR := 3
|
|
const SKILL_AMPLIFIER := 0.15
|
|
const DIFFICULTY_MULTIPLIERS := {
|
|
&"touriste": 1.5,
|
|
&"crawler": 1.0,
|
|
&"veteran": 0.75,
|
|
&"masochiste": 0.5,
|
|
}
|
|
|
|
static func amount(endurance: int, regeneration_skill: int = 1, perk_bonus: int = 0, difficulty_id: StringName = &"crawler") -> int:
|
|
var base := maxi(1, endurance / ENDURANCE_DIVISOR)
|
|
var skill_bonus := maxi(0, regeneration_skill - 1)
|
|
var total := float(base + maxi(0, perk_bonus)) * (1.0 + float(skill_bonus) * SKILL_AMPLIFIER)
|
|
return maxi(0, int(total * float(DIFFICULTY_MULTIPLIERS.get(difficulty_id, 1.0))))
|
|
|
|
static func apply(actor: ActorState, endurance: int, regeneration_skill: int = 1, perk_bonus: int = 0, difficulty_id: StringName = &"crawler") -> int:
|
|
if actor == null or not actor.is_alive():
|
|
return 0
|
|
var before := actor.hit_points
|
|
actor.hit_points = mini(actor.effective_max_hit_points(), actor.hit_points + amount(endurance, regeneration_skill, perk_bonus, difficulty_id))
|
|
return actor.hit_points - before
|