|
||||||||||
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.commands.SimpleHandler
This class provides a simple, common-case implementation of the Command interface. Using the SimpleHandler you can handle a game command without worrying about events and event queues. The SimpleHandler will take care of the details.
To use the SimpleHandler class, subclass it and override addCommands() to add any commands you want it to handle. To set a delay for the commands, pass it to the constructor (usually a private/Singleton constructor). Then override handleEvent to perform the command. You can change the delay in handleEvent() if desired. You must return true if the command succeeded and false if it failed.
For commands for which there are parameters to the command that others may want to interact with, the SimpleHandler may not have sufficient flexibility. Use the Command interface to give yourself maximum control over what goes into the event for the command.
Field Summary | |
protected int |
delay_
|
Fields inherited from class wyvern.kernel.properties.PList |
readOnly_ |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Constructor Summary | |
SimpleHandler()
Constructs a new SimpleHandler with a command delay of zero. |
|
SimpleHandler(int delay)
Constructs a new SimpleHandler. |
Method Summary | |
abstract void |
addCommands(java.util.Map commands,
CommandList list)
Adds our commands. |
CommandEvent |
createEvent(CommandEvent e)
Creates a no-parameter event for the specified command. |
boolean |
execute(CommandEvent event)
Executes the specified CommandEvent. |
abstract boolean |
handleEvent(CommandEvent event)
Callback method for subclasses to handle their command. |
boolean |
knowsCommand(java.lang.String command)
By default, we know the command. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int delay_
Constructor Detail |
public SimpleHandler()
public SimpleHandler(int delay)
delay
- the time (in milliseconds) the command takes for the
agent to execute.Method Detail |
public abstract void addCommands(java.util.Map commands, CommandList list)
addCommands
in interface BuiltInCommand
commands
- a Map whose keys are the command verbs,
and whose values are references to the SimpleHandler
instance that wants to handle the command.list
- the Player, Monster, Vehicle or other CommandList
implementation for which addCommands() is being called.public boolean knowsCommand(java.lang.String command)
knowsCommand
in interface Command
command
- the command to check
public CommandEvent createEvent(CommandEvent e)
createEvent
in interface Command
e
- a "blank" CommandEvent containing only the
command text and the agent who's performing the command. This
initial event is created by the originator of the event (e.g.
the AI or player's command preprocessor).
public boolean execute(CommandEvent event)
execute
in interface Command
event
- the CommandEvent to execute
public abstract boolean handleEvent(CommandEvent event)
event
- a CommandEvent with various fields filled in:
the agent performing the command, the command verb and arguments,
the delay for the command, and success/failure messages.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |