|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectwyvern.kernel.properties.PList
wyvern.kernel.maps.MapObject
wyvern.lib.classes.random.RandomObject
Produces a random game object from any of various sources.
The best way to use a RandomObject is to set an int "level" property (1-20) on the archetype and instantiate it. This will call the RandomItem.class utility methods to choose a random game object of the specified level. You can create a specific type of object by setting a "type" string property on the archetype, chosen from the list of valid categories in RandomItem.
Another way to use the RandomObject is to put a string "list" property on the object, where the list refers to a text file containing a list of archetypes to choose from. This system is not quite as flexible, since it doesn't take item frequencies and levels into account, but it does allow you to choose from a hard-coded list of items when necessary.
Finally, although it's probably not very useful, you can force the random object to generate a single archetype by setting a "gen-arch" string property (whose value is the archetype path).
Note: no matter how you use RandomObject, it will not actually convert itself into a randomly-chosen game object until it's set into the map AND the map isn't loaded into the Map Editor.
Any properties on the RandomObject that start with "add-" are added to the generated object. For example, this archetype will generate a random, unpaid, identified spellbook of a random level for a shop:
Other supported types are add-int-*, add-string-*, as well as random-int-*, which takes a String range in the form min..max, such as "1..20", and chooses a random value from that range for the specified property.
Another supported property generator: "chance-boolean-*", such as "chance-boolean-cursed", which is an int property whose value is the percentage chance (1-100) that the object will have that property.
If you put "arch-random-level" on the archetype, whose value is a range of the form min..max, it will choose a random level in that range and pass it to the RandomItem code. This only applies if the archetype has a "type" property (also for the RandomItem code). This is, for example, how we get shops to generate random items from level 1 to 20.
If the object has "no-gen" on it, it won't automatically convert into a random object from the list on setMap(). Normally only useful for subclasses that want to determine at what point they transform.
| Field Summary | |
static int |
DEFAULT_BAG_CHANCE
Chance that the item will wind up in a bag, crate, or chest, if we're transforming in a map. |
| Fields inherited from class wyvern.kernel.maps.MapObject |
IN_MAP_EDITOR, listenerList_ |
| Fields inherited from class wyvern.kernel.properties.PList |
readOnly_ |
| Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
| Constructor Summary | |
RandomObject()
|
|
| Method Summary | |
protected void |
addChanceProperty(GameObject obj,
java.lang.String name)
Has a chance of adding the specified boolean property. |
protected void |
addObjProperty(GameObject obj,
java.lang.String name)
Adds a property to the passed object. |
protected void |
addRandomProperty(GameObject obj,
java.lang.String name)
Adds a random (int) property to the object. |
Bag |
createBag(int level)
Creates a bag or chest (possibly locked) to put the item in. |
GameObject |
generate()
Generates the object. |
GameObject |
generateFromList(java.lang.String listname)
Generates the object from a list, given the relative path to the list under wiz/ or world/lists. |
int |
getBagChance()
Returns the chance the object should wind up in a bag, which can be overridden by a subclass, or by simply setting an int "bag-chance" property on the object. |
int |
getCurseChance()
Returns the value of the "arch-curse-chance" property, or -1 if not present. |
int |
getLevel()
Returns the level to use for this item. |
java.lang.String |
getListName()
Returns the name of the list we're using, or null if ! |
static void |
main(java.lang.String[] args)
Misc testing functions. |
Bag |
setContainer(Bag container)
We've been placed in a container. |
protected void |
setDangerLevelFromMap(GameMap map)
Sets the "level" property if we don't have one, by copying the map's danger level. |
void |
setMap(GameMap map,
int x,
int y)
When you try to put it in the map, it randomly generates an object from our list and puts that in the map instead. |
GameObject |
transferProperties(GameObject obj)
Transfers add-boolean-whatever, etc. properties to the generated item. |
void |
transform(GameMap map,
int x,
int y)
Generates an object and sets it in the map. |
boolean |
usingList()
Returns true if we have a "list" property. |
boolean |
usingSingleArch()
Returns true if we have a "gen-arch" property that specifies we're only supposed to generate that kind of object. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int DEFAULT_BAG_CHANCE
| Constructor Detail |
public RandomObject()
| Method Detail |
public void setMap(GameMap map,
int x,
int y)
setMap in interface GameObjectsetMap in class MapObjectmap - the mapx - map x locy - map y loc
public void transform(GameMap map,
int x,
int y)
public Bag createBag(int level)
level - the map danger level (1-20)
public GameObject generate()
public boolean usingList()
public java.lang.String getListName()
public boolean usingSingleArch()
public GameObject transferProperties(GameObject obj)
public int getLevel()
public GameObject generateFromList(java.lang.String listname)
public Bag setContainer(Bag container)
setContainer in interface GameObjectsetContainer in class MapObjectcontainer - the container we were added to, or null
if we've been removed from a container.public int getCurseChance()
protected void addObjProperty(GameObject obj,
java.lang.String name)
obj - the object to add it toname - the property name to add. This will start
with "boolean", "int", "string" or some other supported
property type.
protected void addRandomProperty(GameObject obj,
java.lang.String name)
protected void addChanceProperty(GameObject obj,
java.lang.String name)
protected void setDangerLevelFromMap(GameMap map)
public int getBagChance()
public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||