wyvern.lib.classes.magic
Class SpellRegistry

java.lang.Object
  extended bywyvern.lib.classes.magic.SpellRegistry

public final class SpellRegistry
extends java.lang.Object

Class that manages the XML spell registry, which contains metadata about all the spells. The metadata includes: which class implements the spell, the lore level, the Art and Elements, the spellbook description, and so on - pretty much everything that would go into a Spell Manual.

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

Method Summary
static Spell cloneSpell(java.lang.String name)
          Clones a spell from its name.
static Spell cloneSpellByClass(java.lang.String name)
          Clones and initializes a spell from its classname.
static boolean contains(java.lang.String name)
          Returns true if the registry contains the passed spell.
static Art getArt(java.lang.String name)
          Returns the Art for the specified spell.
static java.lang.String getClassName(java.lang.String name)
          Returns the name of the class implementing this spell.
static java.lang.String getDescription(java.lang.String name)
          Returns the spell description - a sentence fragment that describes the spell, such as "allows the caster to see in the dark."
static Element getElement(java.lang.String name)
          Returns the Element for the specified spell.
static java.lang.String getFullDescription(java.lang.String name)
          Returns the full spell description - a sentence of the form "This (Art) of (Elements) (description)."
static int getLore(java.lang.String name)
          Returns the spell lore level
static java.util.List getReagents(java.lang.String name)
          Returns the spell reagents.
static java.util.List getRegisteredSpells()
          Returns a sorted list of all spells in the registry.
static java.util.List getSpellsByArtAndElement(Art art, Element element)
          Returns a list of all of spells of the passed Art and/or Element(s).
static java.util.List getSpellsByLevel(int level)
          Returns a list of all the spells of the passed Lore level.
static java.lang.String getTitle(java.lang.String name)
          Returns the "title" of a spell, such as "Conjuration of Water and Air".
static boolean isLearnable(java.lang.String name)
          Returns true if this spell can be learned by Players.
static java.lang.String listReagents(java.lang.String name)
          Returns a user-visible list of the spell reagents.
static void main(java.lang.String[] args)
          Testing.
static boolean okNoSpells(java.lang.String name)
          Returns true if this spell can be cast in no-spells areas.
static void reload()
          Reloads the spell registry from disk - called by admins when the spell repository has been changed from outside the game engine.
static java.util.List xpath(java.lang.String query)
          Takes an arbitrary XPath expression and returns a List whose elements are the names of the spells matching the expression, or an empty list.
static int xpathCount(java.lang.String query)
          Takes an arbitrary XPath expression that has an integer result, and evaluates and returns it on the spell registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reload

public static void reload()
Reloads the spell registry from disk - called by admins when the spell repository has been changed from outside the game engine.


contains

public static boolean contains(java.lang.String name)
Returns true if the registry contains the passed spell.

Parameters:
name - the name of the spell, e.g. "create earth wall"
Returns:
true if it's a registered spell

getRegisteredSpells

public static java.util.List getRegisteredSpells()
Returns a sorted list of all spells in the registry.

Returns:
a list of spell names, sorted alphabetically.

getClassName

public static java.lang.String getClassName(java.lang.String name)
Returns the name of the class implementing this spell.

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
a fully-qualified java classname, or a python file that can have Wyvern.ROOT_DIR prepended to get the absolute path for execfile(). Examples:
  • "wyvern.lib.spells.LightningBolt"
  • "wyvern.wiz.rhialto.python.spells.Whatever"
  • "wiz/janica/spells/insanity_field.py"
  • "lib/spells/confusion.py"
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getDescription

public static java.lang.String getDescription(java.lang.String name)
Returns the spell description - a sentence fragment that describes the spell, such as "allows the caster to see in the dark."

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
a description suitable for appearing in the spellbook or spell manual.
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getFullDescription

public static java.lang.String getFullDescription(java.lang.String name)
Returns the full spell description - a sentence of the form "This (Art) of (Elements) (description)." Example: "This Evocation of Water hurls a glob of potent acid at a foe."

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
a full description of the spell.
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getTitle

public static java.lang.String getTitle(java.lang.String name)
Returns the "title" of a spell, such as "Conjuration of Water and Air".

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
the spell title
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getLore

public static int getLore(java.lang.String name)
Returns the spell lore level

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
the lore (a positive number)
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getArt

public static Art getArt(java.lang.String name)
Returns the Art for the specified spell.

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
the Art
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getElement

public static Element getElement(java.lang.String name)
Returns the Element for the specified spell.

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
the Element
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

okNoSpells

public static boolean okNoSpells(java.lang.String name)
Returns true if this spell can be cast in no-spells areas.

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
true if it's OK to cast anywhere
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

isLearnable

public static boolean isLearnable(java.lang.String name)
Returns true if this spell can be learned by Players.

Parameters:
name - the spell name, e.g. "word of recall"
Returns:
true if it can be learned, false if it should never appear in a spellbook
Throws:
java.lang.IllegalArgumentException - if the passed spell isn't in the registry.

getReagents

public static java.util.List getReagents(java.lang.String name)
Returns the spell reagents.

Returns:
a list of String names, or an empty list if there are no reagents

listReagents

public static java.lang.String listReagents(java.lang.String name)
Returns a user-visible list of the spell reagents.

Parameters:
name - the spell name
Returns:
a string such as "sulfur, ashes", or "a diamond of at least 1000gp value", or "none" if no reagents are required for this spell.

getSpellsByLevel

public static java.util.List getSpellsByLevel(int level)
Returns a list of all the spells of the passed Lore level.

Parameters:
level - a lore level
Returns:
a List of the names (e.g. "lightning shield") of the passed lore level. Returns an empty list if there are no spells of the passed level.

getSpellsByArtAndElement

public static java.util.List getSpellsByArtAndElement(Art art,
                                                      Element element)
Returns a list of all of spells of the passed Art and/or Element(s).

Parameters:
art - the spell Art (can be null, but Element must be non-null)
element - the spell Element (can be null, but Art must be non-null)
Returns:
a List of the names (e.g. "word of recall") of spells of the passed Art and/or Element(s). Returns an empty list if there are no matching spells found.
Throws:
java.lang.IllegalArgumentException - if Art and Element are both null

xpath

public static java.util.List xpath(java.lang.String query)
                            throws java.lang.Exception
Takes an arbitrary XPath expression and returns a List whose elements are the names of the spells matching the expression, or an empty list.

Parameters:
query - an XPath - you need to know the data model (and XPath) in order to use this. I don't recommend it.
Returns:
a list of string names
Throws:
java.lang.Exception

xpathCount

public static int xpathCount(java.lang.String query)
                      throws java.lang.Exception
Takes an arbitrary XPath expression that has an integer result, and evaluates and returns it on the spell registry.

Parameters:
query - an XPath - you need to know the data model (and XPath) in order to use this. I don't recommend it.
Returns:
the count returned by the query
Throws:
java.lang.Exception

cloneSpell

public static Spell cloneSpell(java.lang.String name)
Clones a spell from its name.

Parameters:
name - the spell name, e.g. "confuse monster"
Returns:
a Spell cloned from that name, null if it couldn't be cloned

cloneSpellByClass

public static Spell cloneSpellByClass(java.lang.String name)
Clones and initializes a spell from its classname.

Parameters:
name - either a python relative path, e.g. "lib/spells/confuse_monster.py", or "wiz/rhialto/python/foospell.py", or a fully-qualified java classname, e.g. "wiz.foobar.spells.MySpell".
Returns:
the spell cloned and instantiated
Throws:
java.lang.IllegalArgumentException - if it couldn't be loaded

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Testing.

Throws:
java.lang.Throwable