wyvern.lib.classes.random
Class RandomObject

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.random.RandomObject
All Implemented Interfaces:
Broadcaster, GameObject, MethodHookable, PropertyList
Direct Known Subclasses:
RandomAxe, RandomBow, RandomClub, RandomRing

public class RandomObject
extends MapObject

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.

Version:
1.0, Nov 08, 1999
Author:
Steve Yegge

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 wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, groupString, inContainer, initialize, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, setAlpha, setAnimated, setBitmap, setCategory, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, toString, updateMapLocation
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 

Field Detail

DEFAULT_BAG_CHANCE

public static final int DEFAULT_BAG_CHANCE
Chance that the item will wind up in a bag, crate, or chest, if we're transforming in a map. If we're in transforming in a container, the chance is always zero.

See Also:
Constant Field Values
Constructor Detail

RandomObject

public RandomObject()
Method Detail

setMap

public 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.

Specified by:
setMap in interface GameObject
Overrides:
setMap in class MapObject
Parameters:
map - the map
x - map x loc
y - map y loc

transform

public void transform(GameMap map,
                      int x,
                      int y)
Generates an object and sets it in the map. If this object is in the map, removes it. Sets a "generated" property on the RandomObject, whose value is the object that's generated, in case you need to manipulated it.


createBag

public Bag createBag(int level)
Creates a bag or chest (possibly locked) to put the item in.

Parameters:
level - the map danger level (1-20)
Returns:
a bag, chest, or crate

generate

public GameObject generate()
Generates the object.

Returns:
a random GameObject produced from our treasure list

usingList

public boolean usingList()
Returns true if we have a "list" property.

Returns:
true if we're going to be generating our object from a static list

getListName

public java.lang.String getListName()
Returns the name of the list we're using, or null if !usingList().

Returns:
the value of the "list" property

usingSingleArch

public boolean usingSingleArch()
Returns true if we have a "gen-arch" property that specifies we're only supposed to generate that kind of object.


transferProperties

public GameObject transferProperties(GameObject obj)
Transfers add-boolean-whatever, etc. properties to the generated item.

Returns:
the object we passed in

getLevel

public int getLevel()
Returns the level to use for this item. Can be set directly with a "level" property, or if not set, uses the map's danger level. You can alternately set an arch-random-level property, a (string) range ("1-7"), and it'll choose a random level from that range.


generateFromList

public GameObject generateFromList(java.lang.String listname)
Generates the object from a list, given the relative path to the list under wiz/ or world/lists.

Returns:
a random GameObject produced from our treasure list

setContainer

public Bag setContainer(Bag container)
We've been placed in a container. Transform, and replace ourselves with the generated object.

Specified by:
setContainer in interface GameObject
Overrides:
setContainer in class MapObject
Parameters:
container - the container we were added to, or null if we've been removed from a container.

getCurseChance

public int getCurseChance()
Returns the value of the "arch-curse-chance" property, or -1 if not present.

Returns:
the chance that the generated item should be cursed. You should compare Range.percent() to this value to determine whether to curse an item.

addObjProperty

protected void addObjProperty(GameObject obj,
                              java.lang.String name)
Adds a property to the passed object.

Parameters:
obj - the object to add it to
name - the property name to add. This will start with "boolean", "int", "string" or some other supported property type.

addRandomProperty

protected void addRandomProperty(GameObject obj,
                                 java.lang.String name)
Adds a random (int) property to the object.


addChanceProperty

protected void addChanceProperty(GameObject obj,
                                 java.lang.String name)
Has a chance of adding the specified boolean property.


setDangerLevelFromMap

protected void setDangerLevelFromMap(GameMap map)
Sets the "level" property if we don't have one, by copying the map's danger level.


getBagChance

public 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.


main

public static void main(java.lang.String[] args)
Misc testing functions.