wyvern.kernel.player
Class SpellListImpl

java.lang.Object
  extended bywyvern.kernel.player.SpellListImpl
All Implemented Interfaces:
MutableProperty, SelfExternalizable, SpellList

public class SpellListImpl
extends java.lang.Object
implements SpellList, SelfExternalizable, MutableProperty

Manages the player's list of known spells.

Version:
1.0, Nov 07, 1999
Author:
Eric Weber, Steve Yegge (big rewrite in 2003 for wiz spells) (and another big rewrite in Dec '03 for Spell Registry)

Field Summary
protected  java.util.Set spells_
           
 
Constructor Summary
SpellListImpl()
           
 
Method Summary
 void addSpell(java.lang.String name)
          Adds a spell to the list; used by the map editor.
static boolean addToPlayer(Commandable player)
          Ensures player has a spell list.
 java.lang.Object createClone()
          Produces a clone of the property for the caller.
 boolean equals(java.lang.Object o)
          Returns true if the passed SpellList is equivalent to this one.
 boolean forgetSpell(java.lang.String name, Commandable agent)
          Forgets a spell.
 int getSize()
          Returns the number of spells in this list.
 java.lang.String[] getSpells()
          Returns the spell names in this list.
 java.lang.String getSpellString()
          Returns all the spells in the spellbook, as a formatted string of the form "spell_1 spell_2 spell_3".
 int hashCode()
          Have to override this if you override equals(), in Java.
 boolean knowsSpell(java.lang.String name)
          Checks whether the player knows this spell
 void learnSpell(java.lang.String name)
          Learns a spell.
 boolean okToLearn(java.lang.String name, Commandable agent, java.lang.StringBuffer reason)
          Checks whether player is allowed to learn this spell, taking into account the lore cost of the spell and available lore points.
 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.lang.String toString()
          Prints the list, for debugging.
 java.util.List writeData()
          Tells the object to write its properties out to a text file.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

spells_

protected java.util.Set spells_
Constructor Detail

SpellListImpl

public SpellListImpl()
Method Detail

learnSpell

public void learnSpell(java.lang.String name)
Learns a spell.

Specified by:
learnSpell in interface SpellList
Parameters:
name - display-name of spell to learn, e.g. "word of recall"

forgetSpell

public boolean forgetSpell(java.lang.String name,
                           Commandable agent)
Forgets a spell.

Specified by:
forgetSpell in interface SpellList
Parameters:
name - the spell to forget, e.g. "create earth wall"
agent - the agent to whom to return the lore points for the spell, or null if not applicable.
Returns:
true if spell was previously known

knowsSpell

public boolean knowsSpell(java.lang.String name)
Checks whether the player knows this spell

Specified by:
knowsSpell in interface SpellList
Parameters:
name - display name to check, e.g. "lightning bolt"
Returns:
true if spell is known

okToLearn

public boolean okToLearn(java.lang.String name,
                         Commandable agent,
                         java.lang.StringBuffer reason)
Checks whether player is allowed to learn this spell, taking into account the lore cost of the spell and available lore points.

Specified by:
okToLearn in interface SpellList
Parameters:
name - spell to check
agent - the agent trying to learn the spell
reason - the error message, if any
Returns:
true if spell is permitted. If false, the reason is appended to the reason buffer

getSpells

public java.lang.String[] getSpells()
Returns the spell names in this list.

Specified by:
getSpells in interface SpellList
Returns:
an array of the names in the list, in random order. Never returns null - if the list has no spells, it returns a String array of length zero.

addToPlayer

public static boolean addToPlayer(Commandable player)
Ensures player has a spell list.

Parameters:
player - the player
Returns:
true if list was created, false if it already existed

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:
true

getSize

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

Specified by:
getSize in interface SpellList

addSpell

public void addSpell(java.lang.String name)
Adds a spell to the list; used by the map editor.

Specified by:
addSpell in interface SpellList
Parameters:
name - the name of the spell to add

getSpellString

public java.lang.String getSpellString()
Returns all the spells in the spellbook, as a formatted string of the form "spell_1 spell_2 spell_3". It's sent to the client, so don't change the format.

Specified by:
getSpellString in interface SpellList
Returns:
the spell list, with spell names having underscores

toString

public java.lang.String toString()
Prints the list, for debugging.


createClone

public java.lang.Object createClone()
Description copied from interface: MutableProperty
Produces a clone of the property for the caller. Note: it's called createClone, not makeClone, because GameObject already has a makeClone. Some GameObjects can be properties (e.g inventories) and we can't do overloaded methods based only on the return type.

Specified by:
createClone in interface MutableProperty

equals

public boolean equals(java.lang.Object o)
Returns true if the passed SpellList is equivalent to this one.


hashCode

public int hashCode()
Have to override this if you override equals(), in Java.