com.planet_ink.coffee_mud.Libraries.interfaces
Interface DiceLibrary

All Superinterfaces:
java.lang.Cloneable, CMLibrary, CMObject, java.lang.Comparable<CMObject>
All Known Implementing Classes:
Dice

public interface DiceLibrary
extends CMLibrary

The Dice library governs random numbers in various ranges, various hit point generation algorithms, and selecting objects from various lists at random.


Method Summary
 java.lang.Object doublePick(java.lang.Object[][] set)
          Selects and returns one of the objects from the one of the object lists in the set.
 int[] getHPBreakup(int level, int code)
          Generates the die roll parts for an encoded hit point bitmap when the code is > 32768, or according to another formula otherwise.
 int getHPCode(int roll, int dice, int plus)
          This function generates an encoded 32 bit bitmap to represent a die roll for a mob hitpoints.
 int getHPCode(java.lang.String str)
          This function takes a friendly-ish hit point die roll formula and generates a bitmap that can be given to the rollHP method.
 java.util.Random getRandomizer()
          Returns the seeded randomizer used by this lib.
 boolean normalizeAndRollLess(int score)
          Takes a score from 0-100, normalizes it to between 5 and 95, and then rolls a random number between 0 and 100.
 int normalizeBy5(int score)
          Takes a score from 0-100, normalizes it to between 5 and 95.
 int pick(int[] set)
          Selects and returns one of the ints from the set.
 int pick(int[] set, int not)
          Selects and returns one of the ints from the set, except for the "not" one given
 java.lang.Object pick(java.util.List<? extends java.lang.Object> set)
          Selects and returns one of the objects from the list.
 java.lang.Object pick(java.lang.Object[] set)
          Selects and returns one of the objects from the set.
 java.lang.Object pick(java.lang.Object[] set, java.lang.Object not)
          Selects and returns one of the objects from the set, except for the "not" one given
 double plusOrMinus(double range)
          Returns a double from -(range) to (range)
 float plusOrMinus(float range)
          Returns a float from -(range) to (range)
 int plusOrMinus(int range)
          Returns an int from -(range-1) to (range-1)
 long plusOrMinus(long range)
          Returns a long from -(range-1) to (range-1)
 int roll(int number, int die, int modifier)
          The great workhorse that rolls dice.
 int rollHP(int level, int code)
          Generates hit points for an NPC based on bizarre rules.
 int rollInRange(int min, int max)
          Returns a random number within the given min and max range.
 long rollInRange(long min, long max)
          Returns a random number within the given min and max range.
 int rollLowBiased(int number, int die, int modifier)
          Rolls dice to generate a random number, but in a way that biases the lower numbers.
 int rollNormalDistribution(int number, int die, int modifier)
          Rolls dice to generate a random number, but in a way that ensures a more balanced distribution.
 int rollPercentage()
          Returns a random number from 1-100
 void scramble(int[] objs)
          Randomizes the contents of the set
 void scramble(java.util.List<?> objs)
          Randomizes the contents of the list.
 
Methods inherited from interface com.planet_ink.coffee_mud.Libraries.interfaces.CMLibrary
activate, getServiceClient, L, propertiesLoaded, shutdown
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.CMObject
copyOf, ID, initializeClass, name, newInstance
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Method Detail

normalizeAndRollLess

boolean normalizeAndRollLess(int score)
Takes a score from 0-100, normalizes it to between 5 and 95, and then rolls a random number between 0 and 100. If the random number is below the normalized score, it returns true, otherwise false

Parameters:
score - the number from 0-100
Returns:
true if you rolled under the score

normalizeBy5

int normalizeBy5(int score)
Takes a score from 0-100, normalizes it to between 5 and 95.

Parameters:
score - the number from 0-100
Returns:
the number from 5-95

rollHP

int rollHP(int level,
           int code)
Generates hit points for an NPC based on bizarre rules. If the code given is > 32768, then the bits above 23 are number of roles, bits 15-23 are the die type, and low bits added. The level is not used at all. If the code is < 32768, then the level is used in the basic npc formula from the properties. The code is then the die-base for the formula.

Parameters:
level - the level of the npc
code - the die type, or a bitmap
Returns:
the hit points to give to the npc
See Also:
getHPCode(String), getHPCode(int, int, int), getHPBreakup(int, int)

getHPCode

int getHPCode(java.lang.String str)
This function takes a friendly-ish hit point die roll formula and generates a bitmap that can be given to the rollHP method. The bits above 23 are number of roles, bits 15-23 are the die type, and low bits added. The dice roll formula type is, for example 4d6+2 which means to roll a six sided die 4 times and then add 2.

Parameters:
str - the string to evaluate
Returns:
the encoded hit points bitmap
See Also:
getHPCode(int, int, int), rollHP(int, int), getHPBreakup(int, int)

getHPCode

int getHPCode(int roll,
              int dice,
              int plus)
This function generates an encoded 32 bit bitmap to represent a die roll for a mob hitpoints. The bits above 23 are number of roles, bits 15-23 are the die type, and low bits added.

Parameters:
roll - the number of die rolls
dice - the sides on the die
plus - the amount to add to the result
Returns:
the encoded hit points bitmap
See Also:
getHPCode(String), rollHP(int, int), getHPBreakup(int, int)

getHPBreakup

int[] getHPBreakup(int level,
                   int code)
Generates the die roll parts for an encoded hit point bitmap when the code is > 32768, or according to another formula otherwise. The 3 parts of the result are: [0] the number of rolls [1] the sides of the die [2] an amount to add to the total If the code given is > 32768, then the bits above 23 are number of roles, bits 15-23 are the die type, and low bits added. The level is not used at all. If the code is < 32768, then the level is the number of rolls, the code is the sides of the die, and the add is level * level * 0.85.

Parameters:
level - the level of the npc
code - the die type, or a bitmap
Returns:
the hit points to give to the npc
See Also:
getHPCode(String), getHPCode(int, int, int), rollHP(int, int)

pick

java.lang.Object pick(java.lang.Object[] set,
                      java.lang.Object not)
Selects and returns one of the objects from the set, except for the "not" one given

Parameters:
set - the set to choose from
not - null, or a member to not select
Returns:
an object from the set, except not
See Also:
pick(Object[]), pick(int[]), pick(List), pick(int[], int), doublePick(Object[][])

pick

java.lang.Object pick(java.lang.Object[] set)
Selects and returns one of the objects from the set.

Parameters:
set - the set to choose from
Returns:
an object from the set
See Also:
pick(Object[], Object), pick(int[]), pick(List), pick(int[], int), doublePick(Object[][])

pick

int pick(int[] set,
         int not)
Selects and returns one of the ints from the set, except for the "not" one given

Parameters:
set - the set to choose from
not - null, or a member to not select
Returns:
an int from the set, except not
See Also:
pick(Object[]), pick(Object[], Object), pick(int[]), pick(List), doublePick(Object[][])

pick

int pick(int[] set)
Selects and returns one of the ints from the set.

Parameters:
set - the set to choose from
Returns:
an int from the set
See Also:
pick(Object[], Object), pick(Object[]), pick(List), pick(int[], int), doublePick(Object[][])

pick

java.lang.Object pick(java.util.List<? extends java.lang.Object> set)
Selects and returns one of the objects from the list.

Parameters:
set - the list to choose from
Returns:
an object from the list
See Also:
pick(Object[], Object), pick(Object[]), pick(int[]), pick(int[], int), doublePick(Object[][])

doublePick

java.lang.Object doublePick(java.lang.Object[][] set)
Selects and returns one of the objects from the one of the object lists in the set.

Parameters:
set - the sets to choose from
Returns:
an object from the sets
See Also:
pick(Object[], Object), pick(Object[]), pick(int[]), pick(List), pick(int[], int)

rollPercentage

int rollPercentage()
Returns a random number from 1-100

Returns:
the random percent number

roll

int roll(int number,
         int die,
         int modifier)
The great workhorse that rolls dice. It will roll a die-sided die number times, and then add modifier.

Parameters:
number - the number of times to roll
die - the sides of the die
modifier - the amount to add
Returns:
the randomly rolled result
See Also:
rollNormalDistribution(int, int, int), rollLowBiased(int, int, int), rollInRange(long, long), rollInRange(int, int)

rollInRange

int rollInRange(int min,
                int max)
Returns a random number within the given min and max range.

Parameters:
min - the minimum of the range
max - the maximum of the range
Returns:
a number in the range
See Also:
rollInRange(long, long), roll(int, int, int), rollLowBiased(int, int, int), rollNormalDistribution(int, int, int)

rollInRange

long rollInRange(long min,
                 long max)
Returns a random number within the given min and max range.

Parameters:
min - the minimum of the range
max - the maximum of the range
Returns:
a number in the range
See Also:
rollInRange(int, int), roll(int, int, int), rollLowBiased(int, int, int), rollNormalDistribution(int, int, int)

rollNormalDistribution

int rollNormalDistribution(int number,
                           int die,
                           int modifier)
Rolls dice to generate a random number, but in a way that ensures a more balanced distribution.

Parameters:
number - the number of times to roll
die - the sides of the die
modifier - the amount to add
Returns:
the randomly rolled result
See Also:
roll(int, int, int), rollLowBiased(int, int, int), rollInRange(int, int), rollInRange(long, long)

rollLowBiased

int rollLowBiased(int number,
                  int die,
                  int modifier)
Rolls dice to generate a random number, but in a way that biases the lower numbers.

Parameters:
number - the number of times to roll
die - the sides of the die
modifier - the amount to add
Returns:
the randomly rolled result
See Also:
roll(int, int, int), rollNormalDistribution(int, int, int), rollInRange(int, int), rollInRange(long, long)

getRandomizer

java.util.Random getRandomizer()
Returns the seeded randomizer used by this lib.

Returns:
the randomizer

plusOrMinus

long plusOrMinus(long range)
Returns a long from -(range-1) to (range-1)

Parameters:
range - the range of the random long
Returns:
the random long
See Also:
plusOrMinus(int)

plusOrMinus

int plusOrMinus(int range)
Returns an int from -(range-1) to (range-1)

Parameters:
range - the range of the random int
Returns:
the random int
See Also:
plusOrMinus(long)

plusOrMinus

double plusOrMinus(double range)
Returns a double from -(range) to (range)

Parameters:
range - the range of the random double
Returns:
the random double
See Also:
plusOrMinus(long)

plusOrMinus

float plusOrMinus(float range)
Returns a float from -(range) to (range)

Parameters:
range - the range of the random float
Returns:
the random float
See Also:
plusOrMinus(long)

scramble

void scramble(java.util.List<?> objs)
Randomizes the contents of the list.

Parameters:
objs - the list to scramble
See Also:
scramble(int[])

scramble

void scramble(int[] objs)
Randomizes the contents of the set

Parameters:
objs - the set to randomize
See Also:
scramble(List)