Class Dice.Rule
java.lang.Object
com.github.yellowstonegames.core.Dice.Rule
- All Implemented Interfaces:
Externalizable, Serializable
- Enclosing class:
Dice
A rule for how to roll a particular set of dice and operations to perform on them, such as "3d6+4" to roll three
6-sided dice and add 4 to the result. You can generate a Rule once (such as by using the constructor,
Rule(String), or Dice.parseRollRule(String)) and roll it potentially many times using
Dice.runRollRule(Rule). This avoids overhead from repeated parsing.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptioncom.github.tommyettinger.ds.IntList -
Constructor Summary
ConstructorsConstructorDescriptionRule()Stores the givenrollCodeas-is, and parses instructions usingDice.parseRollRule(String). -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()voidThe object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.reset()Resets this Rule to be empty, with "" as its rollCode and empty instructions.Resets this Rule to store the givenrollCodeas-is, and parses instructions usingDice.parseRollRuleInto(Rule, String).toString()Returns a string representation of the rollCode.voidThe object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
-
Field Details
-
rollCode
-
instructions
public com.github.tommyettinger.ds.IntList instructions
-
-
Constructor Details
-
Rule
public Rule() -
Rule
Stores the givenrollCodeas-is, and parses instructions usingDice.parseRollRule(String). See the Dice method for more info.- Parameters:
rollCode- a dice string using the notation described inDice.parseRollRule(String)
-
-
Method Details
-
reset
Resets this Rule to be empty, with "" as its rollCode and empty instructions.- Returns:
- this, for chaining
-
reset
Resets this Rule to store the givenrollCodeas-is, and parses instructions usingDice.parseRollRuleInto(Rule, String). See the Dice method for more info.- Parameters:
rollCode- a dice string using the notation described inDice.parseRollRuleInto(Rule, String)- Returns:
- this, for chaining
-
toString
-
equals
-
hashCode
-
writeExternal
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- the stream to write the object to- Throws:
IOException- Includes any I/O exceptions that may occur
-
readExternal
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.- Specified by:
readExternalin interfaceExternalizable- Parameters:
in- the stream to read data from in order to restore the object- Throws:
IOException- if I/O errors occurClassNotFoundException- If the class for an object being restored cannot be found.
-