wyvern.lib
Interface Commandable

All Superinterfaces:
Broadcaster, GameObject, Hookable, MethodHookable, PropertyList, RemoteAudio
All Known Subinterfaces:
Monster, Player
All Known Implementing Classes:
AbstractCommandable, MonsterImpl, PlayerImpl

public interface Commandable
extends Hookable, GameObject, RemoteAudio

A Commandable is an object that can receive and process events. This includes monsters and players, as well as some game-engine entities that do event-driven processing, such as the camera manager, the player-login manager, the timer system, and others.

Nearly all the interesting events that take place in the game originate as commands. A command is a text string, where the first word is the command verb and the remainder of the string (if any) is the command arguments.

Commands are issued by calling command() or commandNow() to wrap the command with a CommandEvent object and put it in the Commandable's EventQueue. Examples include:

Commands are executed in the order they're placed in the queue. Every Commandable has at least one EventQueue - players have two: the standard queue, an extra one for combat commands, so they can do other things while fighting.

Version:
1.0, 10/03/97
Author:
Steve Yegge

Field Summary
 
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
 
Method Summary
 void addAttack(Attack attack)
          Adds an attack to our list of attacks.
 void addMessageListener(MessageListener listener)
          Adds a MessageListener to be notified whenever this Commandable receives a message via a call to one of its message() methods.
 void command(java.lang.String command)
          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.
 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.
 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 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 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 removeMessageListener(MessageListener listener)
          Removes a listener previously added with addMessageListener().
 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 setName(java.lang.String name)
          Gives the commandable a name, stored under the "name" property.
 void start()
          "Starts" the monster.
 void stop()
          "Stops" the monster by destroying its event queue.
 void unregisterCommand(java.lang.String command, Command handler)
          Unregisters a command.
 
Methods inherited from interface wyvern.lib.Hookable
addHook, getHookList, getHooks, removeHook, runFailedPostHook, runPostHook, runPreHook
 
Methods inherited from interface wyvern.lib.MethodHookable
addMethodHook, removeMethodHook, runMethodHook
 
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, destroy, 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, isCommandable, 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
 
Methods inherited from interface wyvern.common.net.RemoteAudio
pauseSound, playAlert, playAlert, playDefaultMusic, playPriorityMusic, playPriorityMusic, playSound, playSound, resumeSound, setMusicGain, setSoundGain, stopAllSounds, stopMusic, stopSound
 

Method Detail

command

public void command(java.lang.String command)
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.

Parameters:
command - the command string, including any args.

commandNow

public void commandNow(java.lang.String command)
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.

Parameters:
command - the command string plus args

command

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

Parameters:
command - the command to enqueue
user - true if the command was initiated by the user

getCommand

public Command getCommand(CommandEvent event)
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.

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

Parameters:
msg - the message to send

message

public void message(java.lang.String msg,
                    byte style)
Sends a message to the client using the specified style.

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

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

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

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

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)
Unregisters a command. The specified handler object will no longer be notified if the user types the command.

Parameters:
command - the command verb to register
handler - the Command object implementing the command

getQueue

public EventQueue getQueue()
Returns the event queue for this object.

Returns:
the EventQueue used for queuing commands for this obj

getCombatQueue

public EventQueue getCombatQueue()
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.

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.

setName

public void setName(java.lang.String name)
Gives the commandable a name, stored under the "name" property.

Parameters:
name - the name for the commandable

getName

public java.lang.String getName()
Returns the name of this commandable

Returns:
the commandable's name. If it has no name, returns something suitable, such as its type.

getCapName

public java.lang.String getCapName()
Returns the capitalized version of the name.

Returns:
the name with the first letter capitalized.

start

public void start()
"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.


stop

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


isStarted

public boolean isStarted()
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.

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

setAI

public void setAI(AI ai)
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).

Parameters:
ai - an AI implementation to drive this monster

getAI

public AI getAI()
Returns the AI driving this monster.

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

getInventory

public Inventory getInventory()
Returns the commandable's inventory object, if any.

Returns:
an Inventory implementation

addAttack

public void addAttack(Attack attack)
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.

Parameters:
attack - an Attack to add

removeAttack

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

Parameters:
attack - the Attack to remove

getFiringPoint

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

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

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()
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.


setEncumbrance

public void setEncumbrance(int encumbrance)
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.

Parameters:
encumbrance - a number from 0 (unencumbered) to 4 (immobilized)

getEncumbrance

public int getEncumbrance()
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.

Returns:
a number from 0 (unencumbered) to 4 (immobilized)

addMessageListener

public void addMessageListener(MessageListener listener)
Adds a MessageListener to be notified whenever this Commandable receives a message via a call to one of its message() methods.


removeMessageListener

public void removeMessageListener(MessageListener listener)
Removes a listener previously added with addMessageListener().