Documentation ¶
Overview ¶
Package diceroller generates either a sum or DiceRollResults out of RollArgs or DiceRolls. It's just that simple so get rolling!
Index ¶
- func DiceRollResultsSum(results ...DiceRollResult) (sum int)
- func ParseRollArgs(rollArgs ...string) (rollingExpressions []rollingExpression, errors []error)
- func PerformRollArgsAndSum(rollArgs ...string) int
- func PerformRollsAndSum(diceRolls ...DiceRoll) int
- func RollingExpressionResultSum(results ...RollingExpressionResult) (sum int)
- type DiceRoll
- type DiceRollResult
- type RollingExpressionResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiceRollResultsSum ¶
func DiceRollResultsSum(results ...DiceRollResult) (sum int)
Returns the total sum of a DiceRollResult array.
func ParseRollArgs ¶
Parses a RollArg array. Returns a DiceRoll array for valid RollArgs, an error array for invalid ones.
A valid RollArg matches either the DiceRoll format or a rollAttribute string.
DiceRoll format: [X]dY[+|-]Z. In other words XdY or dY followed by + or - Z. Valid DiceRoll examples: "5d6", "d20", "4d4+1", "10d10", "1d6-1", "1D8".
RollArgs will be converted into DiceRolls and grouped together in rolling expressions. A new rolling expression starts when a rollAttribute is parsed after a sequence of DiceRolls.
For example:
- 5d6 1d6 10d10 would return one rolling expression containing all three RollArgs as DiceRolls.
- adv d20+5 half spell 8d8 would return two rolling expressions: "adv 1d20+5" and "half spell 8d8".
- 5d6 roll 4d6 roll 3d6 would return three rolling expressions: "5d6", "4d6" and "3d6".
rollAttribute string list:
- roll, hit, dmg : separators, starts a new rolling expressions
DnD rollAttribute string list:
- crit: Critical, doubles all dice ammount
- spell: Spell, DiceRollResults.String() prints the sum and the sum halved for saves
- half: Halves the sums, for resistances and such
- adv: Advantage, rolls each dice twice and drops the lowest
- dis: Disadvantage, rolls each dice twice and drops the highest
- drophigh: Drop High, drops the highest result of a DiceRoll
- droplow: Drop Low, drops the lowest result of a DiceRoll
func PerformRollArgsAndSum ¶ added in v0.2.1
Straightforward rolling using RollArgs. Returns the sum, invalid RollArgs are worth 0.
func PerformRollsAndSum ¶ added in v0.1.2
Performs an array of DiceRoll. Returns the sum, invalid DiceRolls are worth 0.
func RollingExpressionResultSum ¶ added in v1.1.0
func RollingExpressionResultSum(results ...RollingExpressionResult) (sum int)
Sums multiple RollingExpressionResult.
Types ¶
type DiceRoll ¶
type DiceRoll struct { DiceAmmount int // Ammount of dice to be rolled DiceSize int // Size, or number of faces, of the dice to be rolled Modifier int // Value to be applied to the sum of rolled dices Plus bool // Determines if the result of the roll is to be added or substracted Attribs attributes // Contains rollAttributes affecting the rolls }
A DiceRoll represents a dice rolling expression, such as 1d6 or 2d8+1.
func NewDiceRoll ¶
DiceRoll constructor, validates values.
func NewDiceRollWithAttribs ¶ added in v1.1.0
func NewDiceRollWithAttribs(diceAmmount int, diceSize int, modifier int, plus bool, attribs attributes) (*DiceRoll, error)
DiceRoll constructor with rollAttributes, validates values.
type DiceRollResult ¶
type DiceRollResult struct { Dice []int // Individual dice roll result Sum int // Sum of Dice AdvDisDropped []int // Dropped advantage/disadvantage dice HighDropped []int // Dropped high dice LowDropped []int // Dropped low dice // contains filtered or unexported fields }
A DiceRollResult contains the results of performing a DiceRoll
func PerformRolls ¶
func PerformRolls(diceRolls ...DiceRoll) (results []DiceRollResult, diceErrs []error)
Performs an array of DiceRoll. Returns a DiceRollResult array for valid DiceRolls and an error array for invalid ones.
func (DiceRollResult) String ¶
func (result DiceRollResult) String() string
Human readable DiceRollResult string.
type RollingExpressionResult ¶ added in v1.1.0
type RollingExpressionResult struct { Results []DiceRollResult Sum int }
Results of performing a rollingExpression.
func PerformRollArgs ¶ added in v0.2.1
func PerformRollArgs(rollArgs ...string) ([]RollingExpressionResult, []error)
Performs an array of RollArgs. Returns a DiceRollResult array for valid RollArgs and an error array for invalid ones.
func (RollingExpressionResult) String ¶ added in v1.1.0
func (rollExpr RollingExpressionResult) String() string
Formatted result output.