wyvern.kernel.monsters
Class RandomMessages

java.lang.Object
  extended bywyvern.kernel.monsters.RandomMessages
All Implemented Interfaces:
SelfExternalizable

public class RandomMessages
extends java.lang.Object
implements SelfExternalizable

A monster may choose to emit random messages, either during normal operation or during combat, by use of this class.

To use it, put one on the monster like so:

 
    Gragh!
    Brains!
 

 To do a different set of messages for non-combat moves, add
 another object to the property list under the name "random-msgs"
 instead of "combat-msgs". 

If the first line in the bean body is "chance {num}", where num is a percentage chance that the monster will emit a message on that turn, the AI will use this percentage; otherwise it uses the default. At the moment there's no support for any fancier features, such as having the monster emote the message ("Ogre glares at you.") or having different probabilities for each message. You can fake different probabilities to a limited extent by putting more common messages in the list more than once.

If you really need fancier messaging, you have a few options:

Version:
1.0, Oct 3, 2000
Author:
Steve Yegge

Field Summary
protected  int chance_
           
static int DEFAULT_CHANCE
          The chance a monster will emit a message during combat or when moving, depending on which property this object is stored under on the monster.
protected  java.util.List messages_
           
 
Constructor Summary
RandomMessages()
          Constructs a new RandomMessages
 
Method Summary
 java.lang.String chooseRandomMessage()
          Chooses a random message from the list.
 int getChance()
          Returns the chance the monster will emit a message from this list.
 java.lang.String[] getMessages()
          Returns the messages in this list.
 int getSize()
          Returns the number of messages in this list.
 void readData(org.w3c.dom.Node bean)
          Tells the object to parse its externalized representation from a list of lines.
 boolean shouldWrite()
          Returns true if we should write the object at all.
 java.util.List writeData()
          Tells the object to write its properties out to a text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHANCE

public static final int DEFAULT_CHANCE
The chance a monster will emit a message during combat or when moving, depending on which property this object is stored under on the monster.

See Also:
Constant Field Values

messages_

protected java.util.List messages_

chance_

protected int chance_
Constructor Detail

RandomMessages

public RandomMessages()
Constructs a new RandomMessages

Method Detail

readData

public void readData(org.w3c.dom.Node bean)
              throws java.lang.Exception
Tells the object to parse its externalized representation from a list of lines.

Specified by:
readData in interface SelfExternalizable
Parameters:
bean - 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 and XMLWrapper.

Throws:
java.lang.Exception

writeData

public java.util.List writeData()
                         throws java.lang.Exception
Tells the object to write its properties out to a text file. The object does not need to write the block braces; they are written to the stream by the system.

Specified by:
writeData in interface SelfExternalizable
Returns:
a String representation that can be written to the text file.
Throws:
java.lang.Exception

shouldWrite

public boolean shouldWrite()
Returns true if we should write the object at all.

Specified by:
shouldWrite in interface SelfExternalizable
Returns:
false if we're empty

chooseRandomMessage

public java.lang.String chooseRandomMessage()
Chooses a random message from the list.

Returns:
a message to emit, or null if we didn't roll high enough

getSize

public int getSize()
Returns the number of messages in this list.


getChance

public int getChance()
Returns the chance the monster will emit a message from this list.


getMessages

public java.lang.String[] getMessages()
Returns the messages in this list.