wyvern.kernel.commands
Class AbstractCommandable

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.kernel.commands.AbstractCommandable
All Implemented Interfaces:
Broadcaster, Commandable, GameObject, Hookable, MethodHookable, PropertyList, RemoteAudio
Direct Known Subclasses:
AbstractTrap, Combat, FlyingBoulder, Gate, MonsterImpl, NeedleLeaf, Poison, Registration, Spell, TimerAgent, Vehicle

public abstract class AbstractCommandable
extends MapObject
implements Commandable

This class is the superclass of all monster-like things; that is, objects that are controlled by an AI of some sort. This includes actual monsters, spells, and missile attacks. All these objects share certain things in common: event queues, AIs, and extensibility. These things are built into AbstractCommandable so that the subclasses can specialize.

Version:
1.0, Jan 20, 1998
Author:
Steve Yegge

Field Summary
 HookList hookList_
           
protected  EventQueue queue_
           
protected  boolean started_
           
 
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
 
Fields inherited from interface wyvern.common.net.RemoteAudio
DEFAULT_ALERT_GAIN, DEFAULT_ALERT_REPEAT_DELAY, DEFAULT_ALERT_REPEATS, DEFAULT_GAIN, DEFAULT_REPEAT_DELAY, DEFAULT_REPEATS
 
Constructor Summary
AbstractCommandable()
           
 
Method Summary
 void addAttack(Attack attack)
          Adds an attack to our list of attacks.
 void addHook(HookCallback callback, java.lang.String hookName)
          Registers a HookCallback object for the specified hook.
 void addMessageListener(MessageListener l)
          Adds a MessageListener to be notified whenever this Commandable receives a message via a call to one of its message() methods.
 void addMethodHook(MethodHookCallback callback, java.lang.String methodName)
          Registers for the specified method-hook.
protected  void checkAnimated(java.lang.String bitmap)
          Computes our animation parameters based on the available bitmaps.
 void command(java.lang.String cmd)
          Enqueues a command into the object's command queue.
 void command(java.lang.String command, boolean user)
          A variant of wyvern.lib.Commandable.command() that specifies that the command was entered by the user typing away at the game client.
 void commandNow(java.lang.String command)
          Puts a new a command at the front of the object's command queue.
 void destroy()
          Tells the object to destroy itself.
protected  void ensureAI()
          Chooses an AI for the monster.
protected  void ensureEventQueue()
          Creates an EventQueue to hold commands for this monster.
 void fireMessageReceived(java.lang.String msg, byte style)
           
 AI getAI()
          Returns the AI driving this monster.
 java.lang.String getCapName()
          Returns the capitalized version of the name.
 EventQueue getCombatQueue()
          Returns the player's combat queue.
 Command getCommand(CommandEvent event)
          Figures out who will handle a given command.
 int getEncumbrance()
          Returns a wyvern.lib.properties.Encumbrance constant that says how loaded the player or monster is.
 Point getFiringPoint(int dir)
          Used by range weapons and spells to determine where to place the missile or spell when being fired from the monster.
 HookList getHookList()
          Returns the HookList containing the registered hooks for this object.
 java.lang.String[] getHooks()
          Returns a list of custom hooks implemented by this object.
 Inventory getInventory()
          Returns the commandable's inventory object, if any.
 java.lang.String getName()
          Returns the name of this commandable
 EventQueue getQueue()
          Returns the event queue for this object.
 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 isStarted()
          Returns true if the commandable has been started by calling start().
 boolean isTelnet()
          Returns true if the agent is using a telnet client - some commands want to produce different output in this case.
 void message(java.lang.String msg)
          Outputs a message to this object.
 void message(java.lang.String[] strings, byte[] styles)
          Sends a message to the client as an array of strings and styles to use for each piece.
 void message(java.lang.String msg, byte style)
          Sends a message to the client using the specified style.
 void pauseSound(java.lang.String id)
          Pauses a particular sound.
 void playAlert(java.lang.String path)
          Plays the specified sound file on the client, one repeat, no delay, and the default gain.
 void playAlert(java.lang.String path, int repeats, int repeatDelay, double gain)
          Plays the specified alert with custom parameters.
 void playDefaultMusic()
          The player has switched maps, so figure out the default background music to be playing, and plays it.
 void playPriorityMusic(java.lang.String path)
          Sets the background music track to the specified file, with the default gain/volume.
 void playPriorityMusic(java.lang.String path, int repeats, int repeatDelay, double gain)
          Plays the specified music with custom parameters.
 void playSound(java.lang.String path, java.lang.String id)
          Plays a sound effect on the client with the default gain.
 void playSound(java.lang.String path, java.lang.String id, int repeats, int repeatDelay, double gain)
          Plays the specified sound effect with custom parameters.
 void registerCommand(java.lang.String command, Command handler)
          Registers a new command with the monster or player.
 void removeAttack(Attack attack)
          Removes an attack from our list of attacks.
 void removeHook(HookCallback callback, java.lang.String hookName)
          Removes a callback from a specified hook list.
 void removeMessageListener(MessageListener l)
          Removes a listener previously added with addMessageListener().
 void removeMethodHook(MethodHookCallback callback, java.lang.String methodName)
          Unregisters for the specified method-hook.
 void resumeSound(java.lang.String id)
          Resumes a particular sound.
 void runFailedPostHook(CommandEvent event)
          Notifies all the objects registered on this post-hook that the command failed (for whatever reason).
 void runMethodHook(java.lang.String hookName, java.lang.Object data)
          Runs the specific method hook.
 void runPostHook(CommandEvent event)
          Notifies all the objects registered on this post-hook that the event completed successfully.
 void runPreHook(CommandEvent event)
          Calls all objects registered for a particular event and gives them a chance to deal with the event before it happens.
 void sendPicture(java.lang.String path, java.lang.String title)
          Sends a picture to the client.
 void sendPicture(java.lang.String path, java.lang.String title, byte format, byte align, byte view, int flags)
          Sends a picture to the client.
 void setAI(AI ai)
          Sets the AI for this monster.
 void setEncumbrance(int encumbrance)
          Sets the encumbrance for the monster.
 void setMusicGain(double gain)
          Sets the volume of the background music.
 void setName(java.lang.String name)
          Gives the commandable a name, stored under the "name" property.
 void setSoundGain(java.lang.String id, double gain)
          Sets the volume of a particular sound playing on the client.
 void start()
          "Starts" the monster.
 void stop()
          "Stops" the monster by destroying its event queue.
 void stopAllSounds()
          Stops all of the currently playing sounds on the client.
 void stopMusic()
          Stops the background music completely.
 void stopSound(java.lang.String id)
          Stops the specified sound effect.
 void unregisterCommand(java.lang.String command, Command handler)
          Unregisters a command.
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, 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, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMap, 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.GameObject
addContainerChangeListener, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, bless, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, externalize, getAlpha, getAppearance, getArchetype, 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, inContainer, initialize, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDirection, setImage, setImage, setLayer, setLocations, setMap, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport
 
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
 
Methods inherited from interface wyvern.lib.Broadcaster
broadcast, broadcast, broadcast, broadcast, broadcast
 

Field Detail

queue_

protected transient EventQueue queue_

hookList_

public transient HookList hookList_

started_

protected transient volatile boolean started_
Constructor Detail

AbstractCommandable

public AbstractCommandable()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: Commandable
Returns the name of this commandable

Specified by:
getName in interface Commandable
Returns:
the commandable's name. If it has no name, returns something suitable, such as its type.

setName

public void setName(java.lang.String name)
Description copied from interface: Commandable
Gives the commandable a name, stored under the "name" property.

Specified by:
setName in interface Commandable
Parameters:
name - the name for the commandable

getCapName

public java.lang.String getCapName()
Description copied from interface: Commandable
Returns the capitalized version of the name.

Specified by:
getCapName in interface Commandable
Returns:
the name with the first letter capitalized.

command

public void command(java.lang.String command,
                    boolean user)
Description copied from interface: Commandable
A variant of wyvern.lib.Commandable.command() that specifies that the command was entered by the user typing away at the game client. Sometimes we need to know whether a given command was originated by the game engine or by a user.

This method is called by the game engine when enqueueing a user command from the client. You shouldn't call it (normally), unless you're forwarding a command from the user back into the queue for some reason, e.g. if the user were controlling a golem. Normally you should simply use Commandable.command(String).

Specified by:
command in interface Commandable
Parameters:
command - the command to enqueue
user - true if the command was initiated by the user

commandNow

public void commandNow(java.lang.String command)
Description copied from interface: Commandable
Puts a new a command at the front of the object's command queue.

This is an alternative to command() that should be used if you need the command to execute before any pending commands are processed.

By default, events created this way are flagged as not player-originated.

Specified by:
commandNow in interface Commandable
Parameters:
command - the command string plus args

command

public void command(java.lang.String cmd)
Description copied from interface: Commandable
Enqueues a command into the object's command queue.

This method is the main input to a Commandable object. Command originators (e.g. a user, an AI, or any game code) can issue commands to this object by calling this method. The Commandable is responsible for enqueueing a CommandEvent encapsulating the command and the agent of the command.

By default, events created this way are flagged as not player-originated.

Specified by:
command in interface Commandable
Parameters:
cmd - the command string, including any args.

getCommand

public Command getCommand(CommandEvent event)
Description copied from interface: Commandable
Figures out who will handle a given command.

Asks the Commandable to look in its table of registered commands to find a Command to handle the specified command.

Specified by:
getCommand in interface Commandable
Parameters:
event - the event encapsulating the command. We pass in the event because the event automatically parses the command text into a verb and arguments, which comes in quite handy.
Returns:
a Command who recognizes the command and arguments, or null if the command is unknown.

message

public void message(java.lang.String msg)
Description copied from interface: Commandable
Outputs a message to this object.

Mostly used by Player and subclasses; monsters ignore messages by default (but they can intercept them if they like). Spells could conceivably be voice-activated too.

Specified by:
message in interface Commandable
Parameters:
msg - the message to send

message

public void message(java.lang.String msg,
                    byte style)
Description copied from interface: Commandable
Sends a message to the client using the specified style.

Specified by:
message in interface Commandable
Parameters:
msg - the text to send.
style - the RPCConstants.TextStyle to use, for instance, RPCConstants.TextStyle.TEXT_INFO for informational text.
See Also:
RPCConstants

message

public void message(java.lang.String[] strings,
                    byte[] styles)
Description copied from interface: Commandable
Sends a message to the client as an array of strings and styles to use for each piece. This way you can send a message with mixed styles.

Specified by:
message in interface Commandable
Parameters:
strings - the message to send, broken up into pieces
styles - an array (which must be the same length), containing the style to use for each piece in the strings array parameter.

sendPicture

public void sendPicture(java.lang.String path,
                        java.lang.String title,
                        byte format,
                        byte align,
                        byte view,
                        int flags)
Description copied from interface: Commandable
Sends a picture to the client. The picture must be on the server, either in a wiz directory or under the main game artwork directory. This is only implemented for players, but exists in the Commandable interface to cut down on class casting.

Specified by:
sendPicture in interface Commandable
Parameters:
path - the relative path to the image, e.g. "wiz/rhialto/pics/painting", or "monsters/goblin/goblin.S"
format - the image format (gif/jpg/png) - an RPCConstants.ImageFormat value
align - the alignment, which is an RPCConstants.ImageStyle constant specifying left-, center-, or right-aligned in the output view.
view - the view to send it to, which is an RPCConstants.ImageView constant specifying a chat window, the server output window, a popup window, etc.
title - the title use if the picture can't be displayed
flags - RPCConstants.ImageFlags

sendPicture

public void sendPicture(java.lang.String path,
                        java.lang.String title)
Description copied from interface: Commandable
Sends a picture to the client. The picture must be on the server, either in a wiz directory or under the main game artwork directory. This is only implemented for players, but exists in the Commandable interface to cut down on class casting.

The image is sent to the server-output window on the client, and it's left aligned by default. You can use the overloaded version of sendPicture to control the alignment and/or view that you want for the image. The image is assumed to be a GIF.

Specified by:
sendPicture in interface Commandable
Parameters:
path - the relative path to the image, e.g. "wiz/rhialto/pics/painting", or "monsters/goblin/goblin.S"
title - the title use if the picture can't be displayed

registerCommand

public void registerCommand(java.lang.String command,
                            Command handler)
Description copied from interface: Commandable
Registers a new command with the monster or player.

When the monster or player enters the command, the passed callback object will be notified so it can execute the command.

Specified by:
registerCommand in interface Commandable
Parameters:
command - the command verb to register
handler - the Command callback object that implements the specified command

unregisterCommand

