• Home
  • API reference
  • Source code
Show / Hide Table of Contents
  • osrlib.Controllers
    • GameManager
  • osrlib.Core
    • Ability
    • AbilityType
    • Adventure
    • Alignment
    • Being
    • BeingTargetingEventArgs
    • BeingTargetingEventHandler
    • CharacterClass
    • Dungeon
    • Encounter
    • GameAction
    • GameActionEventArgs
    • GameActionEventHandler
    • GamePosition
    • Modifier
    • Party
    • Quest
    • User
    • Weapon
    • WeaponType
  • osrlib.Dice
    • DiceHand
    • DiceRoll
    • DiceRolledEventArgs
    • DiceRolledEventHandler
    • Die
  • osrlib.SaveLoad
    • SaveLoadLocal
    • SaveType
  • osrlib.Tests
    • CoreRulesTests
    • DiceTests
    • PartyGenerator
    • ReadMeTests
    • SaveLoadTests
    • SteppedBattleTests
  • osrlib.Utility
    • Randomizer

Class DiceRoll

The DiceRoll owns a set of Dice that can be rolled for result.

Inheritance
System.Object
DiceRoll
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
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 Source

DiceRoll(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 Source

BaseRoll

Gets the last roll result without any ModifierTotal.

Declaration
public int BaseRoll { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Dice

Gets the Dice collection for the DiceRoll.

Declaration
public List<Die> Dice { get; }
Property Value
Type Description
System.Collections.Generic.List<Die>
| Improve this Doc View Source

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
| Improve this Doc View Source

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 Source

AddDice(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ClearDice()

Removes all Dice from the DiceRoll.

Declaration
public void ClearDice()
| Improve this Doc View Source

ClearModifiers()

Removes all Modifiers from the DiceRoll.

Declaration
public void ClearModifiers()
| Improve this Doc View Source

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.

| Improve this Doc View Source

RollDice()

Rolls each Die in this DiceRolls's Dice collection and returns the aggregate.

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.

| Improve this Doc View Source

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).

| Improve this Doc View Source

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
System.Object.ToString()

Events

| Improve this Doc View Source

DiceRolled

Event raised immediately after RollDice() is called.

Declaration
public event DiceRolledEventHandler DiceRolled
Event Type
Type Description
DiceRolledEventHandler
  • Improve this Doc
  • View Source
Back to top Generated by DocFX