Class Dice.Rule

java.lang.Object
com.github.yellowstonegames.core.Dice.Rule
All Implemented Interfaces:
Externalizable, Serializable
Enclosing class:
Dice

public static class Dice.Rule extends Object implements Externalizable
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 Details

    • rollCode

      public String rollCode
    • instructions

      public com.github.tommyettinger.ds.IntList instructions
  • Constructor Details

  • Method Details

    • reset

      public Dice.Rule reset()
      Resets this Rule to be empty, with "" as its rollCode and empty instructions.
      Returns:
      this, for chaining
    • reset

      public Dice.Rule reset(String rollCode)
      Resets this Rule to store the given rollCode as-is, and parses instructions using Dice.parseRollRuleInto(Rule, String). See the Dice method for more info.
      Parameters:
      rollCode - a dice string using the notation described in Dice.parseRollRuleInto(Rule, String)
      Returns:
      this, for chaining
    • toString

      public String toString()
      Returns a string representation of the rollCode.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the rollCode.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      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:
      writeExternal in interface Externalizable
      Parameters:
      out - the stream to write the object to
      Throws:
      IOException - Includes any I/O exceptions that may occur
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      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:
      readExternal in interface Externalizable
      Parameters:
      in - the stream to read data from in order to restore the object
      Throws:
      IOException - if I/O errors occur
      ClassNotFoundException - If the class for an object being restored cannot be found.