Class DiceRoll
The DiceRoll owns a set of Dice that can be rolled for result.
Inheritance
Inherited Members
Namespace: osrlib.Dice
Assembly: osrlib.Core.dll
Syntax
public class DiceRoll
Remarks
Add dice to the DiceRoll as a DiceHand, then get the roll result by calling RollDice().
Examples
Roll 1d20 using the DiceRoll object
DiceHand hand = new DiceHand(1, DieType.d20);
DiceRoll roll = new DiceRoll(hand);
int toHitRoll = roll.RollDice();
Roll 3d6 using the static method
int strengthScore = DiceRoll.RollDice(new DiceHand(3, DieType.d6))
Roll 1d20 + 3 using the static method
int strengthScore = DiceRoll.RollDice(new DiceHand(1, DieType.d20), 3)
Constructors
| Improve this Doc View SourceDiceRoll(DiceHand)
Creates a new instance of a DiceRoll, adding the specified dice to the DiceRoll's Dice collection.
Declaration
public DiceRoll(DiceHand diceHand)
Parameters
Type | Name | Description |
---|---|---|
DiceHand | diceHand | The DiceHand specifying the Dice to add to the DiceRoll. |
Properties
| Improve this Doc View SourceBaseRoll
Gets the last roll result without any ModifierTotal.
Declaration
public int BaseRoll { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Dice
Gets the Dice collection for the DiceRoll.
Declaration
public List<Die> Dice { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<Die> |
LastRoll
Gets the result of the last time RollDice() was called. This value includes all modifiers applied to the roll.
Declaration
public int LastRoll { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ModifierTotal
Gets the sum of all modifiers applied to the roll with AddModifier(Int32). The RollDice() method adds this value to the BaseRoll to obtain its result.
Declaration
public int ModifierTotal { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAddDice(DiceHand)
Adds the Dice represented by the specified DiceHand to the DiceRoll's Dice collection.
Declaration
public void AddDice(DiceHand diceHand)
Parameters
Type | Name | Description |
---|---|---|
DiceHand | diceHand | The DiceHand specifying the number and type (number of sides) of Die that should be added to the DiceRoll's Dice collection. |
AddDice(List<Die>)
Adds the Die contained in the specified Dice collection to this DiceRoll's Dice collection.
Declaration
public void AddDice(List<Die> dice)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<Die> | dice | Collection Die objects to add to the DiceRoll's Dice collection. |
AddDie(Die)
Adds the specified Die to this DiceRoll's Dice collection.
Declaration
public void AddDie(Die die)
Parameters
Type | Name | Description |
---|---|---|
Die | die | The Dice.Die to add to the DiceRoll's Dice collection. |
AddModifier(Int32)
Adds the specified modifier to the DiceRoll. The value can be negative.
Declaration
public void AddModifier(int modifier)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | modifier | A value that will modify the DiceRoll. |
ClearDice()
Removes all Dice from the DiceRoll.
Declaration
public void ClearDice()
ClearModifiers()
Removes all Modifiers from the DiceRoll.
Declaration
public void ClearModifiers()
RemoveDie(Die)
Removes the specified Die from this DiceRoll's Dice collection,if it exists in the collection.
Declaration
public void RemoveDie(Die die)
Parameters
Type | Name | Description |
---|---|---|
Die | die | The Dice.Die to remove from the DiceRoll's Dice collection. |
RollDice()
Declaration
public int RollDice()
Returns
Type | Description |
---|---|
System.Int32 | The sum of the result of a roll of each Die in this DiceRoll's Dice collection. |
RollDice(DiceHand, Int32)
Rolls the dice in the specified DiceHand and returns the roll - the sum of each rolled die and the modifier, if specified.
Declaration
public static int RollDice(DiceHand diceHand, int modifier = 0)
Parameters
Type | Name | Description |
---|---|---|
DiceHand | diceHand | The handful of dice to roll. |
System.Int32 | modifier | The modifer value to apply to the roll. |
Returns
Type | Description |
---|---|
System.Int32 | The resultant DiceRoll (a DiceRoll with its RollDice() method having been called). |
ToString()
Returns the string representation of the latest roll of this DiceRoll in the format 'N (NdN +/- N)'. For example: "16 (1d20 + 2)".
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | String representation of the roll. |
Overrides
Events
| Improve this Doc View SourceDiceRolled
Event raised immediately after RollDice() is called.
Declaration
public event DiceRolledEventHandler DiceRolled
Event Type
Type | Description |
---|---|
DiceRolledEventHandler |