A simple C# library for simulating dice rolls
$ dotnet add package BB_RPG_DiceSetBB_RPG_DiceSet empowers you to integrate comprehensive dice rolling mechanics into your tabletop RPG (TTRPG) development projects. It offers a user-friendly and versatile API for rolling various dice types, applying modifiers, and combining rolls for dynamic gameplay experiences.
The dice rolls results are determined using a cryptographic random function and the dice distribution has been tested to be uniform within 0.25% in 100 Million Rolls, guaranteeing dice rolls to be sufficiently random but also fair in distribution.
You can install BB_RPG_DiceSet dsirectly from Visual Studio following these steps:
Or you can install it via NuGet Package Manager Console:
nuget install BB_RPG_DiceSet
Here are listed the latest versions with the description of their most prominent features, see the Changelog for more details
To get started, create an instance of the Die, DiceSet, or DiceSetTray class by providing a description of the die, dice set or dice tray.
The description for the Dice set follows the classic notation format <number_of_dice>d<sides>+<bonus>.
After initializing, you can use the Roll() method to get the total result or RollSeparate() to get individual results.
In case of a DiceSetTray you can also call the method RollTray() and get a result for each element of the tray.
Here's an example demonstrating how to use the library to simulate different dice rolls:
using BB_RPG_DiceSet;
public class Example
{
public static void Main(string[] args)
{
Die die = new D20(); // Create a classic d20 die object
int result = die.Roll(); // Roll the die
Console.WriteLine("Result: {0}", result);
}
}
using BB_RPG_DiceSet;
public class Example
{
public static void Main(string[] args)
{
Die die = new Die(32); // Create a custom d32 die object
int result = die.Roll(); // Roll the die
Console.WriteLine("Result: {0}", result);
}
}
using BB_RPG_DiceSet;
public class Example
{
public static void Main(string[] args)
{
int result = new DiceSet("3d10+5").Roll(); // Roll 3d10 with a +5 modifier
Console.WriteLine("Result: {0}", result);
}
}
using BB_RPG_DiceSet;
// Simulate a dice tray, for example a special damage with multiple dice types and a bonus
// Create the dice tray
DiceSetTray tray = new DiceSetTray();
// add a new d6
tray.Add(new Die(6));
// add a new set of 3 ten-sided dice plus a penalty of 4
tray.Add(new DiceSet("3d10-4");
// add a separate bonus
tray.Add(new Bonus(15));
// roll the entire tray for a total number
int result = tray.Roll();
Console.WriteLine($"Dice Set Result: {result}");
// roll the dice tray for dice result and bonus result separeately
DiceResult setresult = tray.RollSeparate();
Console.WriteLine($"Separated Results: Base = {setresult.Base}, Bonus = {setresult.Bonus}");
// roll every element present in the tray separately and obtain
// a list of separate results (die and bonus) for each element
List<DiceResult> resultList = tray.RollTray();
foreach (DiceResult item in resultList)
{
Console.WriteLine($"Tray item Results: Base = {item .Base}, Bonus = {item .Bonus}");
}
Feel free to contribute to the development of BB_RPG_DiceSet. If you encounter any issues or have suggestions for improvement, please open an issue or submit a pull request.
BB_RPG_DiceSet is licensed under the MIT License.