wyvern.kernel.maps
Class MapObject

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
All Implemented Interfaces:
Broadcaster, GameObject, MethodHookable, PropertyList
Direct Known Subclasses:
AbstractCommandable, Area, ArmorImpl, BasicBag, Bootstrap, Checkers, Chess, wyvern.lib.classes.games.ChessChair, Clock, CombatFlash, ConnectedObject, DynamicObject, FallingDown, Firespout, Generator, Guild, Lamp, Mountains, NoSpells, OffLimits, Platform, PortableHole, RandomObject, Shop, Sliding, Soundtrack, StaticObject, Switch, Teleporter, Terrain, Unlearner, WeaponImpl

public class MapObject
extends PList
implements GameObject

The top level implementation of the Wyvern class heirarchy.

Version:
1.0, Aug 17, 1997
Author:
Steve Yegge

Field Summary
protected static boolean IN_MAP_EDITOR
           
protected  GameObjectEventSupport listenerList_
          A lazily-instantiated helper class that registers event listeners.
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
MapObject()
           
 
Method Summary
 void addContainerChangeListener(ContainerChangeListener l)
          Adds a listener to be notified when an object enters or leaves a container.
protected  void addDefaultProperty(java.lang.String name)
          Adds a (boolean) property to the object if the object doesn't already have the property.
 void addMapChangeListener(MapChangeListener l)
          Adds a listener to be notified when the object is added to or removed from a map.
 void addMapMotionListener(MapMotionListener l)
          Adds a listener to be notified when an object moves in its map.
 void addMethodHook(MethodHookCallback callback, java.lang.String methodName)
          Registers for the specified method-hook.
 void addMotionTracker(MotionTracker t)
          Adds a MotionTracker to get map-change and map-motion events.
 void addObjectTracker(ObjectTracker t)
          Adds an ObjectTracker to get map-change, map-motion, and container-change events all delivered to a single place.
 void addPrefix(java.lang.String prefix, boolean id)
          Adds a prefix to the short description, such as "+3".
 void addSuffix(java.lang.String suffix, boolean id)
          Adds a suffix to the short description, such as "of Durability".
protected  void addToMap(GameMap map, java.util.List newpos)
          Places the object in the specified map at all locations in the passed list.
 boolean bless()
          Blesses the object, or if it's cursed, upgrades it to uncursed.
 java.util.List broadcast(java.lang.String msg)
          Broadcasts a message to every player in sight of this object, not including the player who initiated it (if this is a player).
 java.util.List broadcast(java.lang.String msg, byte style)
          Broadcasts a message to every player in earshot of this object, not including the player who initiated it (if this is a player).
 java.util.List broadcast(java.lang.String msg, Predicate p)
          Sends the specified message to players in earshot of this object, not including the player who initiated it (if this is a player).
 java.util.List broadcast(java.lang.String msg, Predicate p, byte style)
          Sends the specified message to player in sight of this object, not including the player who initiated it (if this is a player).
 java.util.List broadcast(java.lang.String msg, Predicate p, byte style, int radius)
          Sends the specified message to everyone in sight.
 boolean canEnter(GameMap map, Point p)
          Determines if it's possible for the (part of) object to enter this square.
 GameObject canEnterBlockedBy(GameMap map, Point p)
          Determines if it's possible for the (part of) object to enter this square.
 boolean canMove(GameMap map, java.util.List dest)
          Checks each point in the destination list to see if the object could go there.
 boolean canMove(int dir)
          Determines whether it's possible for the agent to move to the passed location.
 GameObject canMoveBlockedBy(GameMap map, java.util.List dest)
          Checks each point in the destination list to see if the object could go there.
 GameObject canMoveBlockedBy(int dir)
          Determines whether it's possible for the agent to move to the passed location.
 boolean canMoveTo(GameMap map, Point p)
          Determines whether it's possible for the agent to be teleported to the passed location without changing shape.
 GameObject canMoveToBlockedBy(GameMap map, Point p)
          Determines whether it's possible for the agent to be teleported to the passed location without changing shape.
 java.lang.String checkDrop(Commandable agent, Container destination)
          Checks whether the object can be dropped, thrown, given away, put in a bag, or otherwise disposed of by the bearer.
 boolean curse()
          Curses the object, or if it's blessed, downgrades it to uncursed.
 void cycleFrame()
          Cycles the animation frame for the object.
 void destroy()
          Tells the object to destroy itself.
protected  void ensureListenerList()
          Lazily creates the EventSupport object so we can start adding various custom EventListeners.
protected  void ensureWeight(java.lang.String weight)
          This method is for the convenience of subclasses.
 java.util.LinkedList externalize()
          Produces a text-serialized version of the object and its properties.
protected  void fireContainerEntered(Bag bag)
           
protected  void fireContainerExited(Bag bag)
           
protected  void fireEnteredMap(GameMap map, int x, int y)
           
protected  void fireExitedMap(GameMap map, int x, int y)
           
protected  void fireMovedInMap(GameMap map, java.util.List src, java.util.List dest)
           
 int getAlpha()
          Returns the alpha value for this object (1-100).
 Appearance getAppearance()
          Returns the object's Appearance property.
 Archetype getArchetype()
          Returns the parent archetype for this object.
 java.lang.String getBaseName()
          Returns the basic description of the object, usually the "short" or the "id" property.
 long getBaseWeight()
          Returns the weight of a single unit of the object.
 java.lang.String getBitmap()
          Returns the bitmap string for this object (it's also stored in the Appearance property, so this method is just for convenience).
 Rectangle getBounds()
          Returns the bounding rectangle for this object.
 java.lang.String getCanonicalClassName()
          Returns the name of the object's class in a form suitable for writing to a map file.
 java.lang.String getCategory()
          Returns the relative path for this object (it's also stored in the appearance property, so this method is just for convenience).
 Bag getContainer()
          Returns the container (Bag or Inventory) this object is in, or null if it's not in a container.
 java.lang.String getCreator()
          Returns the name of the Wizard who created this object, if any.
 java.lang.String getDamagedDescription()
          Returns a message like "It is badly damaged".
 java.lang.String getDescription()
          Returns a long-description for the object.
 int getDirection()
          Returns the direction this object is facing.
 java.lang.String getGenderPossessive()
          Returns "his", "her" or "its", as appropriate to the Player (or GameObject's) "sex" property.
 java.lang.String getGenderPronoun()
          Returns "him", "her" or "it", as appropriate to the Player (or GameObject's) "sex" property.
 java.lang.String getImage()
          Returns the image path, such as "monsters/dragon/red_dragon", or "wiz/foo/bar/bugbear"
 int[] getImageDescriptor(int x, int y)
          Returns a single appearance descriptor for the object at the specified (x, y) location.
 int[] getImageDescriptors()
          Returns an appearance descriptor for the object.
 int getLayer()
          Returns the drawing layer this object should be drawn in.
 java.util.List getLocations()
          Returns all the map locations this object occupies.
 GameMap getMap()
          Returns the GameMap reference stored in the instance data for this object, set by setMapLink().
 GameMap getMapLink()
          Returns the GameMap reference stored in the instance data for this object, set by setMapLink().
 Material getMaterial()
          Returns the (primary) Material this object is made from.
 java.lang.String getMaterialDescription()
          Returns "It is made of ".
 Mover getMover()
          Returns the Mover used by this object.
 java.lang.String getOwningPlayer()
          Returns the owner of this object.
 GameMap getParentMap()
          Returns the map this object resides in.
 java.util.List getPrefixes(boolean id)
          Returns a list of prefixes that are to be prepended to the object's short description.
 int getQuantity()
          Convenience method for returning the value of the "quantity" property.
 Point getReferenceLoc()
          Returns the "reference location" for this object, which is the first Point in the object's location list.
 java.util.List getRelativeLocs()
          Returns a list of relative locations.
 java.lang.String getShortDesc()
          Returns a short description for the object.
 java.util.List getSuffixes(boolean id)
          Returns a list of suffixes that are to be appended to the object's short description.
 int getTile(int xloc, int yloc)
          Returns the tile number for this object at this location.
 int getTile(Point p)
          Returns the tile number for this object at this location.
 int getValue()
          Returns the amount (in gold pieces) that the object would cost in a standard shop.
 long getWeight()
          Returns the weight of this object in grams.
protected  java.lang.String groupString(java.lang.String desc)
          Mangles the short description to include quantity information.
 boolean inContainer()
          Returns true if the object is currently in a Bag or Inventory.
 void initialize()
          Initializes the object's default properties.
protected  void initLocs()
          Initializes the location list to 1 point.
 boolean inMapEditor()
          Returns true if we're currently in the Map Editor rather than in a live game.
 void invalidate()
          Notifies the parent container (bag, inv or map) that a visual change has occurred in this object.
 void invalidateImage()
          Notifies the object's parent container (bag, inv or map) that the object's image has changed.
 void invalidateParent()
          Notifies the object's parent container (bag, inv or map) that this object's image and/or text description have changed.
 void invalidateText()
          Notifies the parent container (bag, inv or map) that a textual change has occurred in this object.
 boolean isAnimated()
          Returns true if the item has an "anima" property, typically an AnimationParams.
 boolean isAttackable()
          Returns true if this is an Attackable.
 boolean isBlessed()
          Returns true if the object is blessed.
 boolean isCommandable()
          Returns true if (and only if) this object has an event queue and can be commanded (i.e. it's an instance of Commandable).
 boolean isCursed()
          Returns true if the object is cursed (or damned).
 boolean isDamned()
          Returns true if the object is damned (a more powerful curse).
 boolean isGroupable()
          Returns true if the object has the "groupable" property, so that it will combine with similar objects to form a group (or "stack", as many players call it).
 boolean isIdentified()
          Returns true if the item is identified.
 boolean isMonster()
          Returns true if (and only if) this is a Monster (and not a Player).
 boolean isMonsterOrPlayer()
          Returns true if this is a Monster or Player
 boolean isPlayer()
          Returns true if (and only if) this is a Player.
 boolean isTerrain()
          Returns true if (and only if) this object is an instance of class Terrain, or a subclass.
 boolean isUncursed()
          Returns true if the object is uncursed, meaning it's not damned, cursed, or blessed.
 boolean isUnpaid()
          Returns true if the item has the "unpaid" property.
 boolean isWizard()
          Returns true if (and only if) this is a Player with the "wizard" property.
 GameObject makeClone()
          Produces a clone of this object.
 void markPaid()
          Marks the object as paid-for.
 void markUnpaid()
          Marks the object as unpaid.
 void move(int xoffset, int yoffset)
          Translates the object to a new relative location.
 boolean occupies(int x, int y)
          Returns true if the object (in whole or in part) occupies the specified location.
 void positionAt(GameObject obj)
          Sets the object in the map where another object is located.
 void positionAtMap(GameMap map, GameObject obj)
          Sets the object in the map where another object is located.
 void remove()
          Removes this object from its map.
 void removeContainerChangeListener(ContainerChangeListener l)
          Removes a ContainerChangeListener that was previously added with addContainerChangeListener().
protected  void removeFromMap(GameMap map, java.util.List locations)
          Removes all references to the object from the map.
 void removeMapChangeListener(MapChangeListener l)
          Removes a MapChangeListener that was previously added with addMapChangeListener().
 void removeMapMotionListener(MapMotionListener l)
          Removes a MapMotionListener that was previously added with addMapMotionListener().
 void removeMethodHook(MethodHookCallback callback, java.lang.String methodName)
          Unregisters for the specified method-hook.
 void removeMotionTracker(MotionTracker t)
          Removes a MotionTracker previously added with addMotionTracker.
 void removeObjectTracker(ObjectTracker t)
          Removes an ObjectTracker previously added with addObjectTracker().
 void removePrefix(java.lang.String prefix, boolean id)
          Removes a prefix from the list of prefixes for the short description.
 void removeSuffix(java.lang.String suffix, boolean id)
          Removes a suffix from the list of suffixes for the short description.
 void runMethodHook(java.lang.String hookName, java.lang.Object data)
          Runs the specific method hook.
 void setAlpha(int alpha)
          Sets the alpha value for this appearance (1-100).
 void setAnimated(boolean animate)
          Starts or stops the object's animation timer.
 void setBitmap(java.lang.String bitmap)
          Sets just the file basename for the GameObject's appearance.
 void setCategory(java.lang.String category)
          Sets the relative path for the object's image
 Bag setContainer(Bag container)
          Sets the link to the parent container.
protected  void setDefaultBitmap(java.lang.String bmp)
          Deprecated. setDefaultBitmap() and setDefaultCategory() are deprecated - use setDefaultImage(path) instead
protected  void setDefaultCategory(java.lang.String cat)
          Deprecated. setDefaultBitmap() and setDefaultCategory() are deprecated - use setDefaultImage(path) instead
protected  void setDefaultDesc(java.lang.String desc)
          Sets long description if we don't have one.
protected  void setDefaultImage(java.lang.String path)
          Sets image if we don't have it already
protected  void setDefaultIntProperty(java.lang.String name, int value)
          Sets an int property if it's not already set.
protected  void setDefaultLayer(int layer)
          Sets the layer for the image if getLayer() == 0.
protected  void setDefaultMaterial(Material material)
          If we don't already have a "material" property from the object's archetype, sets "material" to the passed Material.
protected  void setDefaultProperty(java.lang.String name, java.lang.Object value)
          Sets a property if it's not already set.
protected  void setDefaultShortDesc(java.lang.String shortdesc)
          Sets short description if we don't have one.
 void setDirection(int direction)
          Sets the direction this object is facing.
 void setImage(java.lang.String image)
          Sets the image (relative path + filename) for this object.
 void setImage(java.lang.String path, java.lang.String img)
          Sets the image (relative path + filename) for this object.
 void setLayer(int layer)
          Sets the drawing layer this object appears in.
 void setLocations(java.util.List dest)
          Sets an object's location-list using absolute coordinates.
 void setMap(GameMap map, int x, int y)
          Sets the parent map for this object, passing requested location at which to put the object.
 GameMap setMapLink(GameMap map)
          Sets the parent map for this object.
 void setQuantity(int quantity)
          Sets a quantity on the object.
 void setShape(java.util.List new_shape)
          This is the setSize() method for non-rectangular objects.
 void setSize(int width, int height)
          Shapes the object into a rectangle of the specified dimensions.
 void setTransientSize(int width, int height)
          Calls setSize, but saves our original size first, in a transient property called "real-size".
 void setWeight(long weight)
          Sets the weight of the object in grams.
 void setWeight(java.lang.String weight)
          Sets a new weight for the object.
 void teleport(int x, int y)
          Teleports the object to a completely new map location.
 java.lang.String toString()
          Returns the short (usually one-line) description of the object.
protected  void updateMapLocation(java.util.List src, java.util.List dest)
          This method is called by move(), teleport() and setLocations() to remove the object from its old locations and place it in its new locations.
 
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

IN_MAP_EDITOR

protected static final boolean IN_MAP_EDITOR

listenerList_

protected GameObjectEventSupport listenerList_
A lazily-instantiated helper class that registers event listeners.

Constructor Detail

MapObject

public MapObject()
Method Detail

initialize

public void initialize()
Description copied from interface: GameObject
Initializes the object's default properties. Any GameObject implementation that wishes to initialize itself should do so here, rather than in the constructor. This is because nearly all game objects inherit from an archetype, and the archetype parent pointer isn't set until the object's constructor finishes. This is a good place to add any class-default properties for an object - properties that the object gets regardless of which archetype it inherits from. WARNING: don't forget to call the superclass' initialize() method, or the object may not function properly. For instance, it won't become animated even if it specifies animation parameters in the archetype.

Specified by:
initialize in interface GameObject

getLocations

public java.util.List getLocations()
Description copied from interface: GameObject
Returns all the map locations this object occupies.

Specified by:
getLocations in interface GameObject
Returns:
the list of the locations the object occupies. Don't change this list explicitly, since it won't actually update the map. Use move(), setSize(), teleport() and so on to change the locations the object occupies.

initLocs

protected void initLocs()
Initializes the location list to 1 point.


getRelativeLocs

public java.util.List getRelativeLocs()
Description copied from interface: GameObject
Returns a list of relative locations. It's the shape of the object in its local coordinate space, so the reference (or first) location will always be (0,0).

Specified by:
getRelativeLocs in interface GameObject
Returns:
the list of absolute locations we occupy, starting at (0,0). A giant, for example, will typically return (0,0) and (0,1).

occupies

public boolean occupies(int x,
                        int y)
Description copied from interface: GameObject
Returns true if the object (in whole or in part) occupies the specified location.

Specified by:
occupies in interface GameObject
Parameters:
x - the x coordinate to check
y - the y coordinate to check
Returns:
true if the object occupies or overlaps that location.

getReferenceLoc

public Point getReferenceLoc()
Description copied from interface: GameObject
Returns the "reference location" for this object, which is the first Point in the object's location list. It acts as a sort of "hot spot" for the object - a context-dependent reference point for when the object needs to be treated as a point. For instance, when a monster fires a spell, it originates from the monster's reference location. When a monster or player is carrying a torch, for instance, the light emanates from the reference location.

For rectangular objects, it defaults to the upper-left corner of the object. Objects can return any point they like for their reference location, although it's recommended that they return a point that exists in their location-list.

Specified by:
getReferenceLoc in interface GameObject

setSize

public void setSize(int width,
                    int height)
Description copied from interface: GameObject
Shapes the object into a rectangle of the specified dimensions.

You can also use the setShape() method, but this is much easier for the 90+ percent of all objects that are rectangular.

This method keeps the object at the same reference location. That is, it obtains the object's current "position" by taking the first location from its locations list, and it makes sure the locations are all relative to this point, which is treated as the object's upper-left corner for the new rectangle.

Note that this is a "low-level" method: it doesn't do any checking to ensure that the object won't wind up in an invalid state (such as overlapping a wall) when it resizes. The caller should perform such checks before calling this method.

Specified by:
setSize in interface GameObject
Parameters:
width - the new width of the object
height - the new height of the object

setTransientSize

public void setTransientSize(int width,
                             int height)
Description copied from interface: GameObject
Calls setSize, but saves our original size first, in a transient property called "real-size".

Specified by:
setTransientSize in interface GameObject
Parameters:
width - the width of the object, in map coordinates
height - the height of the object, in map coordinates

setShape

public void setShape(java.util.List new_shape)
Description copied from interface: GameObject
This is the setSize() method for non-rectangular objects.

You pass in a list of Points consisting of the relative positions the object occupies. They will be translated to the object's previous "reference position" (defined as the first location in its old locations list).

Specified by:
setShape in interface GameObject
Parameters:
new_shape - a list of points that the object occupies

setLocations

public void setLocations(java.util.List dest)
Description copied from interface: GameObject
Sets an object's location-list using absolute coordinates. No translation is done. The points you pass are the points the object now occupies. It will update its position in the map. This method is equivalent to a call to setShape() followed by a call to teleport().

This method assumes you know what you're doing, and will let you do things like put a player in a wall, so be careful.

The passed destination is used "as-is" as the new location list. Don't use the list again after passing it in to this method. (Typically you should pass in an ArrayList for performance).

Specified by:
setLocations in interface GameObject
Parameters:
dest - the new set of locations the object occupies.

move

public void move(int xoffset,
                 int yoffset)
Description copied from interface: GameObject
Translates the object to a new relative location. E.g. to move an object right one square, call obj.move ( 1, 0 ). Use teleport() to move the object to a new absolute position.

The preferred way to move a Commandable is to command() it with command ( "move <direction>" ). This will ensure that the object only moves as fast as it can, and will run the pre- and post-move hooks so that others can participate in the event, possibly vetoing it if it's not allowed.

Specified by:
move in interface GameObject
Parameters:
xoffset - the x offset to move the object
yoffset - the y offset to move the object

teleport

public void teleport(int x,
                     int y)
Description copied from interface: GameObject
Teleports the object to a completely new map location. The old position is ignored and no translation happens. The point you pass is where it winds up.

Specified by:
teleport in interface GameObject
Parameters:
x - the new x location for the object.
y - the new y location for the object.

remove

public void remove()
Description copied from interface: GameObject
Removes this object from its map. This is the correct way take an object out of a map - you shouldn't invoke the map's remove() method on the object.

Specified by:
remove in interface GameObject

positionAt

public void positionAt(GameObject obj)
Description copied from interface: GameObject
Sets the object in the map where another object is located.

Specified by:
positionAt in interface GameObject
Parameters:
obj - another GameObject to use for the location. We will be placed at the passed object's reference location.
See Also:
GameObject.setMap(wyvern.lib.GameMap, int, int)

positionAtMap

public void positionAtMap(GameMap map,
                          GameObject obj)
Description copied from interface: GameObject
Sets the object in the map where another object is located.

Specified by:
positionAtMap in interface GameObject
Parameters:
map - the new parent map for this object
obj - another GameObject to use for the location. We will be placed at the passed object's reference location.
See Also:
GameObject.setMap(wyvern.lib.GameMap, int, int)

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Description copied from interface: GameObject
Sets the parent map for this object, passing requested location at which to put the object. If the object is large (i.e. bigger than 1x1), then its "reference location", defined as the first location in its location-list, is placed at the requested location, and the remaining locations are placed relative to the reference location.

For example, if a 2x2 object is placed at (10,10), then the object's upper-left corner is its reference loc, so a reference to the object is placed at (10,10). The remaining three locations are placed at (11,10), (10,11) and (11,11).

For objects that wish to subclass this method, it does the following:

A method-hook is available for this method; it's called "add", and it's called whenever an object is added to a map. This happens whenever an object moves within a map (because of the current way in which physical object movement is implemented), so currently it's sufficient to have "add" and "remove" method hooks, but no "move" method hook.

Specified by:
setMap in interface GameObject
Parameters:
map - the new parent map for this object
x - the x coord in the map to place the object.
y - the y coord in the map to place the object.

setMapLink

public GameMap setMapLink(GameMap map)
Description copied from interface: GameObject
Sets the parent map for this object. You should use this only rarely. It doesn't run any hooks, or actually place the object in the map. It's only useful for when you're overriding setMap(map, x, y) but don't want the superclass behavior.

Doesn't actually put the object in the map - you have to call map.add(obj, x, y) for each location the object occupies in order for it to really be in the map.

Specified by:
setMapLink in interface GameObject
Parameters:
map - the map the object should think it's in. getMap() will return this value.
Returns:
the map link that we just replaced (i.e. the map the object thought it was in before).

getParentMap

public GameMap getParentMap()
Description copied from interface: GameObject
Returns the map this object resides in. If the object is in a container or inventory, attempts to follow the links up until it finds the map containing one of its parents. You can put bags in other bags, so it could search up quite a few links.

Specified by:
getParentMap in interface GameObject
Returns:
the parent GameMap, or null if it's really not in one

getMap

public GameMap getMap()
Description copied from interface: GameObject
Returns the GameMap reference stored in the instance data for this object, set by setMapLink(). Use getParentMap() to search up the container chain to find the top-level map.

Specified by:
getMap in interface GameObject
Returns:
the map link for this map, or null if we're not in a map (could be in a bag/inventory, or not connected anywhere).

getMapLink

public GameMap getMapLink()
Description copied from interface: GameObject
Returns the GameMap reference stored in the instance data for this object, set by setMapLink().

Specified by:
getMapLink in interface GameObject
Returns:
the map link for this map, or null if we're not in a map (could be in a bag/inventory, or not connected anywhere).

inContainer

public boolean inContainer()
Description copied from interface: GameObject
Returns true if the object is currently in a Bag or Inventory.

Specified by:
inContainer in interface GameObject
Returns:
true if the object is in a container. If false, the object is either in a map, or not linked from anywhere that a player can get to.

getContainer

public Bag getContainer()
Description copied from interface: GameObject
Returns the container (Bag or Inventory) this object is in, or null if it's not in a container.

Specified by:
getContainer in interface GameObject
Returns:
the container we think we're in, or null if we're not currently in a container.

setContainer

public Bag setContainer(Bag container)
Description copied from interface: GameObject
Sets the link to the parent container. This is NOT the correct way to put something in a bag or inventory. You should call bag.add(object) or inv.add(object). All this method does is set the link from this object to the parent, for getContainer().

Specified by:
setContainer in interface GameObject
Parameters:
container - the container we've been placed in, or null to remove the link. Returns whatever container we were in before the change, or null if none.

getBounds

public Rectangle getBounds()
Description copied from interface: GameObject
Returns the bounding rectangle for this object. Typically objects don't have to override this method, even if they have an oddball location list, since it calls Location.getBounds() to compute the bounding rectangle from the location list. An object can speed this up if it knows its own bounding box.

Specified by:
getBounds in interface GameObject
Returns:
the minimum bounding box that includes all locations occupied by this object at the time the method is called.

canMoveTo

public boolean canMoveTo(GameMap map,
                         Point p)
Description copied from interface: GameObject
Determines whether it's possible for the agent to be teleported to the passed location without changing shape. Takes into consideration things like whether the move is out of bounds for the map, whether the object will fit there, and whether the map allows this kind of object to be present at that location.

Keep in mind that the map contents can change (e.g. monsters can move in the way, walls can appear and disappear), so the results from this method can become stale if you wait too long. It's safe if you call it on the Scheduler thread and then use the results before relinquishing the Scheduler thread.

Generally speaking, this method is useful for computing paths, such as for AIs determining where their monster should try to go.

Specified by:
canMoveTo in interface GameObject
Parameters:
map - the map to teleport to
p - the point in that map
Returns:
true if it would be OK.

canMoveToBlockedBy

public GameObject canMoveToBlockedBy(GameMap map,
                                     Point p)
Description copied from interface: GameObject
Determines whether it's possible for the agent to be teleported to the passed location without changing shape. Takes into consideration things like whether the move is out of bounds for the map, whether the object will fit there, and whether the map allows this kind of object to be present at that location.

Keep in mind that the map contents can change (e.g. monsters can move in the way, walls can appear and disappear), so the results from this method can become stale if you wait too long. It's safe if you call it on the Scheduler thread and then use the results before relinquishing the Scheduler thread.

Generally speaking, this method is useful for computing paths, such as for AIs determining where their monster should try to go.

Specified by:
canMoveToBlockedBy in interface GameObject
Parameters:
map - the map to teleport to
p - the point in that map
Returns:
whatever object blocks us, if any

canMove

public boolean canMove(int dir)
Description copied from interface: GameObject
Determines whether it's possible for the agent to move to the passed location. Takes into account the direction the agent is moving, and computes any shape-changing required. Like canEnter, it only applies until the map layout changes.

Specified by:
canMove in interface GameObject
Parameters:
dir - the wyvern.lib.Direction constant consisting of a direction to move from the monster's current location.

canMoveBlockedBy

public GameObject canMoveBlockedBy(int dir)
Description copied from interface: GameObject
Determines whether it's possible for the agent to move to the passed location. Takes into account the direction the agent is moving, and computes any shape-changing required. Like canEnter, it only applies until the map layout changes. Returns what you were blocked by, if anything.

Specified by:
canMoveBlockedBy in interface GameObject
Parameters:
dir - the wyvern.lib.Direction constant consisting of a direction to move from the monster's current location.

canMove

public boolean canMove(GameMap map,
                       java.util.List dest)
Description copied from interface: GameObject
Checks each point in the destination list to see if the object could go there. Called by canEnter and canMove. Useful if you've already computed the list of points the object/monster would occupy after a move.

Specified by:
canMove in interface GameObject
Parameters:
map - the destination map
dest - the proposed destination list (map locations)
Returns:
true if the object could move there

canMoveBlockedBy

public GameObject canMoveBlockedBy(GameMap map,
                                   java.util.List dest)
Description copied from interface: GameObject
Checks each point in the destination list to see if the object could go there. Called by canEnter and canMove. Useful if you've already computed the list of points the object/monster would occupy after a move.

Specified by:
canMoveBlockedBy in interface GameObject
Parameters:
map - the destination map
dest - the proposed destination list (map locations)
Returns:
true if the object could move there

canEnter

public boolean canEnter(GameMap map,
                        Point p)
Description copied from interface: GameObject
Determines if it's possible for the (part of) object to enter this square. This is what you call if the agent is going to be changing shape, and you want to see if their new shape can encroach into the passed location. Call canMoveTo() if you're trying to see if the object could move into the passed location without changing shape.

Specified by:
canEnter in interface GameObject
Parameters:
map - the map to teleport to
p - the point in that map
Returns:
true if it would be OK.

canEnterBlockedBy

public GameObject canEnterBlockedBy(GameMap map,
                                    Point p)
Description copied from interface: GameObject
Determines if it's possible for the (part of) object to enter this square. This is what you call if the agent is going to be changing shape, and you want to see if their new shape can encroach into the passed location. Call canMoveTo() if you're trying to see if the object could move into the passed location without changing shape.

Specified by:
canEnterBlockedBy in interface GameObject
Parameters:
map - the map to teleport to
p - the point in that map
Returns:
whatever blocks us, null if it would be OK.

getMover

public Mover getMover()
Description copied from interface: GameObject
Returns the Mover used by this object.

Specified by:
getMover in interface GameObject

getTile

public int getTile(Point p)
Description copied from interface: GameObject
Returns the tile number for this object at this location. The default implementation only works for rectangular objects; it MUST be overridden by disjoint objects. The default implementation is to return the object's bitmap if the (x,y) passed in is the object's upper-left corner. Otherwise, it returns -1.

Specified by:
getTile in interface GameObject
Parameters:
p - object (x, y) location
Returns:
the tile number to draw at that location, or -1 for being invisible at that location.

getTile

public int getTile(int xloc,
                   int yloc)
Description copied from interface: GameObject
Returns the tile number for this object at this location. The default implementation only works for rectangular objects; it MUST be overridden by disjoint objects. The default implementation is to return the object's bitmap if the (x,y) passed in is the object's upper-left corner. Otherwise, it returns -1.

Specified by:
getTile in interface GameObject
Parameters:
xloc - object x location
yloc - object y location
Returns:
the tile number to draw at that location, or -1 for being invisible at that location.

getImageDescriptors

public int[] getImageDescriptors()
Description copied from interface: GameObject
Returns an appearance descriptor for the object. The descriptor is an array of triples. Each triple consists of an (x, y) position and an image (tile) number to draw at that position. Non-rectangular objects need to override this method and provide their own list of bitmaps and locations.

Normally you don't need to mess with this method. It's for the client and the map editor.

Specified by:
getImageDescriptors in interface GameObject
Returns:
an array of x, y, bitmap triples. Each three successive ints in the array is one triple.

getImageDescriptor

public int[] getImageDescriptor(int x,
                                int y)
Description copied from interface: GameObject
Returns a single appearance descriptor for the object at the specified (x, y) location.

The descriptor consists of an offset and a bitmap number. The offset specifies where to draw the bitmap, in absolute coordinates, so that the specified square has the correct representation. This is used primarily by the Map Editor to draw a particular square of an object, but anyone can use it for that purpose.

Normally you don't need to mess with this method. It's for the client and the map editor.

Specified by:
getImageDescriptor in interface GameObject
Returns:
an array of 3 ints: (x, y) offset and bitmap number

getBitmap

public java.lang.String getBitmap()
Description copied from interface: GameObject
Returns the bitmap string for this object (it's also stored in the Appearance property, so this method is just for convenience).

Specified by:
getBitmap in interface GameObject
Returns:
the bitmap string

getCategory

public java.lang.String getCategory()
Description copied from interface: GameObject
Returns the relative path for this object (it's also stored in the appearance property, so this method is just for convenience).

Specified by:
getCategory in interface GameObject
Returns:
the image relative path (e.g. "wiz/foo/bar" or "monsters/goblin")

getLayer

public int getLayer()
Description copied from interface: GameObject
Returns the drawing layer this object should be drawn in.

Specified by:
getLayer in interface GameObject
Returns:
the drawing layer to place this object in.

getDirection

public int getDirection()
Description copied from interface: GameObject
Returns the direction this object is facing. Can return zero (Direction.NONE) if the object doesn't have different directions.

Specified by:
getDirection in interface GameObject
Returns:
the direction the object is facing, or Direction.NONE

setImage

public void setImage(java.lang.String path,
                     java.lang.String img)
Description copied from interface: GameObject
Sets the image (relative path + filename) for this object.

Specified by:
setImage in interface GameObject
Parameters:
path - the relative path, such as "monsters/goblin"
img - the file name, with no extension, and usually no direction or animation specifiers, e.g. "red_dragon".

setImage

public void setImage(java.lang.String image)
Description copied from interface: GameObject
Sets the image (relative path + filename) for this object.

Specified by:
setImage in interface GameObject
Parameters:
image - the relative path and file basename for the object, such as "armor/gloves/gauntlets_of_power". Shouldn't include any directional or animation specifiers like ".E1", and shouldn't include the image file extension.

getImage

public java.lang.String getImage()
Description copied from interface: GameObject
Returns the image path, such as "monsters/dragon/red_dragon", or "wiz/foo/bar/bugbear"

Specified by:
getImage in interface GameObject
Returns:
the art subdirectory and image file base name

setBitmap

public void setBitmap(java.lang.String bitmap)
Description copied from interface: GameObject
Sets just the file basename for the GameObject's appearance.

Specified by:
setBitmap in interface GameObject
Parameters:
bitmap - the path (in the art-cache directory) to the bitmap

setCategory

public void setCategory(java.lang.String category)
Description copied from interface: GameObject
Sets the relative path for the object's image

Specified by:
setCategory in interface GameObject
Parameters:
category - the relative path, such as "wiz/foo/myart", or "armor/misc".

setLayer

public void setLayer(int layer)
Description copied from interface: GameObject
Sets the drawing layer this object appears in. It won't take effect until the object is added to a map or moved in its current map. It's OK to move it to the location it already occupies just for the side effect of getting it to change layers.

Specified by:
setLayer in interface GameObject
Parameters:
layer - the drawing layer

getAlpha

public int getAlpha()
Description copied from interface: GameObject
Returns the alpha value for this object (1-100).

Specified by:
getAlpha in interface GameObject
Returns:
the alpha value (1-100)

setAlpha

public void setAlpha(int alpha)
Description copied from interface: GameObject
Sets the alpha value for this appearance (1-100).

Specified by:
setAlpha in interface GameObject
Parameters:
alpha - the alpha value

setDirection

public void setDirection(int direction)
Description copied from interface: GameObject
Sets the direction this object is facing. An object's direction is stored as a subproperty of the appearance property. By default, the value is zero, which is correct for objects whose bitmaps don't have multiple directions.

Specified by:
setDirection in interface GameObject
Parameters:
direction - a valid wyvern.lib.Direction constant. Direction.NONE is valid, but Direction.ILLEGAL_DIR isn't. (Direction.SOUTH, etc. are valid).

invalidate

public void invalidate()
Description copied from interface: GameObject
Notifies the parent container (bag, inv or map) that a visual change has occurred in this object. This method is called automatically by the GameObject in all common cases. Use it only when you're having problems getting a visible change to the object to appear on the client side. This method invalidates both the image and the text description for the object. If only one or the other is changing, you should call invalidateImage() or invalidateText() instead of this method. This invalidate() method recomputes both the text and the image.

Specified by:
invalidate in interface GameObject

invalidateText

public void invalidateText()
Description copied from interface: GameObject
Notifies the parent container (bag, inv or map) that a textual change has occurred in this object. This method is called automatically by the GameObject in all common cases. Use it only when you're having problems getting a visible change to the object's short description to appear on the client side.

Specified by:
invalidateText in interface GameObject

invalidateImage

public void invalidateImage()
Description copied from interface: GameObject
Notifies the object's parent container (bag, inv or map) that the object's image has changed. This method is called automatically by the GameObject in all common cases. Use it only when you're having problems getting a visible change to the object's image to appear on the client.

Specified by:
invalidateImage in interface GameObject

invalidateParent

public void invalidateParent()
Description copied from interface: GameObject
Notifies the object's parent container (bag, inv or map) that this object's image and/or text description have changed. This method is called automatically by invalidate(), invalidateText(), and invalidateImage(). You only need to call it if you've overridden getImageDescriptors or toString(), and you're handling your own caching of the image and text, AND the default invalidate*() methods aren't updating the parent container for you. You're very unlikely to need to use this method.

Specified by:
invalidateParent in interface GameObject

setAnimated

public void setAnimated(boolean animate)
Description copied from interface: GameObject
Starts or stops the object's animation timer.

An object's animation properties (frame rate, number of frames) are stored an an AnimationParams bean property called "anima".

Calling setAnimated(true) will start the timer based on the parameters in that property. If no such property exists, a default one will be created and added to the object.

To change an object's animation cycle:

If you don't do it in this order, you may have 2 timers trying to animate the same object, which would make it go faster than it should.

Specified by:
setAnimated in interface GameObject
Parameters:
animate - true to start animation, false to stop it
See Also:
AnimationParams

cycleFrame

public void cycleFrame()
Description copied from interface: GameObject
Cycles the animation frame for the object. Increments the frame number, modulo the number of frames available.

Normally this method is called by the object's animation timer.

Specified by:
cycleFrame in interface GameObject

externalize

public java.util.LinkedList externalize()
Description copied from interface: GameObject
Produces a text-serialized version of the object and its properties. The resulting text can be parsed by the MapLoader and PropertyParser classes.

Before writing the object, we call getDefaultProperties() and don't write any properties on the object that are considered defaults by the object's class.

Transient properties are not included in the externalized text.

Specified by:
externalize in interface GameObject
Returns:
a list of lines comprising the externalized object.

getArchetype

public Archetype getArchetype()
Description copied from interface: GameObject
Returns the parent archetype for this object.

Specified by:
getArchetype in interface GameObject
Returns:
the parent archetype, or null if not found

getCanonicalClassName

public java.lang.String getCanonicalClassName()
Description copied from interface: GameObject
Returns the name of the object's class in a form suitable for writing to a map file. If the class is in the wyvern.lib.classes package, the package name is removed. The ".class" suffix is also removed.

Specified by:
getCanonicalClassName in interface GameObject
Returns:
the simplified class name

getWeight

public long getWeight()
Description copied from interface: GameObject
Returns the weight of this object in grams.

Specified by:
getWeight in interface GameObject
Returns:
the object's weight

ensureWeight

protected void ensureWeight(java.lang.String weight)
This method is for the convenience of subclasses. A subclass can call this to make sure there's a reasonable default weight associated with the object.

Many game objects have no weight property. It makes no sense to put a weight property on an object that can never be picked up or weighed. This category includes terrain, roads, walls and buildings. For this reason, MapObject doesn't try to force a default weight; the default is zero, and it'll never come into play for objects such as the ones above.

Note: for grouped items such as coins, the weight specified here is the weight of a single coin. getWeight() will return the total weight of the group by multiplying this weight by the group quantity.

Parameters:
weight - a weight specifier such as "10.5 lb" or "50gm"
Throws:
java.lang.IllegalArgumentException - if the weight doesn't parse
See Also:
Weight

getBaseWeight

public long getBaseWeight()
Description copied from interface: GameObject
Returns the weight of a single unit of the object. For objects without the "groupable" property, this is the same as the weight returned by getWeight(). When called on a group of coins, it returns the weight of one coin.

This method is equivalent to ((Weight)getProperty("weight")).getValue().

Specified by:
getBaseWeight in interface GameObject
Returns:
the object's weight in grams (for quantity == 1)

setWeight

public void setWeight(java.lang.String weight)
Description copied from interface: GameObject
Sets a new weight for the object.

Specified by:
setWeight in interface GameObject
Parameters:
weight - the weight as a parseable string, such as "10 lb" or "22gm".
See Also:
Weight

setWeight

public void setWeight(long weight)
Description copied from interface: GameObject
Sets the weight of the object in grams.

Specified by:
setWeight in interface GameObject
Parameters:
weight - the new weight, in grams.
See Also:
Weight

getAppearance

public Appearance getAppearance()
Description copied from interface: GameObject
Returns the object's Appearance property. This encapsulates the current tile, bitmap, category, layer, direction, alpha level, and animation frame for the object. There are individual getters and setters for each sub-property, but if you're getting more than one, you should just call this and get the subprops from the Appearance object directly.

Specified by:
getAppearance in interface GameObject
Returns:
the object's Appearance (can, in some cases, be null)

checkDrop

public java.lang.String checkDrop(Commandable agent,
                                  Container destination)
Description copied from interface: GameObject
Checks whether the object can be dropped, thrown, given away, put in a bag, or otherwise disposed of by the bearer. Handles checks for, e.g. cursed weapons, worn armor, etc. If you override this method, don't forget to call the superclass version, which prevents dropping auctioned items outside of auction houses, and prevents dropping kept (non-auctioned) items at all.

Specified by:
checkDrop in interface GameObject
Parameters:
agent - the person trying to drop it
destination - the intended destination for the dropped object. It can be a Bag ("put"), a GameMap ("drop, throw"), or an Inventory ("give"). Should never be null.
Returns:
null if it's OK to drop/throw/etc. the object. If non-null, it's a message to display to the user as to why they can't get rid of it.

broadcast

public java.util.List broadcast(java.lang.String msg)
Description copied from interface: Broadcaster
Broadcasts a message to every player in sight of this object, not including the player who initiated it (if this is a player).

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - the message to broadcast.
Returns:
a list of Players who heard the message. Monsters can heard the message if they have the "hears-broadcasts" property, but they won't be added to the return list.

broadcast

public java.util.List broadcast(java.lang.String msg,
                                byte style)
Description copied from interface: Broadcaster
Broadcasts a message to every player in earshot of this object, not including the player who initiated it (if this is a player).

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - the message to broadcast.
style - the RPCConstants.TextStyle to use
Returns:
a list of Players who heard the message. Monsters can heard the message if they have the "hears-broadcasts" property, but they won't be added to the return list.

broadcast

public java.util.List broadcast(java.lang.String msg,
                                Predicate p)
Description copied from interface: Broadcaster
Sends the specified message to players in earshot of this object, not including the player who initiated it (if this is a player).

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - the message to send
p - an optional predicate used to filter the recipients. If p is false for a potential recipient, the message is not delivered to that recipient.
Returns:
a list of Players who heard the message. Monsters can heard the message if they have the "hears-broadcasts" property, but they won't be added to the return list.

broadcast

public java.util.List broadcast(java.lang.String msg,
                                Predicate p,
                                byte style)
Description copied from interface: Broadcaster
Sends the specified message to player in sight of this object, not including the player who initiated it (if this is a player).

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - the message to send
p - an optional predicate used to filter the recipients. If p is false for a potential recipient, the message is not delivered to that recipient.
style - the RPCConstants.TextStyle to use
Returns:
a list of Players who heard the message. Monsters can heard the message if they have the "hears-broadcasts" property, but they won't be added to the return list.

broadcast

public java.util.List broadcast(java.lang.String msg,
                                Predicate p,
                                byte style,
                                int radius)
Description copied from interface: Broadcaster
Sends the specified message to everyone in sight.

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - the message to send
p - an optional predicate used to filter the recipients. If p is false for a potential recipient, the message is not delivered to that recipient.
style - the RPCConstants.TextStyle to use
radius - the radius around the player to broadcast to. Includes the player's location, so a radius of 7 would cover their whole view.
Returns:
a list of Players who heard the message. Monsters can heard the message if they have the "hears-broadcasts" property, but they won't be added to the return list.

toString

public java.lang.String toString()
Returns the short (usually one-line) description of the object.

Overrides:
toString in class PList
Returns:
a short String describing this object. If the object represents a group of items, such as coins, the returned description will be a modified version of the description that includes quantity information.

getBaseName

public java.lang.String getBaseName()
Returns the basic description of the object, usually the "short" or the "id" property.

Returns:
an unadorned description of the item. Can be overridden by subclasses to provide anything they like, but it should try to fit in one line (usually no more than 40 chars).

getDescription

public java.lang.String getDescription()
Description copied from interface: GameObject
Returns a long-description for the object. This is preferable to simply checking the "desc" property (which is where many objects cache their long description), because some classes may need to construct their description on the fly. Also, objects may have an "id-desc" property that is returned if the object has been identified.

Specified by:
getDescription in interface GameObject

getShortDesc

public java.lang.String getShortDesc()
Description copied from interface: GameObject
Returns a short description for the object. This is preferable to simply checking the "short" property, as some classes may construct their short description on the fly.

Specified by:
getShortDesc in interface GameObject

getMaterialDescription

public java.lang.String getMaterialDescription()
Description copied from interface: GameObject
Returns "It is made of ".

Specified by:
getMaterialDescription in interface GameObject
Returns:
the material description

getMaterial

public Material getMaterial()
Description copied from interface: GameObject
Returns the (primary) Material this object is made from.

Specified by:
getMaterial in interface GameObject

getDamagedDescription

public java.lang.String getDamagedDescription()
Description copied from interface: GameObject
Returns a message like "It is badly damaged".

Specified by:
getDamagedDescription in interface GameObject
Returns:
a description of the damage IF it's damaged. If there is no damage to the object, returns null. The description is rather generic - you need an appraisal skill to get better information. This message is used by the LookCommand to help construct the description of the object.

addPrefix

public void addPrefix(java.lang.String prefix,
                      boolean id)
Description copied from interface: GameObject
Adds a prefix to the short description, such as "+3". Does NOT automatically call invalidateText() - you should do this after you've added all your prefixes.

Specified by:
addPrefix in interface GameObject
Parameters:
prefix - the prefix to add
id - true if it's only supposed to show when the item is identified. If false, it's always visible.

addSuffix

public void addSuffix(java.lang.String suffix,
                      boolean id)
Description copied from interface: GameObject
Adds a suffix to the short description, such as "of Durability". Does NOT automatically call invalidateText() - you should do this after you've added all your suffixes.

Specified by:
addSuffix in interface GameObject
Parameters:
suffix - the suffix to add
id - true if the suffix should only show up when the item is identified. If false, it's always visible.

removePrefix

public void removePrefix(java.lang.String prefix,
                         boolean id)
Description copied from interface: GameObject
Removes a prefix from the list of prefixes for the short description. Does NOT automatically call invalidateText() - you should do this after you've removed all your prefixes.

Specified by:
removePrefix in interface GameObject
Parameters:
prefix - the prefix to remove; does nothing if the prefix wasn't already in the list
id - which list to use: if true, removes from the identified-prefixes list; else removes from the prefixes that are always visible.

removeSuffix

public void removeSuffix(java.lang.String suffix,
                         boolean id)
Description copied from interface: GameObject
Removes a suffix from the list of suffixes for the short description. Does NOT automatically call invalidateText() - you should do this after you've removed all your suffixes.

Specified by:
removeSuffix in interface GameObject
Parameters:
suffix - the suffix to remove; does nothing if the suffix wasn't already in the list
id - which list to use: if true, removes from the identified-suffixes list; else removes from the suffixes that are always visible.

getPrefixes

public java.util.List getPrefixes(boolean id)
Description copied from interface: GameObject
Returns a list of prefixes that are to be prepended to the object's short description.

Specified by:
getPrefixes in interface GameObject
Parameters:
id - which list to use: if true, removes from the identified-prefixes list; else returns the prefixes that are always visible.
Returns:
a list of prefixes. Can be null.

getSuffixes

public java.util.List getSuffixes(boolean id)
Description copied from interface: GameObject
Returns a list of suffixes that are to be appended to the object's short description.

Specified by:
getSuffixes in interface GameObject
Parameters:
id - which list to use: if true, removes from the identified-suffixes list; else returns the suffixes that are always visible.
Returns:
a list of suffixes. Can be null.

groupString

protected java.lang.String groupString(java.lang.String desc)
Mangles the short description to include quantity information.

Parameters:
desc - the short description of the object returned by the getBaseName() method.
Returns:
if the object quantity is 2 or more, changes the string to include quantity information

isGroupable

public boolean isGroupable()
Description copied from interface: GameObject
Returns true if the object has the "groupable" property, so that it will combine with similar objects to form a group (or "stack", as many players call it).

Specified by:
isGroupable in interface GameObject

setQuantity

public void setQuantity(int quantity)
Description copied from interface: GameObject
Sets a quantity on the object. Normally an object has a quantity of 1. Groupable objects (i.e. those with the property "groupable") can have a higher quantity, which affects their weight, value, appearance and other properties.

The general contract of groupable items is that you treat the group as a single object when querying its properties. For instance, getWeight() will return the weight of the composite; you don't have to multiply by the quantity. The short and long descriptions will automatically be updated to reflect the quantity. getValue() will return the total value of the items in the group, and so on.

Specified by:
setQuantity in interface GameObject
Parameters:
quantity - the new number of items in the group

getQuantity

public int getQuantity()
Description copied from interface: GameObject
Convenience method for returning the value of the "quantity" property. Most GameObjects don't have this property. The default value is 1.

Specified by:
getQuantity in interface GameObject
Returns:
how many items this object represents, usually one.

getValue

public int getValue()
Description copied from interface: GameObject
Returns the amount (in gold pieces) that the object would cost in a standard shop. You should always use this method for fetching an object's value, because this method takes into account things like quantity, remaining charges, etc. in computing the value

Specified by:
getValue in interface GameObject
Returns:
the amount a shop would sell the object for

curse

public boolean curse()
Description copied from interface: GameObject
Curses the object, or if it's blessed, downgrades it to uncursed. If the object is damned, nothing happens. Automatically calls invalidateText().

Specified by:
curse in interface GameObject
Returns:
true if it went from blessed to uncursed, or from uncursed to cursed. false if no change.

bless

public boolean bless()
Description copied from interface: GameObject
Blesses the object, or if it's cursed, upgrades it to uncursed. If the object is damned, nothing happens. Automatically calls invalidateText().

Specified by:
bless in interface GameObject
Returns:
true if it went from cursed to uncursed, or from uncursed to blessed. false if no change.

isCursed

public boolean isCursed()
Description copied from interface: GameObject
Returns true if the object is cursed (or damned).

Specified by:
isCursed in interface GameObject

isBlessed

public boolean isBlessed()
Description copied from interface: GameObject
Returns true if the object is blessed.

Specified by:
isBlessed in interface GameObject

isDamned

public boolean isDamned()
Description copied from interface: GameObject
Returns true if the object is damned (a more powerful curse).

Specified by:
isDamned in interface GameObject

isUncursed

public boolean isUncursed()
Description copied from interface: GameObject
Returns true if the object is uncursed, meaning it's not damned, cursed, or blessed.

Specified by:
isUncursed in interface GameObject

isIdentified

public boolean isIdentified()
Description copied from interface: GameObject
Returns true if the item is identified. It's considered identified if it's identifiable (i.e. has "id" property) and has the "identified" property. If it has no "id", then it's identified by default.

Specified by:
isIdentified in interface GameObject
Returns:
true if the object is identified

markPaid

public void markPaid()
Description copied from interface: GameObject
Marks the object as paid-for. Automatically calls invalidateText().

Specified by:
markPaid in interface GameObject

markUnpaid

public void markUnpaid()
Description copied from interface: GameObject
Marks the object as unpaid. Automatically calls invalidateText().

Specified by:
markUnpaid in interface GameObject

isUnpaid

public boolean isUnpaid()
Description copied from interface: GameObject
Returns true if the item has the "unpaid" property.

Specified by:
isUnpaid in interface GameObject

isAnimated

public boolean isAnimated()
Description copied from interface: GameObject
Returns true if the item has an "anima" property, typically an AnimationParams.

Specified by:
isAnimated in interface GameObject

updateMapLocation

protected void updateMapLocation(java.util.List src,
                                 java.util.List dest)
This method is called by move(), teleport() and setLocations() to remove the object from its old locations and place it in its new locations.

Parameters:
src - the location list that the object occupied.
dest - the new positions to use

removeFromMap

protected void removeFromMap(GameMap map,
                             java.util.List locations)
Removes all references to the object from the map.

Runs a method hook called "remove", whose data parameter is depends on whether we're moving within the map, or being removed completely from the map. If we're just moving, the data parameter is null. If we're being removed, the data parameter is a List. The lists's first element is the map we're being removed from. The remaining elements are Point objects representing our location list when we occupied the map.

Parameters:
map - the map to remove from
locations - the locations the object occupies

addToMap

protected void addToMap(GameMap map,
                        java.util.List newpos)
Places the object in the specified map at all locations in the passed list.

Parameters:
map - the map to add to
newpos - the new locations for the object

runMethodHook

public void runMethodHook(java.lang.String hookName,
                          java.lang.Object data)
Description copied from interface: MethodHookable
Runs the specific method hook.

Specified by:
runMethodHook in interface MethodHookable
Parameters:
hookName - the name of the method, e.g. "add"
data - any data to pass to the callbacks; can be null

addMethodHook

public void addMethodHook(MethodHookCallback callback,
                          java.lang.String methodName)
Description copied from interface: MethodHookable
Registers for the specified method-hook. Only a select few methods actually have hooks, and there is no checking done to make sure the hook name matches a real method on the target. Be sure to check the documentation for a hookable method to see what the hook name for that method is defined to be.

Specified by:
addMethodHook in interface MethodHookable
Parameters:
methodName - the name of the method to hook into
callback - the MethodHookCallback object to notify on the hook

removeMethodHook

public void removeMethodHook(MethodHookCallback callback,
                             java.lang.String methodName)
Description copied from interface: MethodHookable
Unregisters for the specified method-hook.

Specified by:
removeMethodHook in interface MethodHookable
Parameters:
methodName - the name of the method
callback - the MethodHookCallback object to notify on the hook

setDefaultImage

protected void setDefaultImage(java.lang.String path)
Sets image if we don't have it already

Parameters:
path - the path to the image

setDefaultCategory

protected void setDefaultCategory(java.lang.String cat)
Deprecated. setDefaultBitmap() and setDefaultCategory() are deprecated - use setDefaultImage(path) instead

Sets category if we don't already have a category property.

Parameters:
cat - the default category to use

setDefaultBitmap

protected void setDefaultBitmap(java.lang.String bmp)
Deprecated. setDefaultBitmap() and setDefaultCategory() are deprecated - use setDefaultImage(path) instead

Sets bitmap if we don't already have a bitmap property.

Parameters:
bmp - the default bitmap to use

addDefaultProperty

protected void addDefaultProperty(java.lang.String name)
Adds a (boolean) property to the object if the object doesn't already have the property. This allows archetypes to set a boolean value for a property, and the class won't override it.


setDefaultProperty

protected void setDefaultProperty(java.lang.String name,
                                  java.lang.Object value)
Sets a property if it's not already set.

Parameters:
name - the property name
value - the property value

setDefaultIntProperty

protected void setDefaultIntProperty(java.lang.String name,
                                     int value)
Sets an int property if it's not already set.

Parameters:
name - the property name
value - the int value

setDefaultMaterial

protected void setDefaultMaterial(Material material)
If we don't already have a "material" property from the object's archetype, sets "material" to the passed Material.

Parameters:
material - the default material to use for this object/class

setDefaultShortDesc

protected void setDefaultShortDesc(java.lang.String shortdesc)
Sets short description if we don't have one.


setDefaultDesc

protected void setDefaultDesc(java.lang.String desc)
Sets long description if we don't have one.


setDefaultLayer

protected void setDefaultLayer(int layer)
Sets the layer for the image if getLayer() == 0.


makeClone

public GameObject makeClone()
Description copied from interface: GameObject
Produces a clone of this object. The clone is created as follows:

Specified by:
makeClone in interface GameObject
Returns:
a "shallow" clone of the object, sharing the same parent archetype as the original. The local property list is copied, and any top-level mutable properties are cloned as well. Any mutable local sub-properties are carried over, so be careful.

destroy

public void destroy()
Description copied from interface: GameObject
Tells the object to destroy itself. The default implementation removes the object from its parent container (a map, bag or inventory). Subclasses can override this method to do other cleanup that might be necessary, such as removing transient properties or hook callbacks the object has set somewhere.

This method is called when the object's parent map is unloaded, when a wizard disposes the object, or when the object is destroyed via some natural force (e.g. a fireball). If you override this method, make sure to call the superclass version, so the superclass can perform its own cleanup if needed.

Specified by:
destroy in interface GameObject

getGenderPossessive

public java.lang.String getGenderPossessive()
Description copied from interface: GameObject
Returns "his", "her" or "its", as appropriate to the Player (or GameObject's) "sex" property.

Specified by:
getGenderPossessive in interface GameObject
Returns:
"his", "her" or "its"

getGenderPronoun

public java.lang.String getGenderPronoun()
Description copied from interface: GameObject
Returns "him", "her" or "it", as appropriate to the Player (or GameObject's) "sex" property.

Specified by:
getGenderPronoun in interface GameObject
Returns:
"him", "her" or "it"

getOwningPlayer

public java.lang.String getOwningPlayer()
Description copied from interface: GameObject
Returns the owner of this object. The object is considered owned by a player if it has a "kept" property with that player's name, or an "offered-by" property with that player's name.

Specified by:
getOwningPlayer in interface GameObject
Returns:
the name of the owner, or null if it's not owned

getCreator

public java.lang.String getCreator()
Description copied from interface: GameObject
Returns the name of the Wizard who created this object, if any.

Specified by:
getCreator in interface GameObject
Returns:
the name of the wizard in whose directory the object's archetype (or class, if there's no archetype) resides. Returns null if it's not a wiz object (i.e. it's a built-in game object).

isPlayer

public boolean isPlayer()
Description copied from interface: GameObject
Returns true if (and only if) this is a Player.

Specified by:
isPlayer in interface GameObject
Returns:
true if this is a Player

isMonster

public boolean isMonster()
Description copied from interface: GameObject
Returns true if (and only if) this is a Monster (and not a Player).

Specified by:
isMonster in interface GameObject
Returns:
true if this is a Monster.

isWizard

public boolean isWizard()
Description copied from interface: GameObject
Returns true if (and only if) this is a Player with the "wizard" property.

Specified by:
isWizard in interface GameObject
Returns:
true if this is a Wizard

isTerrain

public boolean isTerrain()
Description copied from interface: GameObject
Returns true if (and only if) this object is an instance of class Terrain, or a subclass. Don't try to return true for objects that aren't terrain, or you'll just get bad results.

Specified by:
isTerrain in interface GameObject
Returns:
true if this is a Terrain object.

isCommandable

public boolean isCommandable()
Description copied from interface: GameObject
Returns true if (and only if) this object has an event queue and can be commanded (i.e. it's an instance of Commandable).

Specified by:
isCommandable in interface GameObject
Returns:
true if this is a Commandable object.

isMonsterOrPlayer

public boolean isMonsterOrPlayer()
Description copied from interface: GameObject
Returns true if this is a Monster or Player

Specified by:
isMonsterOrPlayer in interface GameObject
Returns:
true if this is a Monster or Player

isAttackable

public boolean isAttackable()
Description copied from interface: GameObject
Returns true if this is an Attackable.

Specified by:
isAttackable in interface GameObject
Returns:
true if this is a wyvern.lib.properties.Attackable object.

inMapEditor

public boolean inMapEditor()
Description copied from interface: GameObject
Returns true if we're currently in the Map Editor rather than in a live game. This is occasionally useful to know - for example, you might want your object to behave differently if it's in the editor and it's added to a map.

Specified by:
inMapEditor in interface GameObject

addMapChangeListener

public void addMapChangeListener(MapChangeListener l)
Description copied from interface: GameObject
Adds a listener to be notified when the object is added to or removed from a map. If you call this after the object has already been added to the map, then the first notification you'll receive, if any, will be an objectLeftMap().

Specified by:
addMapChangeListener in interface GameObject

removeMapChangeListener

public void removeMapChangeListener(MapChangeListener l)
Description copied from interface: GameObject
Removes a MapChangeListener that was previously added with addMapChangeListener().

Specified by:
removeMapChangeListener in interface GameObject

fireEnteredMap

protected void fireEnteredMap(GameMap map,
                              int x,
                              int y)

fireExitedMap

protected void fireExitedMap(GameMap map,
                             int x,
                             int y)

addMapMotionListener

public void addMapMotionListener(MapMotionListener l)
Description copied from interface: GameObject
Adds a listener to be notified when an object moves in its map.

Specified by:
addMapMotionListener in interface GameObject

removeMapMotionListener

public void removeMapMotionListener(MapMotionListener l)
Description copied from interface: GameObject
Removes a MapMotionListener that was previously added with addMapMotionListener().

Specified by:
removeMapMotionListener in interface GameObject

fireMovedInMap

protected void fireMovedInMap(GameMap map,
                              java.util.List src,
                              java.util.List dest)

addContainerChangeListener

public void addContainerChangeListener(ContainerChangeListener l)
Description copied from interface: GameObject
Adds a listener to be notified when an object enters or leaves a container. (i.e. a bag or inventory).

Specified by:
addContainerChangeListener in interface GameObject

removeContainerChangeListener

public void removeContainerChangeListener(ContainerChangeListener l)
Description copied from interface: GameObject
Removes a ContainerChangeListener that was previously added with addContainerChangeListener().

Specified by:
removeContainerChangeListener in interface GameObject

fireContainerEntered

protected void fireContainerEntered(Bag bag)

fireContainerExited

protected void fireContainerExited(Bag bag)

addMotionTracker

public void addMotionTracker(MotionTracker t)
Description copied from interface: GameObject
Adds a MotionTracker to get map-change and map-motion events.

Specified by:
addMotionTracker in interface GameObject

removeMotionTracker

public void removeMotionTracker(MotionTracker t)
Description copied from interface: GameObject
Removes a MotionTracker previously added with addMotionTracker.

Specified by:
removeMotionTracker in interface GameObject

addObjectTracker

public void addObjectTracker(ObjectTracker t)
Description copied from interface: GameObject
Adds an ObjectTracker to get map-change, map-motion, and container-change events all delivered to a single place.

Specified by:
addObjectTracker in interface GameObject

removeObjectTracker

public void removeObjectTracker(ObjectTracker t)
Description copied from interface: GameObject
Removes an ObjectTracker previously added with addObjectTracker().

Specified by:
removeObjectTracker in interface GameObject

ensureListenerList

protected void ensureListenerList()
Lazily creates the EventSupport object so we can start adding various custom EventListeners.