Hit point rules.
Applies damage and healing to a hit point pool, accounting for temporary hit
points and clamping to the range 0..max_hp. Each operation reports an outcome
describing the transition, such as dropping to 0 or dying outright.
Summary
Functions
Apply damage. Temporary hit points absorb it first and current hit points floor at 0. Damage that leaves the pool at 0 with an excess of at least the maximum is instant death.
Apply healing, up to the maximum. Temporary hit points are unaffected.
Build a hit point pool.
Types
@type outcome() :: :ok | :downed | :hit_while_down | :dead | :recovered
The outcome of the most recent operation on a hit point pool:
:ok- hit points remain above 0:downed- damage dropped the pool from above 0 to 0:hit_while_down- damage was taken while already at 0:dead- instant death, when the damage past 0 is at least the maximum:recovered- healing brought the pool from 0 back above 0
@type t() :: %Srd.Rules.Hitpoints{ hp: non_neg_integer(), max_hp: pos_integer(), outcome: outcome() | nil, temp_hp: non_neg_integer() }
A hit point pool:
Functions
@spec damage(t(), non_neg_integer()) :: t()
Apply damage. Temporary hit points absorb it first and current hit points floor at 0. Damage that leaves the pool at 0 with an excess of at least the maximum is instant death.
@spec heal(t(), non_neg_integer()) :: t()
Apply healing, up to the maximum. Temporary hit points are unaffected.
@spec new(non_neg_integer(), pos_integer(), non_neg_integer()) :: t()
Build a hit point pool.