|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectwyvern.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 Commandablepublic void setName(java.lang.String name)
Commandable
setName in interface Commandablename - the name for the commandablepublic java.lang.String getCapName()
Commandable
getCapName in interface Commandable
public void command(java.lang.String command,
boolean user)
CommandableThis 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 Commandablecommand - the command to enqueueuser - true if the command was initiated by the userpublic void commandNow(java.lang.String command)
CommandableThis 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 Commandablecommand - the command string plus argspublic void command(java.lang.String cmd)
CommandableThis 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 Commandablecmd - the command string, including any args.public Command getCommand(CommandEvent event)
CommandableAsks the Commandable to look in its table of registered commands to find a Command to handle the specified command.
getCommand in interface Commandableevent - 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)
CommandableMostly 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 Commandablemsg - the message to send
public void message(java.lang.String msg,
byte style)
Commandable
message in interface Commandablemsg - 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 Commandablestrings - 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 Commandablepath - 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.ImageFlags
public void sendPicture(java.lang.String path,
java.lang.String title)
CommandableThe 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 Commandablepath - 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
public void registerCommand(java.lang.String command,
Command handler)
CommandableWhen the monster or player enters the command, the passed callback object will be notified so it can execute the command.
registerCommand in interface Commandablecommand - the command verb to registerhandler - the Command callback object that implements the
specified command
public void unregisterCommand(java.lang.String command,
Command handler)
Commandable
unregisterCommand in interface Commandablecommand - the command verb to registerhandler - the Command object implementing the commandpublic EventQueue getQueue()
Commandable
getQueue in interface Commandablepublic EventQueue getCombatQueue()
Commandable
getCombatQueue in interface Commandablepublic AI getAI()
Commandable
getAI in interface Commandablepublic void setAI(AI ai)
CommandableYou 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 Commandableai - an AI implementation to drive this monsterpublic void start()
Commandable
start in interface Commandablepublic void stop()
Commandable
stop in interface Commandablepublic boolean isStarted()
Commandable
isStarted in interface Commandablepublic Inventory getInventory()
Commandable
getInventory in interface Commandablepublic java.lang.String[] getHooks()
HookableThe 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)
HookableThe 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 Hookablecallback - 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 Hookablecallback - the HookCallback to remove from the listhookName - the name of the hook list to unregister from.public void runPreHook(CommandEvent event)
HookableCallbacks 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 Hookableevent - 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 Hookableevent - 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)
HookableChanging the event parameters will have no effect at this point.
runFailedPostHook in interface Hookableevent - 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 MethodHookableaddMethodHook in class MapObject
public void removeMethodHook(MethodHookCallback callback,
java.lang.String methodName)
MethodHookable
removeMethodHook in interface MethodHookableremoveMethodHook in class MapObject
public void runMethodHook(java.lang.String hookName,
java.lang.Object data)
MethodHookable
runMethodHook in interface MethodHookablerunMethodHook in class MapObjectpublic Point getFiringPoint(int dir)
CommandableFinds 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 Commandabledir - 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 Commandablepublic void destroy()
GameObjectThis 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 GameObjectdestroy in class MapObjectpublic void addAttack(Attack attack)
Commandable
addAttack in interface Commandableattack - an Attack to addpublic void removeAttack(Attack attack)
Commandable
removeAttack in interface Commandableattack - 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 Commandablepublic void setEncumbrance(int encumbrance)
Commandable
setEncumbrance in interface Commandableencumbrance - a number from 0 (unencumbered) to 4 (immobilized)public boolean isCommandable()
GameObject
isCommandable in interface GameObjectisCommandable in class MapObjectpublic HookList getHookList()
Hookable
getHookList in interface Hookablepublic void playAlert(java.lang.String path)
RemoteAudioCan't be stopped, so use with care.
playAlert in interface RemoteAudiopath - the relative path to the sound file
public void playAlert(java.lang.String path,
int repeats,
int repeatDelay,
double gain)
RemoteAudioParameters 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 RemoteAudiopath - 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()