wyvern.lib.commands.autobag
Class AutobagRules

java.lang.Object
  extended bywyvern.lib.commands.autobag.AutobagRules
All Implemented Interfaces:
AddRemoveNotify, HookCallback, SelfExternalizable

public class AutobagRules
extends java.lang.Object
implements SelfExternalizable, HookCallback, AddRemoveNotify

A persistent list of autobag rules. Keeps a list of AutobagRule objects, and knows how to read and write them as XML in the player's property list.

Version:
1.0, Dec 27, 2003
Author:
Steve Yegge

Constructor Summary
AutobagRules()
           
 
Method Summary
 void addHooks(Player p)
           
protected  void considerItem(GameObject item)
          Called when an item is picked up by our owner.
 void delete(int num)
           
 AutobagRule getRule(int number)
          Returns the rule at the specified position.
 java.util.List getRules()
          Returns the complete set of rules.
 void hookEvent(java.lang.String hook, CommandEvent e)
          Called after an item is picked up.
 boolean isEmpty()
          Returns true if there are no rules defined in this list.
 void notifyAdd(PropertyList list)
          Notifies the property that it's being added to a PropertyList.
 void notifyRemove(PropertyList list)
          Notifies the property that it's being removed from a PropertyList.
 void readData(org.w3c.dom.Node bean)
          Tells the object to parse its externalized representation from a list of lines.
 void removeHooks(Player p)
           
 boolean shouldWrite()
          Allows the object to determine whether it wants to be written out at all.
 int size()
           
 java.lang.String toString()
           
 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, wait, wait, wait
 

Constructor Detail

AutobagRules

public AutobagRules()
Method Detail

notifyAdd

public void notifyAdd(PropertyList list)
Description copied from interface: AddRemoveNotify
Notifies the property that it's being added to a PropertyList.

You should never assume that the passed value is a GameObject. Make sure to test it with instanceof (Java) or isInstance (Jython) first. Properties are added to Archetypes as well as GameObjects, so your AddRemoveNotify is likely to be called for both cases.

Specified by:
notifyAdd in interface AddRemoveNotify
Parameters:
list - the PropertyList whose property list we're being added to

notifyRemove

public void notifyRemove(PropertyList list)
Description copied from interface: AddRemoveNotify
Notifies the property that it's being removed from a PropertyList.

You should never assume that the passed value is a GameObject. Make sure to test it with instanceof (Java) or isInstance (Jython) first. Properties are added to Archetypes as well as GameObjects, so your AddRemoveNotify is likely to be called for both cases.

Specified by:
notifyRemove in interface AddRemoveNotify
Parameters:
list - the PropertyList we're being removed from

addHooks

public void addHooks(Player p)

removeHooks

public void removeHooks(Player p)

hookEvent

public void hookEvent(java.lang.String hook,
                      CommandEvent e)
Called after an item is picked up.

Specified by:
hookEvent in interface HookCallback
Parameters:
hook - the name of the hook, such as "movePreHook".
e - the CommandEvent encapsulating the event parameters

considerItem

protected void considerItem(GameObject item)
Called when an item is picked up by our owner.

Parameters:
item - the item that was picked up.

getRule

public AutobagRule getRule(int number)
Returns the rule at the specified position.


getRules

public java.util.List getRules()
Returns the complete set of rules. Can be null, but won't be empty.


size

public int size()

delete

public void delete(int num)

isEmpty

public boolean isEmpty()
Returns true if there are no rules defined in this list.


readData

public void readData(org.w3c.dom.Node bean)
              throws java.lang.Exception
Description copied from interface: SelfExternalizable
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.

Throws:
java.lang.Exception

writeData

public java.util.List writeData()
                         throws java.lang.Exception
Description copied from interface: SelfExternalizable
Tells the object to write its properties out to a text file.

Specified by:
writeData in interface SelfExternalizable
Returns:
a list of lines to be written to the text file, formatted appropriately. The lines include everything except the and tags, which are constructed and written automatically.
Throws:
java.lang.Exception

shouldWrite

public boolean shouldWrite()
Description copied from interface: SelfExternalizable
Allows the object to determine whether it wants to be written out at all. If the object determines that it's the equivalent of a null value (e.g. an item list with no items in it), it can return false and it won't go into the output file.

Specified by:
shouldWrite in interface SelfExternalizable
Returns:
true to write the object, false to skip it

toString

public java.lang.String toString()