|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.monsters.Talker
A Talker property allows you to make a monster or NPC reply to a query given via the "talk" command. It allows you to add cycling or random responses, and you can answer more than one subject string with the same response or set of responses.
Nested Class Summary | |
class |
Talker.Reply
Encapsulates a reply and any attributes it might have. |
class |
Talker.Response
Keeps track of the response(s) to a given subject. |
Field Summary | |
protected java.lang.String |
npcName_
the name of the NPC currently talking. |
protected java.util.HashMap |
topics_
Subjects that the talker knows about. |
Constructor Summary | |
Talker()
Constructs a new Talker property with no filename. |
|
Talker(java.lang.String name)
Constructs a new Talker object. |
Method Summary | |
protected void |
barf(java.lang.String type,
java.lang.String name)
Throws a semi-descriptive parse error. |
protected void |
combatElement(Talker.Response r,
java.util.LinkedList out)
Adds a |
Talker.Response |
createResponse(java.util.List keywords,
java.lang.String reply,
boolean nosay)
Creates an initial response with the specified keywords and initial reply. |
java.lang.String |
getCombatMessage()
Returns a combat message. |
protected java.lang.String |
getNodeText(org.w3c.dom.Element node)
Returns the text from a text element. |
Talker.Response |
getResponse(java.lang.String query)
Looks up the Response for a given subject. |
java.util.Set |
getResponses()
Returns all the Responses for this Talker. |
boolean |
isEmpty()
True if the talker is empty. |
boolean |
knowsSubject(java.lang.String subject)
Returns true if we have a Response for the passed subject. |
Talker |
makeClone()
Creates a clone of this Talker object. |
void |
newSubject(java.util.List keywords,
Talker.Response r)
Sets a new subject with an existing response. |
protected void |
parseChance(org.w3c.dom.Element node,
Talker.Response response)
Parses a "chance" attribute in a topic or combat node. |
protected void |
parseCombatMessage(org.w3c.dom.Element node)
Parses a combat message to use when the monster is in combat. |
protected void |
parseElement(org.w3c.dom.Element node)
Parses an XML element from the talk data. |
protected void |
parseTopic(org.w3c.dom.Element node)
Parses a talk topic. |
void |
readData(org.w3c.dom.Node node)
Tells the object to parse its externalized representation from a list of lines. |
void |
removeSubject(java.util.List keywords)
Removes the list of keywords from the Talker. |
java.lang.String |
removeUnnecessaryWords(java.lang.String s)
Removes any unnecessary text from the subject that you are asking about. |
void |
setName(java.lang.String name)
Sets the name of the NPC doing the talking. |
boolean |
shouldWrite()
Returns true if we should write the object at all. |
java.lang.String |
talk(java.lang.String query,
java.lang.String player)
This method takes a query (and the name of the player who's talking) and figures out what to say by reading a "talk file". |
protected void |
topicElement(Talker.Response r,
java.util.LinkedList out)
Adds a |
java.util.List |
writeData()
Tells the object to write its data out to a text file. |
protected void |
writeReplies(Talker.Response r,
java.util.LinkedList out)
Writes the reply or random/cyclic replies. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String npcName_
protected java.util.HashMap topics_
Constructor Detail |
public Talker()
public Talker(java.lang.String name)
name
- the name of the file to load, minus extension
(typically the NPC name this Talker is associated with).Method Detail |
public void setName(java.lang.String name)
public java.lang.String talk(java.lang.String query, java.lang.String player)
query
- the user's query string, minus the "talk" verbplayer
- the name of the player doing the query
public java.lang.String getCombatMessage()
public java.lang.String removeUnnecessaryWords(java.lang.String s)
public Talker.Response getResponse(java.lang.String query)
query
- the subject/keyword to look up
public boolean knowsSubject(java.lang.String subject)
public void readData(org.w3c.dom.Node node) throws java.lang.Exception
readData
in interface SelfExternalizable
node
- the XML DOM representation of the externalized
bean object. Its child could be a text node, in which case
the bean has to do all the parsing for the data. It could
also wrap a series of elements (e.g. archetypes), in which case
the bean may wish to leverage the XML parsing utilities that
the game provides in the ArchetypeManager.
java.lang.Exception
protected void parseElement(org.w3c.dom.Element node) throws java.lang.Exception
node
- the element
java.lang.Exception
protected void parseTopic(org.w3c.dom.Element node)
protected void parseCombatMessage(org.w3c.dom.Element node)
protected java.lang.String getNodeText(org.w3c.dom.Element node)
node
- the text node
beginning of the line.protected void parseChance(org.w3c.dom.Element node, Talker.Response response)
protected void barf(java.lang.String type, java.lang.String name)
public void removeSubject(java.util.List keywords)
public void newSubject(java.util.List keywords, Talker.Response r)
public Talker.Response createResponse(java.util.List keywords, java.lang.String reply, boolean nosay)
public java.util.Set getResponses()
public boolean isEmpty()
public java.util.List writeData() throws java.lang.Exception
writeData
in interface SelfExternalizable
java.lang.Exception
public boolean shouldWrite()
shouldWrite
in interface SelfExternalizable
protected void combatElement(Talker.Response r, java.util.LinkedList out)
protected void topicElement(Talker.Response r, java.util.LinkedList out)
r
- the response we're printingout
- the list of lines to add the XML toprotected void writeReplies(Talker.Response r, java.util.LinkedList out)
r
- the responseout
- the linked list of lines to outputpublic Talker makeClone()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |