View Source Rollex.Dice.Operations (Rollex v0.8.0)

Support for operations that can be applied to dice rolls including:

  • odd only (o)
  • even oly (e)
  • keep high (kh#, k#)
  • keep low (kl#)
  • drop high (dh#)
  • drop low (dl#)
  • less than (<#)
  • greater than (>#)
  • equal to (=#, =[#, #, #..], =[#..#])
  • reroll lower than (r<#)
  • reroll higher than (r>#)
  • reroll equal to (r=#, r=[#, #, #..], r=[#..#])
  • explode (!)

Link to this section Summary

Functions

Applies an operation returned by parse/1 to a list of numbers representing dice rolls

Parse operations from a provided string

Link to this section Types

@type operable_token() :: %{
  :operation => operation(),
  :sides => non_neg_integer(),
  required(atom()) => any()
}
@type operation() :: operation_type() | {operation_type(), params :: term()}
@type operation_type() ::
  :drop_bottom
  | :drop_top
  | :greater_than
  | :less_than
  | :match
  | :match_list
  | nil
  | :reroll_higher
  | :reroll_lower
  | :reroll_match
  | :reroll_match_list
  | :take_bottom
  | :take_even
  | :take_odd
  | :take_top

Link to this section Functions

@spec apply(token :: operable_token(), rolls :: [integer()]) ::
  {valid :: [integer()], rejected :: [integer()]}

Applies an operation returned by parse/1 to a list of numbers representing dice rolls

@spec parse(definition :: String.t()) ::
  {operation(), num_chars_consumed :: non_neg_integer()}
  | {:error, reason :: String.t()}

Parse operations from a provided string