Packages

Pure-Elixir tabletop RPG game support and rules modeled on the System Reference Document (SRD) 5.2 with opt-in support for some 5.1 rules.

Current section

Files

Jump to
srd_5e lib srd rules check.ex
Raw

lib/srd/rules/check.ex

defmodule Srd.Rules.Check do
@moduledoc """
Ability check rules
"""
alias Srd.Dice.Roll
alias Srd.Rules.D20
defstruct [:success?, :natural, :total, :dc, :margin]
@typedoc """
The result of an ability check: whether it met the DC, plus the values behind
the outcome. A check is a d20 test against a difficulty class, with no critical
semantics.
"""
@type t :: %__MODULE__{
success?: boolean(),
natural: 1..20,
total: integer(),
dc: integer(),
margin: integer()
}
@doc """
Resolve an ability check against a difficulty class
"""
@spec resolve(Roll.t(), dc: integer()) :: t()
def resolve(%Roll{} = roll, dc: dc) do
t = D20.test(roll, dc)
%__MODULE__{
success?: t.success?,
natural: t.natural,
total: t.total,
dc: dc,
margin: t.margin
}
end
end