|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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:
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.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 |
public void command(java.lang.String command)
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.
command
- the command string, including any args.public void commandNow(java.lang.String command)
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.
command
- the command string plus argspublic void command(java.lang.String command, boolean 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).
command
- the command to enqueueuser
- true if the command was initiated by the userpublic Command getCommand(CommandEvent event)
Asks the Commandable to look in its table of registered commands to find a Command to handle the specified command.
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.
public void message(java.lang.String msg)
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.
msg
- the message to sendpublic void message(java.lang.String msg, byte style)
msg
- the text to send.style
- the RPCConstants.TextStyle to use, for instance,
RPCConstants.TextStyle.TEXT_INFO for informational text.RPCConstants
public void message(java.lang.String[] strings, byte[] styles)
strings
- the message to send, broken up into piecesstyles
- an array (which must be the same length),
containing the style to use for each piece in the strings
array parameter.public void sendPicture(java.lang.String path, java.lang.String title, byte format, byte align, byte view, int flags)
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 valuealign
- 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 displayedflags
- RPCConstants.ImageFlagspublic void sendPicture(java.lang.String path, java.lang.String title)
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.
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 displayedpublic void registerCommand(java.lang.String command, Command handler)
When the monster or player enters the command, the passed callback object will be notified so it can execute the command.
command
- the command verb to registerhandler
- the Command callback object that implements the
specified commandpublic void unregisterCommand(java.lang.String command, Command handler)
command
- the command verb to registerhandler
- the Command object implementing the commandpublic EventQueue getQueue()
public EventQueue getCombatQueue()
public void setName(java.lang.String name)
name
- the name for the commandablepublic java.lang.String getName()
public java.lang.String getCapName()
public void start()
public void stop()
public boolean isStarted()
public void setAI(AI ai)
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).
ai
- an AI implementation to drive this monsterpublic AI getAI()
public Inventory getInventory()
public void addAttack(Attack attack)
attack
- an Attack to addpublic void removeAttack(Attack attack)
attack
- the Attack to removepublic Point getFiringPoint(int dir)
Finds the first map location in the specified direction that isn't occupied by the monster, starting at the monster's reference location.
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.
public boolean isTelnet()
public void setEncumbrance(int encumbrance)
encumbrance
- a number from 0 (unencumbered) to 4 (immobilized)public int getEncumbrance()
public void addMessageListener(MessageListener listener)
public void removeMessageListener(MessageListener listener)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |