|
||||||||||
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.EventImpl
Wyvern's concrete implementation of the CommandEvent interface.
This class provides some parsing of the command string. In particular, it parses the verb (automatically, from the constructor), the ARGV array on demand when getArgs() is called, and the argument string on demand when getArgString() is called.
A command goes through several parsing phases, in the following order:
Field Summary | |
protected Commandable |
agent_
|
protected boolean |
appendToFile_
|
protected java.lang.String |
argString_
|
protected boolean |
argStringParsed_
|
protected java.lang.String[] |
argv_
|
protected boolean |
argvParsed_
|
protected long |
delay_
|
protected java.lang.String |
failureMessage_
|
protected CommandFilter[] |
filterObjects_
A list of CommandFilters parsed from the filter expressions we found in the command. |
protected java.lang.String[] |
filters_
A list of filter expressions that we found within the player's command. |
protected Command |
handler_
|
protected GameMap |
map_
|
protected boolean |
modified_
|
protected java.lang.String |
originalText_
|
protected boolean |
playerOriginated_
|
protected java.io.File |
redirectFile_
If the command ends with " > [filename]", then any calls to message() for the event will be redirected into the specified filename, replacing the existing contents of the file. |
protected boolean |
redirecting_
|
protected boolean |
sendToAgent_
|
protected java.lang.String |
successMessage_
|
protected java.lang.String |
verb_
|
protected boolean |
vetoed_
|
protected boolean |
wizParsed_
|
Fields inherited from class wyvern.kernel.properties.PList |
readOnly_ |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Constructor Summary | |
EventImpl()
|
|
EventImpl(CommandEvent c)
Constructs a new CommandEvent from the information in the passed CommandEvent. |
|
EventImpl(java.lang.String text,
Commandable agent)
Constructs a new EventImpl with the specified text and agent. |
Method Summary | |
java.util.List |
broadcast(java.lang.String msg)
Broadcasts a message to every player in sight of this object, not including the player who initiated it (if this is a player). |
java.util.List |
broadcast(java.lang.String msg,
byte style)
Broadcasts a message to every player in earshot of this object, not including the player who initiated it (if this is a player). |
java.util.List |
broadcast(java.lang.String msg,
Predicate p)
Sends the specified message to players in earshot of this object, not including the player who initiated it (if this is a player). |
java.util.List |
broadcast(java.lang.String msg,
Predicate p,
byte style)
Sends the specified message to player in sight of this object, not including the player who initiated it (if this is a player). |
java.util.List |
broadcast(java.lang.String msg,
Predicate p,
byte style,
int radius)
Sends the specified message to everyone in sight. |
boolean |
checkVeto()
If the event is vetoed, sends the event's failureMessage() to the event's agent. |
boolean |
fail()
Issues the event's failure-message to the event's agent. |
protected java.lang.String |
filterMessage(java.lang.String message)
Runs the message through any filters the player specified. |
java.util.List |
findAllMatches(Commandable agent,
Predicate p)
Finds all objects in the map, adjacent to or beneath the agent, that match the passed predicate. |
GameObject |
findByHashcode(java.lang.String hashcode)
Looks for an object by its hashcode. |
GameObject |
findInMap(Commandable agent,
Predicate p)
Searches for an object matching the specified predicate. |
GameObject |
findNeighbor(Commandable agent,
Predicate p)
Searches for an object on the ground under and adjacent to the agent. |
GameObject |
findObject(Commandable agent,
Predicate p)
Searches for an object matching the specified predicate. |
GameObject |
findTarget(Commandable agent,
Predicate p)
Searches for an object matching the specified predicate. |
Commandable |
getAgent()
Get the agent associated with this command event - usually a player or monster, but it can be anything with an event queue (such as a spell). |
java.lang.String[] |
getArgs()
Gets the arguments to this command, split into an array. |
java.lang.String |
getArgString()
Gets the arguments to the command as a whitespace-delimited string. |
long |
getDelay()
Returns the delay associated with this event. |
java.lang.String |
getFailureMessage()
Returns the "failure" message for this event. |
CommandFilter[] |
getFilterObjects()
Returns the parsed CommandFilter objects that will be applied to the message for this event. |
java.lang.String[] |
getFilters()
Returns the filter strings being applied to this event. |
Command |
getHandler()
Returns the Command that will handle this event, if the Command is different from the one that created the event. |
GameMap |
getMap()
Returns the map where this event is taking place. |
java.lang.String |
getOriginalText()
Returns the original text for this command event, before removing aliases, prepositions, etc. |
java.io.File |
getRedirectFile()
Returns the file that we're redirecting output to, if any. |
java.lang.String |
getSuccessMessage()
Returns the "success" message for this event. |
java.lang.String |
getVerb()
Returns the command verb for this event. |
boolean |
hasArgs()
Returns true if there were any arguments to the event. |
boolean |
isAppending()
Returns true if the redirect-to-file operator was "+>>" or ">>". |
boolean |
isModified()
Returns true if this event has been modified by a hook callback. |
boolean |
isMonster()
Returns true if the event's agent is a Monster (not a player). |
boolean |
isPlayer()
Returns true if the event's agent is a Player (or wizard). |
boolean |
isPlayerOriginated()
Returns true if a player actually typed in this command. |
boolean |
isRedirecting()
True if there was a redirect operator detected at the end of the command: ">", ">>", "+>", or "+>>". |
boolean |
isSendingToAgent()
Returns true if the redirect operator included a "+" to send the output to the agent as well. |
boolean |
isVetoed()
Returns true if this event has been vetoed by someone. |
boolean |
isWizard()
Returns true if the event's agent is a Wizard. |
static void |
main(java.lang.String[] args)
Function for testing the command parser. |
void |
message(java.lang.String msg)
Sends a message to the event's agent. |
void |
message(java.lang.String msg,
byte style)
Sends a message to the event's agent, in the specified TextStyle. |
boolean |
noArgs()
Returns true if there were no arguments to the event. |
protected void |
parseArgString()
Parses the original text and sets argString_ variable to the substring of the text starting at the 2nd token, or null if there are no args. |
protected void |
parseARGV()
Parses the original text and produces a String[] of tokens, following the verb. |
protected void |
parseVerb()
Parses the verb from the head of the command string. |
static java.lang.String |
profileParsing()
Returns information about how long we've spent just doing event parsing in this class. |
protected boolean |
redirectMessage(java.lang.String msg)
Sends the specified message to the output file. |
void |
runPostHooks(boolean success)
Runs one of the event's post hooks. 99.9% of the time this is called by the game kernel after execute() runs. |
void |
runPreHooks()
Runs the event's pre-hooks. |
GameObject |
searchInv(Predicate p)
Searches the agent's inventory for the first object matching the passed Predicate. |
GameObject |
searchInvAndMapNearby(Predicate p)
Searches for an object matching the specified predicate. |
GameObject |
searchInvAndMapUnder(Predicate p)
Searches for an object matching the specified predicate. |
GameObject |
searchInvByHashcode(java.lang.String hashcode)
Searches the agent's inventory for an object with the specified hashcode. |
GameObject |
searchMapNearby(Predicate p)
Searches for an object on the ground under and adjacent to the agent. |
GameObject |
searchMapUnder(Predicate p)
Searches for an object matching the specified predicate. |
GameObject |
searchMapUnderByHashcode(java.lang.String hashcode)
Searches agent's inventory and the ground under the agent for an object with the specified hashcode. |
void |
setAgent(Commandable agent)
Sets the agent for this event. |
void |
setArgs(java.lang.String[] args)
Sets the arguments for this command. |
void |
setDelay(long delay)
Sets the delay time to wait after this event is executed. |
void |
setFailureMessage(java.lang.String m)
Sets the "failure" message for this event. |
void |
setHandler(Command handler)
Sets the Command that will handle this event. |
void |
setMap(GameMap map)
Sets the map where this event is taking place. |
void |
setModified(boolean mod)
Sets the "modified" flag for this event. |
void |
setOriginalText(java.lang.String t)
This method is here for the sake of completeness, but it's not recommended that objects change the original text of a command, as other objects may rely on it. |
void |
setPlayerOriginated(boolean po)
Sets the event flag indicating that this command was originated by a player. |
void |
setSuccessMessage(java.lang.String m)
Sets the "success" message for this event. |
void |
setVerb(java.lang.String verb)
Convenience method; when constructing an event, a Command should set the verb; otherwise it'll have to be deduced from the command text, and the guess could be incorrect. |
void |
setVeto(boolean veto)
Sets the veto-flag for this event. |
java.lang.String |
toString()
Returns a string representation of this PropertyList. |
CommandEvent |
veto(java.lang.String msg)
Sets the veto flag and the failure message for the event. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Commandable agent_
protected GameMap map_
protected java.lang.String originalText_
protected java.lang.String verb_
protected java.lang.String argString_
protected boolean argStringParsed_
protected java.lang.String[] argv_
protected boolean argvParsed_
protected boolean wizParsed_
protected boolean modified_
protected boolean vetoed_
protected java.lang.String successMessage_
protected java.lang.String failureMessage_
protected long delay_
protected Command handler_
protected boolean playerOriginated_
protected boolean redirecting_
protected boolean appendToFile_
protected boolean sendToAgent_
protected java.io.File redirectFile_
protected java.lang.String[] filters_
protected CommandFilter[] filterObjects_
Constructor Detail |
public EventImpl()
public EventImpl(java.lang.String text, Commandable agent)
text
- the original text of the commandagent
- the Commandable (e.g. player) performing the commandpublic EventImpl(CommandEvent c)
c
- the initial eventMethod Detail |
public boolean isPlayer()
CommandEvent
isPlayer
in interface CommandEvent
public boolean isWizard()
CommandEvent
isWizard
in interface CommandEvent
public boolean isMonster()
CommandEvent
isMonster
in interface CommandEvent
public void setAgent(Commandable agent)
CommandEvent
setAgent
in interface CommandEvent
agent
- the new agent to perform the commandpublic Commandable getAgent()
CommandEvent
getAgent
in interface CommandEvent
public void setHandler(Command handler)
CommandEvent
setHandler
in interface CommandEvent
handler
- the new Command to execute the commandpublic Command getHandler()
CommandEvent
This is a somewhat rare occurrence; an example is the "move" command, which can result in a move, a push, an attack, or other events depending on the context. One Command will create the initial MoveEvent, and it may be transmogrified into an AttackEvent or other event, which requires a new handler to execute it.
This is the method the game engine calls to see if someone called setHandler() on the event during the hook callbacks.
getHandler
in interface CommandEvent
public java.lang.String getOriginalText()
CommandEvent
getOriginalText
in interface CommandEvent
public void setOriginalText(java.lang.String t)
CommandEvent
setOriginalText
in interface CommandEvent
public java.lang.String getVerb()
CommandEvent
getVerb
in interface CommandEvent
public void setVerb(java.lang.String verb)
CommandEvent
setVerb
in interface CommandEvent
verb
- the command verb (e.g. "move")public void setArgs(java.lang.String[] args)
CommandEvent
setArgs
in interface CommandEvent
args
- the arguments to use to interpret the commandpublic boolean hasArgs()
CommandEvent
hasArgs
in interface CommandEvent
public boolean noArgs()
CommandEvent
noArgs
in interface CommandEvent
public java.lang.String[] getArgs()
CommandEvent
getArgs
in interface CommandEvent
public java.lang.String getArgString()
CommandEvent
getArgString
in interface CommandEvent
public void setVeto(boolean veto)
CommandEvent
If you want to use the default failure message, you can call this method to set the flag. This method can also be used to clear the veto flag, meaning you want to un-veto the event.
setVeto
in interface CommandEvent
veto
- true to veto the event.public boolean isVetoed()
CommandEvent
isVetoed
in interface CommandEvent
public boolean checkVeto()
CommandEvent
checkVeto
in interface CommandEvent
public CommandEvent veto(java.lang.String msg)
CommandEvent
veto
in interface CommandEvent
msg
- the failure message to send to the agent (i.e.
the reason for vetoing the event).
public boolean fail()
CommandEvent
fail
in interface CommandEvent
public void setSuccessMessage(java.lang.String m)
CommandEvent
setSuccessMessage
in interface CommandEvent
m
- the message to display if the event succeeds.public java.lang.String getSuccessMessage()
CommandEvent
getSuccessMessage
in interface CommandEvent
public void setFailureMessage(java.lang.String m)
CommandEvent
setFailureMessage
in interface CommandEvent
m
- the message to display if the event fails.public java.lang.String getFailureMessage()
CommandEvent
getFailureMessage
in interface CommandEvent
public void setModified(boolean mod)
CommandEvent
setModified
in interface CommandEvent
mod
- true to mark the event as modifiedpublic boolean isModified()
CommandEvent
isModified
in interface CommandEvent
public void setDelay(long delay)
CommandEvent
setDelay
in interface CommandEvent
delay
- the command delay in millisecondspublic long getDelay()
CommandEvent
getDelay
in interface CommandEvent
public boolean isPlayerOriginated()
CommandEvent
isPlayerOriginated
in interface CommandEvent
public void setPlayerOriginated(boolean po)
CommandEvent
setPlayerOriginated
in interface CommandEvent
po
- true if it was originated by a user, via the client.public GameObject findNeighbor(Commandable agent, Predicate p)
CommandEvent
NOTE: If you're coding a command that looks for a target at the agent's feet first, use findObject() instead. Otherwise you'll get weird bugs if there's an item with the same name next to the agent, since this may find that one first.
findNeighbor
in interface CommandEvent
agent
- the GameObject to look aroundp
- a Predicate to use for searching the map
public GameObject findObject(Commandable agent, Predicate p)
CommandEvent
findObject
in interface CommandEvent
agent
- the agent to check (must be in a map)p
- the predicate used to tell which object to grab.
public GameObject findTarget(Commandable agent, Predicate p)
CommandEvent
findTarget
in interface CommandEvent
agent
- the agent to look nearp
- the predicate to use to locate the object
public GameObject findInMap(Commandable agent, Predicate p)
CommandEvent
findInMap
in interface CommandEvent
agent
- the agent to check (must be in a map)p
- the predicate used to tell which object to grab.
public java.util.List findAllMatches(Commandable agent, Predicate p)
CommandEvent
findAllMatches
in interface CommandEvent
agent
- the agent to check (must be in a map)p
- the predicate used to tell which object to grab.
public GameObject findByHashcode(java.lang.String hashcode)
CommandEvent
findByHashcode
in interface CommandEvent
hashcode
- the hash code of the object to retrieve
public GameObject searchInv(Predicate p)
CommandEvent
searchInv
in interface CommandEvent
p
- a predicate to test the objects in inventory
public GameObject searchMapUnder(Predicate p)
CommandEvent
searchMapUnder
in interface CommandEvent
p
- the predicate used to tell which object to grab.
public GameObject searchMapNearby(Predicate p)
CommandEvent
NOTE: If you're coding a command that looks for a target at the agent's feet first, use findObject() instead. Otherwise you'll get weird bugs if there's an item with the same name next to the agent, since this may find that one first.
searchMapNearby
in interface CommandEvent
p
- a Predicate to use for searching the map
public GameObject searchInvAndMapUnder(Predicate p)
CommandEvent
searchInvAndMapUnder
in interface CommandEvent
p
- the predicate to use to locate the object
public GameObject searchInvAndMapNearby(Predicate p)
CommandEvent
searchInvAndMapNearby
in interface CommandEvent
p
- the predicate used to tell which object to grab.
public GameObject searchInvByHashcode(java.lang.String hashcode)
CommandEvent
searchInvByHashcode
in interface CommandEvent
hashcode
- the object's hashcode, as a string
public GameObject searchMapUnderByHashcode(java.lang.String hashcode)
CommandEvent
searchMapUnderByHashcode
in interface CommandEvent
hashcode
- the object's hashcode, as a string
public java.util.List broadcast(java.lang.String msg)
Broadcaster
broadcast
in interface Broadcaster
msg
- the message to broadcast.
public java.util.List broadcast(java.lang.String msg, byte style)
Broadcaster
broadcast
in interface Broadcaster
msg
- the message to broadcast.style
- the RPCConstants.TextStyle to use
public java.util.List broadcast(java.lang.String msg, Predicate p)
Broadcaster
broadcast
in interface Broadcaster
msg
- the message to sendp
- an optional predicate used to filter the recipients.
If p is false for a potential recipient, the message is not
delivered to that recipient.
public java.util.List broadcast(java.lang.String msg, Predicate p, byte style)
Broadcaster
broadcast
in interface Broadcaster
msg
- the message to sendp
- an optional predicate used to filter the recipients.
If p is false for a potential recipient, the message is not
delivered to that recipient.style
- the RPCConstants.TextStyle to use
public java.util.List broadcast(java.lang.String msg, Predicate p, byte style, int radius)
Broadcaster
broadcast
in interface Broadcaster
msg
- the message to sendp
- an optional predicate used to filter the recipients.
If p is false for a potential recipient, the message is not
delivered to that recipient.style
- the RPCConstants.TextStyle to useradius
- the radius around the player to broadcast to.
Includes the player's location, so a radius of 7 would cover
their whole view.
public void runPostHooks(boolean success)
CommandEvent
runPostHooks
in interface CommandEvent
success
- true to run the post hook, false for failed hookpublic void runPreHooks()
CommandEvent
runPreHooks
in interface CommandEvent
public void setMap(GameMap map)
CommandEvent
setMap
in interface CommandEvent
map
- the GameMap where the event is happening. This is
primarily important for where the map-hooks for the event will
be run.public GameMap getMap()
CommandEvent
getMap
in interface CommandEvent
protected void parseVerb()
protected void parseARGV()
protected void parseArgString()
public static java.lang.String profileParsing()
public void message(java.lang.String msg)
CommandEvent
message
in interface CommandEvent
msg
- the message to print.public void message(java.lang.String msg, byte style)
CommandEvent
message
in interface CommandEvent
msg
- the messagestyle
- the Kernel.TextStyle constantpublic java.lang.String[] getFilters()
CommandEvent
getFilters
in interface CommandEvent
public CommandFilter[] getFilterObjects()
CommandEvent
getFilterObjects
in interface CommandEvent
public boolean isRedirecting()
CommandEvent
isRedirecting
in interface CommandEvent
public boolean isAppending()
CommandEvent
isAppending
in interface CommandEvent
public boolean isSendingToAgent()
CommandEvent
isSendingToAgent
in interface CommandEvent
public java.io.File getRedirectFile()
CommandEvent
getRedirectFile
in interface CommandEvent
protected java.lang.String filterMessage(java.lang.String message)
message
- the message to filter
protected boolean redirectMessage(java.lang.String msg)
msg
- the message to append to the file, or to overwrite
the file contents with
public java.lang.String toString()
PList
toString
in class PList
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |