Srd.Rules.Hitpoints (srd_5e v0.2.0)

Copy Markdown View Source

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

Types

The outcome of the most recent operation on a hit point pool

t()

A hit point pool

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

outcome()

@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

t()

@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:

  • :hp - current hit points (0..max_hp)
  • :max_hp - the hit point maximum
  • :temp_hp - temporary hit points, a separate buffer that absorbs damage first
  • :outcome - the result of the most recent damage/2 or heal/2, or nil

Functions

damage(pool, amount)

@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.

heal(pool, amount)

@spec heal(t(), non_neg_integer()) :: t()

Apply healing, up to the maximum. Temporary hit points are unaffected.

new(hp, max_hp, temp_hp \\ 0)

@spec new(non_neg_integer(), pos_integer(), non_neg_integer()) :: t()

Build a hit point pool.