public void unregisterCommand(java.lang.String command,
                              Command handler)
Description copied from interface: Commandable
Unregisters a command. The specified handler object will no longer be notified if the user types the command.

Specified by:
unregisterCommand in interface Commandable
Parameters:
command - the command verb to register
handler - the Command object implementing the command

getQueue

public EventQueue getQueue()
Description copied from interface: Commandable
Returns the event queue for this object.

Specified by:
getQueue in interface Commandable
Returns:
the EventQueue used for queuing commands for this obj

getCombatQueue

public EventQueue getCombatQueue()
Description copied from interface: Commandable
Returns the player's combat queue. Players have an extra queue for combat commands to give a more MUD-like combat experience. Combat is automatic and happens in parallel with movement. If we used the same queue for attacks and movement, you'd be "paralyzed" before or after each attack. We tried it that way and it was no fun.

Specified by:
getCombatQueue in interface Commandable
Returns:
the combat queue. For Commandable implementations that aren't players, this returns the same queue as the one returned by getQueue(); i.e. the only queue.

getAI

public AI getAI()
Description copied from interface: Commandable
Returns the AI driving this monster.

Specified by:
getAI in interface Commandable
Returns:
the AI implementation driving the monster. May return null if the monster has no AI (e.g. it's a Player, or just happens not to be driven right now).

setAI

public void setAI(AI ai)
Description copied from interface: Commandable
Sets the AI for this monster.

You shouldn't set the AI for a monster directly, since the monster has to register with the new AI (and unregister with its old one, if any).

Specified by:
setAI in interface Commandable
Parameters:
ai - an AI implementation to drive this monster

start

public void start()
Description copied from interface: Commandable
"Starts" the monster. Creates an event queue, registers with the kernel for getting events, and creates an AI for responding to commands for the monster.

Specified by:
start in interface Commandable

stop

public void stop()
Description copied from interface: Commandable
"Stops" the monster by destroying its event queue. The monster can be restarted via another call to start().

Specified by:
stop in interface Commandable

isStarted

public boolean isStarted()
Description copied from interface: Commandable
Returns true if the commandable has been started by calling start(). The general contract is that you can call start() and stop() as many times as you like, in any order - you can call start() five times, followed by stop(), for instance.

Specified by:
isStarted in interface Commandable
Returns:
true if start() has been called at least once, and stop() hasn't been called since the last call to start().

getInventory

public Inventory getInventory()
Description copied from interface: Commandable
Returns the commandable's inventory object, if any.

Specified by:
getInventory in interface Commandable
Returns:
an Inventory implementation

getHooks

public java.lang.String[] getHooks()
Description copied from interface: Hookable
Returns a list of custom hooks implemented by this object.

The list doesn't include names of default hooks for built-in commands.

Specified by:
getHooks in interface Hookable
Returns:
an array of names for custom hooks that the object defines. For example, if a Hookable had a Foo operation that it wanted to run pre- and post-hooks for, and no other hookable operations, this method would return an array of two strings:
  • "fooPreHook"
  • "fooPostHook"
Returns an empty string array if this object has no custom hooks.

addHook

public void addHook(HookCallback callback,
                    java.lang.String hookName)
Description copied from interface: Hookable
Registers a HookCallback object for the specified hook.

The reserved pseudo-command "any" is reserved for callbacks that need to get every single command that comes through the queue. This should very rarely be necessary, and can hurt overall game performance considerably if abused.

Specified by:
addHook in interface Hookable
Parameters:
callback - the HookCallback to notify when the hook is run.
hookName - the name of the hook list to register on.

removeHook

public void removeHook(HookCallback callback,
                       java.lang.String hookName)
Description copied from interface: Hookable
Removes a callback from a specified hook list.

Specified by:
removeHook in interface Hookable
Parameters:
callback - the HookCallback to remove from the list
hookName - the name of the hook list to unregister from.

runPreHook

public void runPreHook(CommandEvent event)
Description copied from interface: Hookable
Calls all objects registered for a particular event and gives them a chance to deal with the event before it happens.

Callbacks may veto the event, but it's still passed to any other callbacks on the list, and eventually to the Command. For callbacks, it typically doesn't really matter if the flag has been set by a previous callback; callbacks should do the same thing they would have done even if it wasn't vetoed, because the Command (or any other callback downstream) may un-veto it.

The callbacks may modify any of the event parameters. Callbacks aren't required to do rigorous checking of the validity of their changes. For example, a simple callback registered on a player's preMoveHook might change the direction in the MoveEvent randomly.

To prevent callbacks from generating illegal event parameters, the Command handling the event is implicitly the last hook on the list. Before executing the command it re-checks the preconditions to make sure the move is still legal, and if it isn't, it vetoes it and issues an error message. The message, of course, is a modifiable parameter of the event.

If a HookCallback wants to force an "illegal" event, it has to change the game state (in the agent, the map, the Command, or whatever) to make the move legal. For example, if the hook wants to make sure the player moves over a wall, the hook can set a property on the player (or the wall) that allows this move, before returning control to this method.

Specified by:
runPreHook in interface Hookable
Parameters:
event - a CommandEvent that has already run. Calling getVerb() should return the canonical verb for this command, such as "move" or "get". The verb is used to construct the hook name, by appending "PreHook" to the verb.

runPostHook

public void runPostHook(CommandEvent event)
Description copied from interface: Hookable
Notifies all the objects registered on this post-hook that the event completed successfully. Changing the event params will have no effect at this point.

Specified by:
runPostHook in interface Hookable
Parameters:
event - a CommandEvent that has already run. Calling getVerb() should return the canonical verb for this command, such as "move" or "get". The verb is used to construct the hook name, by appending "PostHook" to the verb.

runFailedPostHook

public void runFailedPostHook(CommandEvent event)
Description copied from interface: Hookable
Notifies all the objects registered on this post-hook that the command failed (for whatever reason). It's up to the CommandEvent subclass to provide more detailed information as to why it failed.

Changing the event parameters will have no effect at this point.

Specified by:
runFailedPostHook in interface Hookable
Parameters:
event - a CommandEvent that has failed for some reason. getVerb() should return the canonical verb for this command, such as "move" or "get". The verb is used to construct the hook name, by appending "FailedPostHook" to the verb.

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
Overrides:
addMethodHook in class MapObject

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
Overrides:
removeMethodHook in class MapObject

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
Overrides:
runMethodHook in class MapObject

getFiringPoint

public Point getFiringPoint(int dir)
Description copied from interface: Commandable
Used by range weapons and spells to determine where to place the missile or spell when being fired from the monster.

Finds the first map location in the specified direction that isn't occupied by the monster, starting at the monster's reference location.

Specified by:
getFiringPoint in interface Commandable
Parameters:
dir - the direction to fire - you can pass the result of monster.getDirection() if you want to fire in the direction the monster is currently facing.
Returns:
the location at which to place the spell, missile, thrown object or whatever. Caller still needs to check if the location is out of bounds, blocked, etc.

isTelnet

public boolean isTelnet()
Description copied from interface: Commandable
Returns true if the agent is using a telnet client - some commands want to produce different output in this case. It's probably always false for non-Player Commandables, and true for players connected via telnet.

Specified by:
isTelnet in interface Commandable

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
Overrides:
destroy in class MapObject

addAttack

public void addAttack(Attack attack)
Description copied from interface: Commandable
Adds an attack to our list of attacks. This list is examined in the attacking sequence to see how we should attack. If you wield a weapon, it goes into the attacks list.

Specified by:
addAttack in interface Commandable
Parameters:
attack - an Attack to add

removeAttack

public void removeAttack(Attack attack)
Description copied from interface: Commandable
Removes an attack from our list of attacks. If you unwield a weapon, it comes out of the attacks list.

Specified by:
removeAttack in interface Commandable
Parameters:
attack - the Attack to remove

ensureEventQueue

protected void ensureEventQueue()
Creates an EventQueue to hold commands for this monster. If the monster already has a queue, does nothing. The queue is instantiated lazily on the first command, so if you need to put something in the queue while the monster is being created, you might have to call this method first.


ensureAI

protected void ensureAI()
Chooses an AI for the monster. Called by start() method, which in turn is called when the monster is constructed or read from a map. Subclasses should remember to call the superclass version.

This is (probably) the most appropriate time to convert the externalized "ai" property (an Archetype) into an actual instantiated AI class. It's stored in the file as an archetype because the AI classes aren't usually directly instantiable, so doing something like "ai class FooAI" would result in an IllegalAccessError.

Because there are no static interfaces in Java (as yet), we can't simply take the class, cast it to a static interface, and invoke the getImpl() class method on it. Alas. Instead, we must use reflection to sniff out the getImpl() class method. This returns the (singleton) instance of the AI, which we can store a reference to in our "ai" property.


checkAnimated

protected void checkAnimated(java.lang.String bitmap)
Computes our animation parameters based on the available bitmaps.

Parameters:
bitmap - the database bitmap string

getEncumbrance

public int getEncumbrance()
Description copied from interface: Commandable
Returns a wyvern.lib.properties.Encumbrance constant that says how loaded the player or monster is. Encumbrance is computed from the monster's strength and current inventory weight.

Specified by:
getEncumbrance in interface Commandable
Returns:
a number from 0 (unencumbered) to 4 (immobilized)

setEncumbrance

public void setEncumbrance(int encumbrance)
Description copied from interface: Commandable
Sets the encumbrance for the monster. Encumbrance level is stored in a transient int property called "load", and is one of the constants defined in wyvern.lib.properties.Encumbrance.

Specified by:
setEncumbrance in interface Commandable
Parameters:
encumbrance - a number from 0 (unencumbered) to 4 (immobilized)

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
Overrides:
isCommandable in class MapObject

getHookList

public HookList getHookList()
Description copied from interface: Hookable
Returns the HookList containing the registered hooks for this object.

Specified by:
getHookList in interface Hookable

playAlert

public void playAlert(java.lang.String path)
Description copied from interface: RemoteAudio
Plays the specified sound file on the client, one repeat, no delay, and the default gain.

Can't be stopped, so use with care.

Specified by:
playAlert in interface RemoteAudio
Parameters:
path - the relative path to the sound file

playAlert

public void playAlert(java.lang.String path,
                      int repeats,
                      int repeatDelay,
                      double gain)
Description copied from interface: RemoteAudio
Plays the specified alert with custom parameters. Can't be stopped, so use with care.

Parameters are file path, number of repeats, delay between repeats, and gain (volume). The alert won't play if the path is null or not found on the server. All other params are adjusted to be within the valid range for the parameter, if necessary.

Specified by:
playAlert in interface RemoteAudio
Parameters:
path - the relative path to the sound file.
repeats - number of times the client should repeat the piece before stopping (and for music and sound, sending the notification back to the server). 0 means don't repeat; just play and stop.
repeatDelay - number of milliseconds to pause between repeats, if we're repeating.
gain - the volume for this track, from 0.0 to 1.0

playDefaultMusic

public void playDefaultMusic()
Description copied from interface: RemoteAudio
The player has switched maps, so figure out the default background music to be playing, and plays it.

Specified by:
playDefaultMusic in interface RemoteAudio

playPriorityMusic

public void playPriorityMusic(java.lang.String path)
Description copied from interface: RemoteAudio
Sets the background music track to the specified file, with the default gain/volume. Always defaults to zero repeats in this version. If you want repeats or looping, call the overloaded version that lets you specify other parameters.

Client sends an "#endmusic" directive back to the server when it's finished playing all the repeats.

When this playMusic() is called, the specified music overrides the current background music. The player is considered to be playing the soundtrack in "priority" mode, meaning that switching maps or combat states won't revert it back to the normal map or combat music.

Specified by:
playPriorityMusic in interface RemoteAudio
Parameters:
path - the relative path to the sound file, including extension. Can be any supported sound format (midi, ogg, others.) Nothing will be played if the path is null, or the file isn't found on the server.


playPriorityMusic

public void playPriorityMusic(java.lang.String path,
                              int repeats,
                              int repeatDelay,
                              double gain)
Description copied from interface: RemoteAudio
Plays the specified music with custom parameters.

Specified by:
playPriorityMusic in interface RemoteAudio
Parameters:
path - the relative path to the sound file. Can be any supported sound format.
repeats - number of times the client should repeat the piece before stopping and sending a notification back to the server. A value of 0 means don't repeat; just play the track once. A value of -1 means repeat indefinitely.
repeatDelay - number of milliseconds to pause between repeats, if we're repeating. Negative values are interpreted as zero (no delay).
gain - the volume for this track, from 0.0 to 1.0. Values outside the range are clipped to 0.0 or 1.0.

stopMusic

public void stopMusic()
Description copied from interface: RemoteAudio
Stops the background music completely. Client does not send a notification back to the server.

Specified by:
stopMusic in interface RemoteAudio

setMusicGain

public void setMusicGain(double gain)
Description copied from interface: RemoteAudio
Sets the volume of the background music.

Specified by:
setMusicGain in interface RemoteAudio
Parameters:
gain - the new background music gain, from 0.0 to 1.0

playSound

public void playSound(java.lang.String path,
                      java.lang.String id)
Description copied from interface: RemoteAudio
Plays a sound effect on the client with the default gain. Plays the sound exactly once, with no delay.

Client sends a "#endsound id" directive back to the server when the sound finishes playing, unless it was interrupted with stopSound() or stopAllSounds().

Specified by:
playSound in interface RemoteAudio
Parameters:
path - relative path to the sound file, in any supported format, including midi.
id - the unique ID of this sound. It has to be unique, so you can't use (for example) the hashcode of the path to the file, since more than one of the same sound may be playing at once. Usually you pass the hashcode of the object that emitted the sound.

playSound

public void playSound(java.lang.String path,
                      java.lang.String id,
                      int repeats,
                      int repeatDelay,
                      double gain)
Description copied from interface: RemoteAudio
Plays the specified sound effect with custom parameters. Client sends a "#endsound id" directive back to the server when the sound finishes playing, unless it was interrupted with stopSound() or stopAllSounds().

Specified by:
playSound in interface RemoteAudio
Parameters:
path - the relative path to the sound file, in any supported format, including midi.
id - the unique ID of this sound. It has to be unique, so you can't use (for example) the hashcode of the path to the file, since more than one of the same sound may be playing at once. Usually you pass the hashcode of the object that emitted the sound.
repeats - number of times the client should repeat the piece before stopping and sending a notification back to the server. A value of 0 means don't repeat; just play the track once. A value of -1 means repeat indefinitely, until explicitly stopped.
repeatDelay - number of milliseconds to pause between repeats, if we're repeating. Negative values are interpreted as zero (no delay).
gain - the volume for this track, from 0.0 to 1.0. Values outside the range are clipped to 0.0 or 1.0.

stopSound

public void stopSound(java.lang.String id)
Description copied from interface: RemoteAudio
Stops the specified sound effect.

Specified by:
stopSound in interface RemoteAudio
Parameters:
id - the unique ID of the sound effect. The client will not send an "#endsound" back to the server.

stopAllSounds

public void stopAllSounds()
Description copied from interface: RemoteAudio
Stops all of the currently playing sounds on the client. Does not stop the background music or any currently-playing alerts. No notifications are sent back from theclient.

Specified by:
stopAllSounds in interface RemoteAudio

setSoundGain

public void setSoundGain(java.lang.String id,
                         double gain)
Description copied from interface: RemoteAudio
Sets the volume of a particular sound playing on the client.

Specified by:
setSoundGain in interface RemoteAudio
Parameters:
gain - the new background music gain, from 0.0 to 1.0
id - the unique track ID for the sound to modify

pauseSound

public void pauseSound(java.lang.String id)
Description copied from interface: RemoteAudio
Pauses a particular sound. The sound will stop playing on the client, and resume when we call resumeSound() with this track id. If the sound is stopped with stop() after pausing it, then it cannot be resumed, and will ignore the resumeSound() request.

Specified by:
pauseSound in interface RemoteAudio
Parameters:
id - the unique track id of the sound to resume

resumeSound

public void resumeSound(java.lang.String id)
Description copied from interface: RemoteAudio
Resumes a particular sound. The sound will resume on the client, unless it was stopped after it was paused.

Specified by:
resumeSound in interface RemoteAudio
Parameters:
id - the unique track id of the sound to resume

addMessageListener

public void addMessageListener(MessageListener l)
Description copied from interface: Commandable
Adds a MessageListener to be notified whenever this Commandable receives a message via a call to one of its message() methods.

Specified by:
addMessageListener in interface Commandable

removeMessageListener

public void removeMessageListener(MessageListener l)
Description copied from interface: Commandable
Removes a listener previously added with addMessageListener().

Specified by:
removeMessageListener in interface Commandable

fireMessageReceived

public void fireMessageReceived(java.lang.String msg,
                                byte style)