Dice class
Dice can have sides, an amount and modifiers.
You may also use one of the rolling convenience methods.
For more information about rolls and their results see DiceRoll
and DiceRollResult
classes.
You can multiply dice of the same sides together, which will return the amount of dice doubled between each other. This also works for division, addition and subtraction. Sides and modifiers are not affected by this, and the leftmost operant is always the one that is used.
Constructors
- Dice({required int amount, required int sides, int? modifierValue, String? modifierStat, String? modifierSign})
- Dice.fromJson(String json)
-
factory
- Dice.fromRawJson(String str)
-
factory
Properties
- amount → int
-
The amount of dice to roll. In a 2d6 roll, this would be 2.
final
- debugProperties → String
-
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasModifier → bool
-
Whether or not this dice has a modifier.
no setter
- modifier → String
-
The modifier name. In a 2d6+DEX roll, this would be DEX.
no setter
- modifierSign → String
-
The modifier sign. In a 2d6+3 roll, this would be +. In a 2d6-3 roll, this would be -.
final
- modifierStat → String?
-
The modifier stat. In a 2d6+DEX roll, this would be DEX.
final
- modifierValue → int?
-
The modifier value. In a 2d6+3 roll, this would be 3.
final
- modifierWithSign → String
-
The modifier with the sign. In a 2d6+3 roll, this would be +3. In a 2d6-3 roll, this would be -3.
no setter
- needsModifier → bool
-
Whether or not this dice needs a modifier to be rolled - if it has a modifier stat but no value.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sides → int
-
The amount of sides on the dice. In a 2d6 roll, this would be 6.
final
Methods
-
copyWith(
{int? amount, int? sides, int? modifierValue, String? modifierSign, String? modifierStat}) → Dice -
If you want to change the modifier value, use copyWithModifierValue instead.
Otherwise, use
copyWith
to change the modifier sign, as this class is immutable, and the sign is determined by the modifier value. -
copyWithModifierValue(
int statValue) → Dice - Creates a copy of this dice with the modifier value set to the given stat value. The sign is updated using this operation, so use it instead of copyWith if you want to use a stat.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
roll(
) → DiceRoll - Rolls the dice and returns the result, a random number between 1 and the amount of sides. It is returned with the dice that was rolled in a DiceRoll object, which also contains the results of the individual dice.
-
toJson(
) → String -
toRawJson(
) → String -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator *(
int amount) → dynamic -
operator +(
int amount) → dynamic -
operator -(
int amount) → dynamic -
operator /(
int amount) → dynamic -
operator ==(
Object? other) → bool -
The equality operator.
override
Static Properties
Static Methods
-
flatten(
List< Dice> dice) → List<Dice> - Flattens a list of dice into a list of dice with the amount set to 1, each dice roll separated into its own dice.
-
guessFromString(
String str) → List< Dice> -
Parses a string for dice rolls and returns a list of dice found.
The string must be in the format of
XdY
where X is the amount of dice and Y is the amount of sides, optionally followed by a modifier in the format of+Z
or-Z
where Z is the modifier value.