A Dice Roller Package based on elm/random that allows you to build customizable dice rolling functions in a readable way.
Represents a Die or pool of dice. Most common dice are built in, but you can also create your own.
-- A 5 sided die.
d5 =
DX 5
-- A custom die
customDie =
CustomDie "EvenRoller" [ 2, 2, 2, 2, 4, 4, 4, 6, 6, 8 ]
-- A weighted die. Effectively the same as the customDie above.
weightedDie =
WeightedDie "EvenRoller"
[ ( 4, 2 )
, ( 3, 4 )
, ( 2, 6 )
, ( 1, 8 )
]
-- A Constant Value
always4 =
Constant "Four" 4Represents the results of a roll.
--possible result of `roll 1 D6`:
{ descripion = "1D6"
, value = 4
, children = Empty
}
--possible result of `roll 2 D6`:
{ description = "3D6"
, value = 8
, children =
RollResults
[ { description = "1D6", value = 3, children = Empty }
, { description = "1D6", value = 5, children = Empty }
]
}represents the children of a RollResult.
Recalculates the value of a RollResult by dropping the lowest value of its children. If the RollResult had no children (because it was the result of a single die roll or constant value), Then dropLowest will set the value to zero.
statGenerator =
roll 4 D6 |> dropLowestRecalculates the value of a RollResult by counting the number of children that pass the test.
roll 3 D10
|> countSuccessesIf (\r -> r > 7)"explodes" a RollResult. An exploding die will keep rolling as long as it satisfies the predicate. For instance, if you roll a 10 on the following D10, you will roll again and add the rolls together. If your reroll is another D10, you repeat this process.
--defines a ten sided die that "explodes" on a 10.
explodingDie =
roll 1 D10
|> andThen ExplodeIf ((==) 10)Currently, all dice are limited to 100 explosions.
Rerolls a RollResult if it satisfies the given predicate. The value of one roll will be kept using the Keep rules specified.
-- rerolls any ones or twos, keeping the new result even if lower.
roll 2 D6
|> andThen RerollIf (\r -> r < 2) Newused to apply transformations to RollResult generators.
Represents how we decide when choosing between multiple die results. see RerollIf
combine the results of two rolls. The value of the resulting roll will be the sum of the values of those two rolls.
d6PlusD4 =
roll 1 D6
|> plus (roll 1 D4)
--one possible result:
{ description = "1D6 + 1D4"
, value = 8
, children =
RollResults
[ { description = "1D6", value = 6, children = Empty }
, { description = "1D4", value = 2, children = Empty }
]
}Converts a Random.Generator Int into a Random.Generator RollResult.
make a Random.Generator for a roll of n dice.