|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.lib.classes.random.RandomList
Parses a treasure/monster list.
Treasure and monster lists are a way to parameterize random generators. The list format is one object per line, with comments beginning with "#" and blank lines OK.
The format for each line is:
class-or-arch [chance=#] {[random-]property=value}*
Class or Archetype:
If archetype, it's a local path like what's found in map and archetype files. Examples:
monsters/dragon/red_dragon wiz/pamela/dungeon/bikiniIf it's a classname, it needs to be fully-qualified, e.g. "wyvern.lib.classes.Teleporter".
Properties:
Specified properties are added to the generated object. The generator will look for a setProperty() function with the same name as the specified property (first letter gets uppercased). Failing that, it attempts to set the property with that name in the object's property-list.
If "random-" prepends the property name, the property value will be a random number from 1 to value. Value can be a range, such as 5..10 or 0..100, in which case the random number will be chosen from that range.
Examples:
weapons/arrow random-quantity=20
objects/treasure/diamond random-value=500..1000
Weighting:
The "chance" field is optional. If no lines in the file have a "chance" field, then all lines are given equal weighting, 1/N where N is the total number of lines.
If any of the objects specified a "chance" weight, as an integer, then any objects with no "chance" property are given a default chance of 1.
Examples: The following is a list with 3 objects, all archetypes. The axe has a total chance of 5/8 (62.5%), the bow 2/8 (25%), and the bullwhip 1/3 (12.5%):
weapons/stone_axe chance=5 weapons/orcish_bow chance=2 weapons/bullwhip
Field Summary | |
protected java.util.List |
objects_
|
protected int |
totalWeight_
|
Method Summary | |
protected void |
addObject(wyvern.lib.classes.random.RandomList.RandomObject obj)
Adds an object wrapper to the list. |
GameObject |
generate()
Chooses one of the objects in the list and instantiates it. |
static RandomList |
loadList(java.lang.String name)
Parses and loads the specified treasure list, and returns it as a RandomList instance. |
static void |
main(java.lang.String[] args)
Tests functionality. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.List objects_
protected int totalWeight_
Method Detail |
public static RandomList loadList(java.lang.String name)
name
- the list name, either one of the names in
world/lists, or a wiz list like "wiz/foo/bar". The ".list"
extension is optional.
public GameObject generate() throws java.lang.Exception
any
- exception - the class may fail to load,
or newInstance() may fail, or one of the specified
properties may have the wrong value for the class.
java.lang.Exception
protected void addObject(wyvern.lib.classes.random.RandomList.RandomObject obj)
obj
- a RandomObject produced by parsing a list linepublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |