wyvern.lib.classes.magic
Class Spell

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.kernel.commands.AbstractCommandable
              extended bywyvern.lib.classes.magic.Spell
All Implemented Interfaces:
Broadcaster, Commandable, Dispellable, GameObject, Hookable, MethodHookable, PropertyList, RemoteAudio, Targetable
Direct Known Subclasses:
BallSpell, BoltSpell, Charging, ConeSpell, CreateLava, CreateWater, DestroyArmor, DestroyObject, Destruction, DispelSpell, Elixir, EnlargeArmor, Enlightenment, FindTraps, FlameShield, Heal, Identify, JoinPlayer, Jump, Knock, KnowAlignment, MagicMap, Paralyze, ParalyzeSelf, RemoveCurse, Repair, Restoration, RestoreMana, Resurrection, Satiety, ShrinkArmor, SlowPoison, StaticBlade, SummonPlayer, SummonSpell, Teleport, TimedSpell, TimeStop, WaterWalk, WizardEye, WizardLock, WordOfRecall

public abstract class Spell
extends AbstractCommandable
implements Targetable, Dispellable

This class extends Monster in various ways, to make spells behave more or less like monsters in the game. This is useful even for one-shot spells like Identify that never actually go in the map.

The Spell class inherits various useful methods from AbstractCommandable:

Plus it inherits the entire command and hooks mechanism, so all spell movements are hookable by interested listeners.

To activate a spell, the following steps may be necessary:

  1. set the spell's level
  2. set the spell's direction
  3. set the spell in the map
  4. start the spell
Not all of these steps may be required for a given spell, in which case the spell can ignore the steps. However, to make all spells behave the same from an API standpoint, all these steps must be executed to initiate a spell.

Version:
1.0, Jan 19, 1998
Author:
Steve Yegge

Nested Class Summary
protected  class Spell.DamageVisitor
          Invokes callback function for damaging monsters.
protected  class Spell.UsableReagentPredicate
          Determines if we can use a given reagent.
 
Field Summary
static Element AIR
           
static Element AIR_AND_DEATH
           
static Element AIR_AND_LIFE
           
static Element AIR_AND_MIND
           
static Element AIR_AND_SPIRIT
           
static int[] ART_MANA_REDUCTIONS
           
protected  int[] bitmaps_
          Keeps track of the spells bitmap numbers for animation.
static Art CONJURATION
           
protected  Visitor damager_
           
static Element DEATH
           
static Element DEATH_AND_MIND
           
static Element DEATH_AND_SPIRIT
           
static Element EARTH
           
static Element EARTH_AND_AIR
           
static Element EARTH_AND_DEATH
           
static Element EARTH_AND_LIFE
           
static Element EARTH_AND_MIND
           
static Element EARTH_AND_SPIRIT
           
static Art ENCHANTMENT
           
static Art EVOCATION
           
static Element FIRE
           
static Element FIRE_AND_AIR
           
static Element FIRE_AND_DEATH
           
static Element FIRE_AND_EARTH
           
static Element FIRE_AND_LIFE
           
static Element FIRE_AND_MIND
           
static Element FIRE_AND_SPIRIT
           
static Element FIRE_AND_WATER
           
static Art INCANTATION
           
static Element LIFE
           
static Element LIFE_AND_DEATH
           
static Element LIFE_AND_MIND
           
static Element LIFE_AND_SPIRIT
           
static Element MIND
           
static Element MIND_AND_SPIRIT
           
static int[] SELF_DAMAGE_CHANCE
           
static Element SPIRIT
           
static Element WATER
           
static Element WATER_AND_AIR
           
static Element WATER_AND_DEATH
           
static Element WATER_AND_EARTH
           
static Element WATER_AND_LIFE
           
static Element WATER_AND_MIND
           
static Element WATER_AND_SPIRIT
           
 
Fields inherited from class wyvern.kernel.commands.AbstractCommandable
hookList_, queue_, started_
 
Fields inherited from class wyvern.kernel.maps.MapObject
IN_MAP_EDITOR, listenerList_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Fields inherited from interface wyvern.common.net.RemoteAudio
DEFAULT_ALERT_GAIN, DEFAULT_ALERT_REPEAT_DELAY, DEFAULT_ALERT_REPEATS, DEFAULT_GAIN, DEFAULT_REPEAT_DELAY, DEFAULT_REPEATS
 
Constructor Summary
Spell()
           
 
Method Summary
 void addReagent(java.lang.String path)
          Adds a reagent to the list of required reagents for this spell.
static boolean canDamageSelf(Commandable caster, Spell spell)
          Checks to see if the caster has enough skill to avoid damaging themselves
 boolean canEnter(GameMap map, int x, int y)
          Returns true if the spell is allowed to enter the specified location.
 boolean canEnter(GameMap map, Point ref)
          Returns true if the spell is allowed to enter the specified location.
 boolean castingOnSelf()
          Returns true if the spell target is the same as the spell agent/caster.
static Spell cloneSpell(java.lang.String name)
          Clones a spell from its name.
 boolean consumeReagents(Commandable agent)
          Figures out which reagents the spell requires, if any, and consumes them.
 void damageMonster(Damageable obj, Spell spell)
          Does damage to a specific monster.
 void damageMonsters()
          Does damage to all cells we currently occupy.
 void destroy()
          Destroys the spell.
 void dispel()
          Dispels the spell.
protected  void ensureAI()
          Chooses an AI for the monster.
 int ensureDirection()
          Makes sure we have a valid (cardinal) direction, in case nobody set it before firing the spell.
 boolean ensureReagents()
          Calls consumeReagents(), and if the result is false, prints a message to the caster saying they don't have enough reagents.
 GameObject findTargetObject()
          Same as findTargetObject(useAgent), but never uses the caster as the target.
 GameObject findTargetObject(boolean useAgent)
          Uses standard rules for finding the target.
 void fireDirection(Commandable agent, int dir)
          Tells the spell to fire itself in the specified direction.
 void fireLocation(Commandable agent, Point target)
          Tells the object to fire itself along the line specified from the agent to a destination point.
 Commandable getAgent()
          Returns the caster, if any.
protected  void getAnimationFrames(java.lang.String cat, java.lang.String bmp)
          Gets the frames to use for random animation.
 Art getArt()
          Returns one of the four spell Arts.
 Predicate getBlockingPredicate()
          Returns a predicate that determines whether the spell can be placed at a given map location.
 int getCastingDelay()
          Returns the delay for casting this spell.
 Command getCommand(CommandEvent event)
          Returns the Command that handles this spell.
 java.lang.String getDescString()
          Converts the art and element(s) into a string.
 Element getElement()
          Returns the Element for this spell.
 int getLevel(Element element)
          Returns the level of the spell.
 int getLoreCost()
          Returns the lore cost for this spell - by default, what's in the "lore" entry for the spell, in the SpellRegistry.
 GameObject getMagicItem()
          Returns the wand/rod/scroll/whatever that initiated this spell, if any.
 java.util.Set getPoints()
          Returns the map locations that the spell is currently occupying.
 java.util.List getReagents()
          Returns the reagents for this spell.
 int getRequiredMana()
          Returns the amount of mana required for this spell.
 int getSpeed()
          Gets the propagation speed of the spell.
 java.lang.String getSpellArgs()
          Returns the spell arguments, if any.
 java.lang.String getSpellDescription()
          Returns a generic description for the spell.
 java.lang.String getSpellName()
          Returns the name of the spell, such as "word of recall", used for casting the spell.
 GameObject getTarget()
          Returns the actual target object to use for this spell.
 java.lang.String getTargetName()
          Returns the name set during the casting, if the user wants to cast a spell on a particular object or monster.
 Point getTargetPoint()
          Returns the target location for this spell, if it was invoked using the mouse (or by specifying a location on the command line).
 void initialize()
          Adds the default properties for a Spell object.
 boolean isBlessed()
          Returns true if the spell is blessed, e.g. it came from a blessed scroll.
 boolean isConjuration()
          Returns true if this spell's art is CONJURATION.
 boolean isCursed()
          Returns true if the spell is cursed, e.g. it came from a cursed scroll.
 boolean isEnchantment()
          Returns true if this spell's art is ENCHANTMENT.
 boolean isEvocation()
          Returns true if this spell's art is EVOCATION.
 boolean isIncantation()
          Returns true if this spell's art is INCANTATION.
 boolean isPotion()
          Returns true if the spell was "cast" by drinking a potion (or being hit by one).
 void logUsage()
          Logs the casting of the spell into the spell log.
 void makeDispellable()
          Adds this spell to the agent's active-list, so it can be viewed and dispelled.
static void reloadSpells()
          Instructs the Spell.cloneSpell() methods to use a new ClassLoader instance to load spells, which will cause them to be re-read from the class files on disk.
 void removeFromActiveListIfPresent()
          Gets spell's agent, and removes this spell from "active-spells" list, if it's there.
 void setAgent(Commandable agent)
          Sets the agent casting or invoking the spell.
 void setLevel(int level)
          Sets the spell's level property.
 void setMagicItem(GameObject item)
          Sets the magic item that was used to invoke this spell, such as a wand or scroll.
 void setSpeed(int speed)
          Sets the propagation speed of the spell.
 void setSpellArgs(java.lang.String args)
          Sets the argument string used to invoke the spell, using the "with-args" keyword.
 void setTarget(GameObject target)
          Sets the actual target of the spell.
 void setTargetName(java.lang.String name)
          Names the object on which the user wants to cast the spell.
 void setTargetPoint(Point point)
          Sets a location at which the user requested to cast the spell, usually via the mouse.
 void start()
          Starts the spell.
 void tellCaster(java.lang.String msg)
          Sends a message to the spell's caster, if the spell has a caster set.
 
Methods inherited from class wyvern.kernel.commands.AbstractCommandable
addAttack, addHook, addMessageListener, addMethodHook, checkAnimated, command, command, commandNow, ensureEventQueue, fireMessageReceived, getAI, getCapName, getCombatQueue, getEncumbrance, getFiringPoint, getHookList, getHooks, getInventory, getName, getQueue, isCommandable, isStarted, isTelnet, message, message, message, pauseSound, playAlert, playAlert, playDefaultMusic, playPriorityMusic, playPriorityMusic, playSound, playSound, registerCommand, removeAttack, removeHook, removeMessageListener, removeMethodHook, resumeSound, runFailedPostHook, runMethodHook, runPostHook, runPreHook, sendPicture, sendPicture, setAI, setEncumbrance, setMusicGain, setName, setSoundGain, stop, stopAllSounds, stopMusic, stopSound, unregisterCommand
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMap, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, toString, updateMapLocation
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.GameObject
addContainerChangeListener, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, bless, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, externalize, getAlpha, getAppearance, getArchetype, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, inContainer, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDirection, setImage, setImage, setLayer, setLocations, setMap, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from interface wyvern.lib.Broadcaster
broadcast, broadcast, broadcast, broadcast, broadcast
 

Field Detail

INCANTATION

public static final Art INCANTATION

CONJURATION

public static final Art CONJURATION

EVOCATION

public static final Art EVOCATION

ENCHANTMENT

public static final Art ENCHANTMENT

FIRE

public static final Element FIRE

WATER

public static final Element WATER

EARTH

public static final Element EARTH

AIR

public static final Element AIR

LIFE

public static final Element LIFE

DEATH

public static final Element DEATH

MIND

public static final Element MIND

SPIRIT

public static final Element SPIRIT

FIRE_AND_WATER

public static final Element FIRE_AND_WATER

FIRE_AND_EARTH

public static final Element FIRE_AND_EARTH

FIRE_AND_AIR

public static final Element FIRE_AND_AIR

FIRE_AND_LIFE

public static final Element FIRE_AND_LIFE

FIRE_AND_DEATH

public static final Element FIRE_AND_DEATH

FIRE_AND_MIND

public static final Element FIRE_AND_MIND

FIRE_AND_SPIRIT

public static final Element FIRE_AND_SPIRIT

WATER_AND_EARTH

public static final Element WATER_AND_EARTH

WATER_AND_AIR

public static final Element WATER_AND_AIR

WATER_AND_LIFE

public static final Element WATER_AND_LIFE

WATER_AND_DEATH

public static final Element WATER_AND_DEATH

WATER_AND_MIND

public static final Element WATER_AND_MIND

WATER_AND_SPIRIT

public static final Element WATER_AND_SPIRIT

EARTH_AND_AIR

public static final Element EARTH_AND_AIR

EARTH_AND_LIFE

public static final Element EARTH_AND_LIFE

EARTH_AND_DEATH

public static final Element EARTH_AND_DEATH

EARTH_AND_MIND

public static final Element EARTH_AND_MIND

EARTH_AND_SPIRIT

public static final Element EARTH_AND_SPIRIT

AIR_AND_LIFE

public static final Element AIR_AND_LIFE

AIR_AND_DEATH

public static final Element AIR_AND_DEATH

AIR_AND_MIND

public static final Element AIR_AND_MIND

AIR_AND_SPIRIT

public static final Element AIR_AND_SPIRIT

LIFE_AND_DEATH

public static final Element LIFE_AND_DEATH

LIFE_AND_MIND

public static final Element LIFE_AND_MIND

LIFE_AND_SPIRIT

public static final Element LIFE_AND_SPIRIT

DEATH_AND_MIND

public static final Element DEATH_AND_MIND

DEATH_AND_SPIRIT

public static final Element DEATH_AND_SPIRIT

MIND_AND_SPIRIT

public static final Element MIND_AND_SPIRIT

ART_MANA_REDUCTIONS

public static final int[] ART_MANA_REDUCTIONS

SELF_DAMAGE_CHANCE

public static final int[] SELF_DAMAGE_CHANCE

bitmaps_

protected int[] bitmaps_
Keeps track of the spells bitmap numbers for animation. Not used by invisible or non-animated spells. Initialized by a subclass's call to getAnimationFrames().


damager_

protected Visitor damager_
Constructor Detail

Spell

public Spell()
Method Detail

initialize

public void initialize()
Adds the default properties for a Spell object.

Specified by:
initialize in interface GameObject
Overrides:
initialize in class MapObject

ensureAI

protected void ensureAI()
Description copied from class: AbstractCommandable
Chooses an AI for the monster. Called by start() method, which in turn is called when the monster is constructed or read from a map. Subclasses should remember to call the superclass version.

This is (probably) the most appropriate time to convert the externalized "ai" property (an Archetype) into an actual instantiated AI class. It's stored in the file as an archetype because the AI classes aren't usually directly instantiable, so doing something like "ai class FooAI" would result in an IllegalAccessError.

Because there are no static interfaces in Java (as yet), we can't simply take the class, cast it to a static interface, and invoke the getImpl() class method on it. Alas. Instead, we must use reflection to sniff out the getImpl() class method. This returns the (singleton) instance of the AI, which we can store a reference to in our "ai" property.

Overrides:
ensureAI in class AbstractCommandable

getSpellName

public java.lang.String getSpellName()
Returns the name of the spell, such as "word of recall", used for casting the spell. The spell name is used as a key into the SpellRegistry, to get at meta-data such as the lore level, the Art and Element, the reagents, description, and so on.

Returns:
the "spell-name" property of the spell, which is set by the SpellRegistry after cloning the spell.

getArt

public Art getArt()
Returns one of the four spell Arts. Calls the SpellRegistry. Spells not in the registry should override this method.


getElement

public Element getElement()
Returns the Element for this spell. Calls the SpellRegistry. Spells not in the registry should override this method.


getLoreCost

public int getLoreCost()
Returns the lore cost for this spell - by default, what's in the "lore" entry for the spell, in the SpellRegistry. Spells not in the registry should override this method.


getCastingDelay

public int getCastingDelay()
Returns the delay for casting this spell. Most spells have no delay, but for some, we add a delay to prevent imbalances.

Returns:
the delay, in milliseconds, the player should have to wait before casting the spell again

getSpellDescription

public java.lang.String getSpellDescription()
Returns a generic description for the spell. Spell can override it, or set a "desc-string" property in its initialize() method.


getDescString

public java.lang.String getDescString()
Converts the art and element(s) into a string.

Returns:
something like "enchantment of life"

start

public void start()
Starts the spell. Sets a target on the spell if the player says so.

Specified by:
start in interface Commandable
Overrides:
start in class