|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.properties.PList wyvern.kernel.maps.MapObject wyvern.kernel.commands.AbstractCommandable
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.
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface wyvern.lib.Broadcaster |
broadcast, broadcast, broadcast, broadcast, broadcast |
Field Detail |
protected transient EventQueue queue_
public transient HookList hookList_
protected transient volatile boolean started_
Constructor Detail |
public AbstractCommandable()
Method Detail |
public java.lang.String getName()
Commandable
getName
in interface Commandable
public void setName(java.lang.String name)
Commandable
setName
in interface Commandable
name
- the name for the commandablepublic java.lang.String getCapName()
Commandable
getCapName
in interface Commandable
public void command(java.lang.String command, boolean user)
Commandable
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
in interface Commandable
command
- the command to enqueueuser
- true if the command was initiated by the userpublic void commandNow(java.lang.String command)
Commandable
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.
commandNow
in interface Commandable
command
- the command string plus argspublic void command(java.lang.String cmd)
Commandable
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
in interface Commandable
cmd
- the command string, including any args.public Command getCommand(CommandEvent event)
Commandable
Asks the Commandable to look in its table of registered commands to find a Command to handle the specified command.
getCommand
in interface Commandable
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)
Commandable
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.
message
in interface Commandable
msg
- the message to sendpublic void message(java.lang.String msg, byte style)
Commandable
message
in interface Commandable
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)
Commandable
message
in interface Commandable
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)
Commandable
sendPicture
in interface Commandable
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)
Commandable
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.
sendPicture
in interface Commandable
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)
Commandable
When the monster or player enters the command, the passed callback object will be notified so it can execute the command.
registerCommand
in interface Commandable
command
- the command verb to registerhandler
- the Command callback object that implements the
specified commandpublic void unregisterCommand(java.lang.String command, Command handler)
Commandable
unregisterCommand
in interface Commandable
command
- the command verb to registerhandler
- the Command object implementing the commandpublic EventQueue getQueue()
Commandable
getQueue
in interface Commandable
public EventQueue getCombatQueue()
Commandable
getCombatQueue
in interface Commandable
public AI getAI()
Commandable
getAI
in interface Commandable
public void setAI(AI ai)
Commandable
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).
setAI
in interface Commandable
ai
- an AI implementation to drive this monsterpublic void start()
Commandable
start
in interface Commandable
public void stop()
Commandable
stop
in interface Commandable
public boolean isStarted()
Commandable
isStarted
in interface Commandable
public Inventory getInventory()
Commandable
getInventory
in interface Commandable
public java.lang.String[] getHooks()
Hookable
The list doesn't include names of default hooks for built-in commands.
getHooks
in interface Hookable
public void addHook(HookCallback callback, java.lang.String hookName)
Hookable
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.
addHook
in interface Hookable
callback
- the HookCallback to notify when the hook is run.hookName
- the name of the hook list to register on.public void removeHook(HookCallback callback, java.lang.String hookName)
Hookable
removeHook
in interface Hookable
callback
- the HookCallback to remove from the listhookName
- the name of the hook list to unregister from.public void runPreHook(CommandEvent event)
Hookable
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.
runPreHook
in interface Hookable
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.public void runPostHook(CommandEvent event)
Hookable
runPostHook
in interface Hookable
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.public void runFailedPostHook(CommandEvent event)
Hookable
Changing the event parameters will have no effect at this point.
runFailedPostHook
in interface Hookable
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.public void addMethodHook(MethodHookCallback callback, java.lang.String methodName)
MethodHookable
addMethodHook
in interface MethodHookable
addMethodHook
in class MapObject
public void removeMethodHook(MethodHookCallback callback, java.lang.String methodName)
MethodHookable
removeMethodHook
in interface MethodHookable
removeMethodHook
in class MapObject
public void runMethodHook(java.lang.String hookName, java.lang.Object data)
MethodHookable
runMethodHook
in interface MethodHookable
runMethodHook
in class MapObject
public Point getFiringPoint(int dir)
Commandable
Finds the first map location in the specified direction that isn't occupied by the monster, starting at the monster's reference location.
getFiringPoint
in interface Commandable
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()
Commandable
isTelnet
in interface Commandable
public void destroy()
GameObject
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.
destroy
in interface GameObject
destroy
in class MapObject
public void addAttack(Attack attack)
Commandable
addAttack
in interface Commandable
attack
- an Attack to addpublic void removeAttack(Attack attack)
Commandable
removeAttack
in interface Commandable
attack
- the Attack to removeprotected void ensureEventQueue()
protected void ensureAI()
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.
protected void checkAnimated(java.lang.String bitmap)
bitmap
- the database bitmap stringpublic int getEncumbrance()
Commandable
getEncumbrance
in interface Commandable
public void setEncumbrance(int encumbrance)
Commandable
setEncumbrance
in interface Commandable
encumbrance
- a number from 0 (unencumbered) to 4 (immobilized)public boolean isCommandable()
GameObject
isCommandable
in interface GameObject
isCommandable
in class MapObject
public HookList getHookList()
Hookable
getHookList
in interface Hookable
public void playAlert(java.lang.String path)
RemoteAudio
Can't be stopped, so use with care.
playAlert
in interface RemoteAudio
path
- the relative path to the sound filepublic void playAlert(java.lang.String path, int repeats, int repeatDelay, double gain)
RemoteAudio
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.
playAlert
in interface RemoteAudio
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.0public void playDefaultMusic()
RemoteAudio
playDefaultMusic
in interface RemoteAudio
public void playPriorityMusic(java.lang.String path)
RemoteAudio
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.
playPriorityMusic
in interface RemoteAudio
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. public void playPriorityMusic(java.lang.String path, int repeats, int repeatDelay, double gain)
RemoteAudio
playPriorityMusic
in interface RemoteAudio
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.public void stopMusic()
RemoteAudio
stopMusic
in interface RemoteAudio
public void setMusicGain(double gain)
RemoteAudio
setMusicGain
in interface RemoteAudio
gain
- the new background music gain, from 0.0 to 1.0public void playSound(java.lang.String path, java.lang.String id)
RemoteAudio
Client sends a "#endsound id" directive back to the server when the sound finishes playing, unless it was interrupted with stopSound() or stopAllSounds().
playSound
in interface RemoteAudio
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.public void playSound(java.lang.String path, java.lang.String id, int repeats, int repeatDelay, double gain)
RemoteAudio
playSound
in interface RemoteAudio
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.public void stopSound(java.lang.String id)
RemoteAudio
stopSound
in interface RemoteAudio
id
- the unique ID of the sound effect. The client
will not send an "#endsound" back to the server.public void stopAllSounds()
RemoteAudio
stopAllSounds
in interface RemoteAudio
public void setSoundGain(java.lang.String id, double gain)
RemoteAudio
setSoundGain
in interface RemoteAudio
gain
- the new background music gain, from 0.0 to 1.0id
- the unique track ID for the sound to modifypublic void pauseSound(java.lang.String id)
RemoteAudio
pauseSound
in interface RemoteAudio
id
- the unique track id of the sound to resumepublic void resumeSound(java.lang.String id)
RemoteAudio
resumeSound
in interface RemoteAudio
id
- the unique track id of the sound to resumepublic void addMessageListener(MessageListener l)
Commandable
addMessageListener
in interface Commandable
public void removeMessageListener(MessageListener l)
Commandable
removeMessageListener
in interface Commandable
public void fireMessageReceived(java.lang.String msg, byte style)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |