com.planet_ink.coffee_mud.Libraries
Class Dice

java.lang.Object
  extended by com.planet_ink.coffee_mud.Libraries.StdLibrary
      extended by com.planet_ink.coffee_mud.Libraries.Dice
All Implemented Interfaces:
CMObject, Tickable, CMLibrary, DiceLibrary, java.lang.Cloneable, java.lang.Comparable<CMObject>

public class Dice
extends StdLibrary
implements DiceLibrary


Field Summary
protected  CMath.CompiledFormula baseNpcHitpointsFormula
           
 
Fields inherited from class com.planet_ink.coffee_mud.Libraries.StdLibrary
isDebugging, name, serviceClient, tickStatus
 
Fields inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
STATUS_AFFECT, STATUS_ALIVE, STATUS_BEHAVIOR, STATUS_CLASS, STATUS_DEAD, STATUS_END, STATUS_FIGHT, STATUS_MISC, STATUS_MISC2, STATUS_MISC3, STATUS_MISC4, STATUS_MISC5, STATUS_MISC6, STATUS_MISC7, STATUS_NOT, STATUS_OTHER, STATUS_RACE, STATUS_REBIRTH, STATUS_SCRIPT, STATUS_START, STATUS_WEATHER, TICKID_AREA, TICKID_BEAMWEAPON, TICKID_CLAN, TICKID_CLANITEM, TICKID_DEADBODY_DECAY, TICKID_ELECTRONICS, TICKID_EMAIL, TICKID_EXIT_BEHAVIOR, TICKID_EXIT_REOPEN, TICKID_ITEM_BEHAVIOR, TICKID_ITEM_BOUNCEBACK, TICKID_LIGHT_FLICKERS, TICKID_LIVEAUCTION, TICKID_LONGERMASK, TICKID_MISCELLANEOUS, TICKID_MOB, TICKID_PROPERTY_SPECIAL, TICKID_QUEST, TICKID_READYTOSTOP, TICKID_ROOM_BEHAVIOR, TICKID_ROOM_ITEM_REJUV, TICKID_SOLITARYMASK, TICKID_SPECIALCOMBAT, TICKID_SPECIALMANEUVER, TICKID_SPELL_AFFECT, TICKID_SUPPORT, TICKID_TIMEAUCTION, TICKID_TRAP_DESTRUCTION, TICKID_TRAP_RESET
 
Constructor Summary
Dice()
           
 
Method Summary
 boolean activate()
          Activates the library.
 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.
 java.lang.String ID()
          The CoffeeMud Java Class ID shared by all instances of this object.
 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)
 void propertiesLoaded()
          This method is called whenever system properties are altered by the user.
 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 class com.planet_ink.coffee_mud.Libraries.StdLibrary
checkDatabase, compareTo, copyOf, getServiceClient, getTickStatus, initializeClass, L, name, newInstance, setThreadStatus, shutdown, tick
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.planet_ink.coffee_mud.Libraries.interfaces.CMLibrary
getServiceClient, L, shutdown
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.CMObject
copyOf, initializeClass, name, newInstance
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

baseNpcHitpointsFormula

protected CMath.CompiledFormula baseNpcHitpointsFormula
Constructor Detail

Dice

public Dice()
Method Detail

ID

public java.lang.String ID()
Description copied from interface: CMObject
The CoffeeMud Java Class ID shared by all instances of this object. Unlike the Java Class name, this method does not include package information. However, it must return a String value unique to its class category in the ClassLoader. Class categories include Libraries, Common, Areas, Abilities, Behaviors, CharClasses, Commands, Exits Locales, MOBS, Races, WebMacros, Basic Items, Armor, Weapons, ClanItems, Tech. The name is typically identical to the class name.

Specified by:
ID in interface CMObject
Overrides:
ID in class StdLibrary
Returns:
the name of this class

getRandomizer

public java.util.Random getRandomizer()
Description copied from interface: DiceLibrary
Returns the seeded randomizer used by this lib.

Specified by:
getRandomizer in interface DiceLibrary
Returns:
the randomizer

activate

public boolean activate()
Description copied from interface: CMLibrary
Activates the library. This is called after the mud is booted, but before connections are accepted.

Specified by:
activate in interface CMLibrary
Overrides:
activate in class StdLibrary
Returns:
true if activation was successful, false if you're screwed
See Also:
CMLibrary.shutdown()

propertiesLoaded

public void propertiesLoaded()
Description copied from interface: CMLibrary
This method is called whenever system properties are altered by the user. This allows the library to react to any important properties they monitor.

Specified by:
propertiesLoaded in interface CMLibrary
Overrides:
propertiesLoaded in class StdLibrary

normalizeAndRollLess

public boolean normalizeAndRollLess(int score)
Description copied from interface: DiceLibrary
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

Specified by:
normalizeAndRollLess in interface DiceLibrary
Parameters:
score - the number from 0-100
Returns:
true if you rolled under the score

normalizeBy5

public int normalizeBy5(int score)
Description copied from interface: DiceLibrary
Takes a score from 0-100, normalizes it to between 5 and 95.

Specified by:
normalizeBy5 in interface DiceLibrary
Parameters:
score - the number from 0-100
Returns:
the number from 5-95

rollHP

public int rollHP(int level,
                  int code)
Description copied from interface: DiceLibrary
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.

Specified by:
rollHP in interface DiceLibrary
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:
DiceLibrary.getHPCode(String), DiceLibrary.getHPCode(int, int, int), DiceLibrary.getHPBreakup(int, int)

scramble

public void scramble(java.util.List<?> objs)
Description copied from interface: DiceLibrary
Randomizes the contents of the list.

Specified by:
scramble in interface DiceLibrary
Parameters:
objs - the list to scramble
See Also:
DiceLibrary.scramble(int[])

scramble

public void scramble(int[] objs)
Description copied from interface: DiceLibrary
Randomizes the contents of the set

Specified by:
scramble in interface DiceLibrary
Parameters:
objs - the set to randomize
See Also:
DiceLibrary.scramble(List)

plusOrMinus

public long plusOrMinus(long range)
Description copied from interface: DiceLibrary
Returns a long from -(range-1) to (range-1)

Specified by:
plusOrMinus in interface DiceLibrary
Parameters:
range - the range of the random long
Returns:
the random long
See Also:
DiceLibrary.plusOrMinus(int)

plusOrMinus

public int plusOrMinus(int range)
Description copied from interface: DiceLibrary
Returns an int from -(range-1) to (range-1)

Specified by:
plusOrMinus in interface DiceLibrary
Parameters:
range - the range of the random int
Returns:
the random int
See Also:
DiceLibrary.plusOrMinus(long)

plusOrMinus

public double plusOrMinus(double range)
Description copied from interface: DiceLibrary
Returns a double from -(range) to (range)

Specified by:
plusOrMinus in interface DiceLibrary
Parameters:
range - the range of the random double
Returns:
the random double
See Also:
DiceLibrary.plusOrMinus(long)

plusOrMinus

public float plusOrMinus(float range)
Description copied from interface: DiceLibrary
Returns a float from -(range) to (range)

Specified by:
plusOrMinus in interface DiceLibrary
Parameters:
range - the range of the random float
Returns:
the random float
See Also:
DiceLibrary.plusOrMinus(long)

rollInRange

public int rollInRange(int min,
                       int max)
Description copied from interface: DiceLibrary
Returns a random number within the given min and max range.

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

rollInRange

public long rollInRange(long min,
                        long max)
Description copied from interface: DiceLibrary
Returns a random number within the given min and max range.

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

doublePick

public java.lang.Object doublePick(java.lang.Object[][] set)
Description copied from interface: DiceLibrary
Selects and returns one of the objects from the one of the object lists in the set.

Specified by:
doublePick in interface DiceLibrary
Parameters:
set - the sets to choose from
Returns:
an object from the sets
See Also:
DiceLibrary.pick(Object[], Object), DiceLibrary.pick(Object[]), DiceLibrary.pick(int[]), DiceLibrary.pick(List), DiceLibrary.pick(int[], int)

pick

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

Specified by:
pick in interface DiceLibrary
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:
DiceLibrary.pick(Object[]), DiceLibrary.pick(int[]), DiceLibrary.pick(List), DiceLibrary.pick(int[], int), DiceLibrary.doublePick(Object[][])

pick

public java.lang.Object pick(java.lang.Object[] set)
Description copied from interface: DiceLibrary
Selects and returns one of the objects from the set.

Specified by:
pick in interface DiceLibrary
Parameters:
set - the set to choose from
Returns:
an object from the set
See Also:
DiceLibrary.pick(Object[], Object), DiceLibrary.pick(int[]), DiceLibrary.pick(List), DiceLibrary.pick(int[], int), DiceLibrary.doublePick(Object[][])

pick

public int pick(int[] set,
                int not)
Description copied from interface: DiceLibrary
Selects and returns one of the ints from the set, except for the "not" one given

Specified by:
pick in interface DiceLibrary
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:
DiceLibrary.pick(Object[]), DiceLibrary.pick(Object[], Object), DiceLibrary.pick(int[]), DiceLibrary.pick(List), DiceLibrary.doublePick(Object[][])

rollNormalDistribution

public int rollNormalDistribution(int number,
                                  int die,
                                  int modifier)
Description copied from interface: DiceLibrary
Rolls dice to generate a random number, but in a way that ensures a more balanced distribution.

Specified by:
rollNormalDistribution in interface DiceLibrary
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:
DiceLibrary.roll(int, int, int), DiceLibrary.rollLowBiased(int, int, int), DiceLibrary.rollInRange(int, int), DiceLibrary.rollInRange(long, long)

rollLowBiased

public int rollLowBiased(int number,
                         int die,
                         int modifier)
Description copied from interface: DiceLibrary
Rolls dice to generate a random number, but in a way that biases the lower numbers.

Specified by:
rollLowBiased in interface DiceLibrary
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:
DiceLibrary.roll(int, int, int), DiceLibrary.rollNormalDistribution(int, int, int), DiceLibrary.rollInRange(int, int), DiceLibrary.rollInRange(long, long)

pick

public int pick(int[] set)
Description copied from interface: DiceLibrary
Selects and returns one of the ints from the set.

Specified by:
pick in interface DiceLibrary
Parameters:
set - the set to choose from
Returns:
an int from the set
See Also:
DiceLibrary.pick(Object[], Object), DiceLibrary.pick(Object[]), DiceLibrary.pick(List), DiceLibrary.pick(int[], int), DiceLibrary.doublePick(Object[][])

pick

public java.lang.Object pick(java.util.List<? extends java.lang.Object> set)
Description copied from interface: DiceLibrary
Selects and returns one of the objects from the list.

Specified by:
pick in interface DiceLibrary
Parameters:
set - the list to choose from
Returns:
an object from the list
See Also:
DiceLibrary.pick(Object[], Object), DiceLibrary.pick(Object[]), DiceLibrary.pick(int[]), DiceLibrary.pick(int[], int), DiceLibrary.doublePick(Object[][])

getHPCode

public int getHPCode(java.lang.String str)
Description copied from interface: DiceLibrary
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.

Specified by:
getHPCode in interface DiceLibrary
Parameters:
str - the string to evaluate
Returns:
the encoded hit points bitmap
See Also:
DiceLibrary.getHPCode(int, int, int), DiceLibrary.rollHP(int, int), DiceLibrary.getHPBreakup(int, int)

getHPCode

public int getHPCode(int roll,
                     int dice,
                     int plus)
Description copied from interface: DiceLibrary
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.

Specified by:
getHPCode in interface DiceLibrary
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:
DiceLibrary.getHPCode(String), DiceLibrary.rollHP(int, int), DiceLibrary.getHPBreakup(int, int)

getHPBreakup

public int[] getHPBreakup(int level,
                          int code)
Description copied from interface: DiceLibrary
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.

Specified by:
getHPBreakup in interface DiceLibrary
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:
DiceLibrary.getHPCode(String), DiceLibrary.getHPCode(int, int, int), DiceLibrary.rollHP(int, int)

roll

public int roll(int number,
                int die,
                int modifier)
Description copied from interface: DiceLibrary
The great workhorse that rolls dice. It will roll a die-sided die number times, and then add modifier.

Specified by:
roll in interface DiceLibrary
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:
DiceLibrary.rollNormalDistribution(int, int, int), DiceLibrary.rollLowBiased(int, int, int), DiceLibrary.rollInRange(long, long), DiceLibrary.rollInRange(int, int)

rollPercentage

public int rollPercentage()
Description copied from interface: DiceLibrary
Returns a random number from 1-100

Specified by:
rollPercentage in interface DiceLibrary
Returns:
the random percent number