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 AbstractCommandable

getSpeed

public int getSpeed()
Gets the propagation speed of the spell.

Returns:
the propagation speed, in millis

setSpeed

public void setSpeed(int speed)
Sets the propagation speed of the spell.

Parameters:
speed - the new speed in millis

getLevel

public int getLevel(Element element)
Returns the level of the spell. This is either the "level" property of the item that cast the spell, or the "level" property set on the spell manually by some wizard code, OR if the spell has a caster, it returns their rating in the selected element.

Parameters:
element - the element to check for - only checked if the spell has an agent, not used for magic items.
Returns:
the effective spell level in that element - can be zero.

setLevel

public void setLevel(int level)
Sets the spell's level property.

Parameters:
level - the level of the spell, to be interpreted by subclass

setAgent

public void setAgent(Commandable agent)
Sets the agent casting or invoking the spell. Some spells act on the agent casting the spell, so setting the "agent" to property someone else will effectively retarget the spell.

Parameters:
agent - the caster

setMagicItem

public void setMagicItem(GameObject item)
Sets the magic item that was used to invoke this spell, such as a wand or scroll. Stores the reference to the object in a property called "@item".

Parameters:
item - the actual wand, scroll, etc. that invoked the spell.

setTargetPoint

public void setTargetPoint(Point point)
Sets a location at which the user requested to cast the spell, usually via the mouse. Spells are free to use or ignore this parameter, which may be null.

Parameters:
point - the map (x, y) location where the user clicked

getTargetPoint

public 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).

Returns:
the target point, or null if none was specified

getTarget

public GameObject getTarget()
Returns the actual target object to use for this spell. May not be set; if it's null, check for a target-name.

Returns:
the target of the spell, or null if it hasn't been determined (or set). Stored in a property called "@target".

setTarget

public void setTarget(GameObject target)
Sets the actual target of the spell.

Parameters:
target - the object to operate on. Stored in a property called "@target".

setTargetName

public void setTargetName(java.lang.String name)
Names the object on which the user wants to cast the spell. If the caster typed "cast foo at bar", or "cast foo on bar", then the target name is "bar".

If the spell supports targets, the spell should first check for an actual target object via getTarget(). If that's null, the spell should look for an object that matches this name by whatever rules the spell uses for finding targets (e.g. look in caster's inventory, look on ground, look nearby).

Parameters:
name - the name of an object at which the caster wants to apply the spell.

getTargetName

public 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.

Returns:
whatever they cast they spell "on" or "at", or null if no target was specified.

getMagicItem

public GameObject getMagicItem()
Returns the wand/rod/scroll/whatever that initiated this spell, if any. Note: equivalent to calling getProperty("@item").

Returns:
the magic item that contained the spell, or null if it was created some other way (e.g. by casting it).

isPotion

public boolean isPotion()
Returns true if the spell was "cast" by drinking a potion (or being hit by one).

Returns:
true if the spell was launched by a potion

getRequiredMana

public int getRequiredMana()
Returns the amount of mana required for this spell.

Returns:
the mana, by default what's in the "mana" property

isConjuration

public boolean isConjuration()
Returns true if this spell's art is CONJURATION.


isEvocation

public boolean isEvocation()
Returns true if this spell's art is EVOCATION.


isIncantation

public boolean isIncantation()
Returns true if this spell's art is INCANTATION.


isEnchantment

public boolean isEnchantment()
Returns true if this spell's art is ENCHANTMENT.


consumeReagents

public boolean consumeReagents(Commandable agent)
Figures out which reagents the spell requires, if any, and consumes them. If we're being cast by a magic item, it doesn't use any reagents and returns true.

Parameters:
agent - the caster
Returns:
true if we found and used the appropriate reagents, or we didn't need any to begin with

getReagents

public java.util.List getReagents()
Returns the reagents for this spell.


addReagent

public void addReagent(java.lang.String path)
Adds a reagent to the list of required reagents for this spell.

Parameters:
path - the path to the reagent archetype, e.g. magic/reagent/clover

ensureReagents

public boolean ensureReagents()
Calls consumeReagents(), and if the result is false, prints a message to the caster saying they don't have enough reagents. Basically a minor shortcut spells can use in their start() method to check for reagents.

Returns:
true if there were enough reagents, false if not

setSpellArgs

public void setSpellArgs(java.lang.String args)
Sets the argument string used to invoke the spell, using the "with-args" keyword. Everything after the "with-args" is used as the arguments to the spell. Most spells don't take any arguments.

Usage example: "cast magic mouth with-args Hi there." will create a magic mouth that says "Hi there." when you step on it. The spell args are "Hi there.".

Parameters:
args - the spell arguments passed using "with-args" keyword

getSpellArgs

public java.lang.String getSpellArgs()
Returns the spell arguments, if any. If the spell was cast using the "with-args" keyword, anything after the "with-args" is placed in the spell args using this method.

Returns:
the spell args, if they were set. Can be null.

isCursed

public boolean isCursed()
Returns true if the spell is cursed, e.g. it came from a cursed scroll. Subclasses should implement cursed versions of each spell.

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

isBlessed

public boolean isBlessed()
Returns true if the spell is blessed, e.g. it came from a blessed scroll. Subclasses should implement blessed versions of each spell.

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

getAgent

public Commandable getAgent()
Returns the caster, if any.

Returns:
the monster/person casting this spell

getCommand

public Command getCommand(CommandEvent event)
Returns the Command that handles this spell.

Specified by:
getCommand in interface Commandable
Overrides:
getCommand in class AbstractCommandable
Returns:
whoever's handling the event - defaults to whatever is in the "ai" property of the spell's property list.

getPoints

public java.util.Set getPoints()
Returns the map locations that the spell is currently occupying. By default, spells occupy no area at all, but this should be overridden in subclasses that have a physical presence (e.g. fireball).

Returns:
a set of points for the spell, null if the spell occupies no map locations.

damageMonsters

public void damageMonsters()
Does damage to all cells we currently occupy. Shared by subclasses that do area-effect damage.


canDamageSelf

public static boolean canDamageSelf(Commandable caster,
                                    Spell spell)
Checks to see if the caster has enough skill to avoid damaging themselves


damageMonster

public void damageMonster(Damageable obj,
                          Spell spell)
Does damage to a specific monster. Figures out all the wc-* properties on the spell, creates DamageTypes for them, and uses those to create DamageEvents to put in the monster's queue.

Parameters:
obj - the monster to damage
spell - the spell doing the damage (in case this needs to be used as a utility by another spell). If the spell has the property "show-defender-msg", the DamageEvent generated will show normal damage-messages (depending on the damage type) to the monster; otherwise it will be silent.

findTargetObject

public GameObject findTargetObject(boolean useAgent)
Uses standard rules for finding the target. Looks for a target object via getTarget(), and if that's null, looks for a target name via getTargetName(). If the target name is non-null, looks in the vicinity of the caster for an object matching the target name.

Parameters:
useAgent - true to use the agent if we can't find a target
Returns:
the target to use, null if none was found.

findTargetObject

public GameObject findTargetObject()
Same as findTargetObject(useAgent), but never uses the caster as the target.


ensureDirection

public int ensureDirection()
Makes sure we have a valid (cardinal) direction, in case nobody set it before firing the spell. As a last resort, chooses a random direction if necessary.

Returns:
the direction we chose

tellCaster

public void tellCaster(java.lang.String msg)
Sends a message to the spell's caster, if the spell has a caster set. (It won't be set if the spell was invoked via a potion or some other magic item).

Parameters:
msg - the message to send

getAnimationFrames

protected void getAnimationFrames(java.lang.String cat,
                                  java.lang.String bmp)
Gets the frames to use for random animation. Used by animated spells that want to handle their own animation, rather than relying on the default behavior of MapObject and AnimationParams. For instance, Ball and Cone spells return random images from the available set of images, when asked for their appearance by the game engine.

We cache all the available bitmap numbers here so we don't have to look them all up later.


getBlockingPredicate

public Predicate getBlockingPredicate()
Returns a predicate that determines whether the spell can be placed at a given map location.

Returns:
a predicate, by default a BlocksSpellPredicate
See Also:
BlocksSpellPredicate

canEnter

public boolean canEnter(GameMap map,
                        Point ref)
Returns true if the spell is allowed to enter the specified location. If it's blocked (by whatever blocking predicate the spell uses), returns false.

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

canEnter

public boolean canEnter(GameMap map,
                        int x,
                        int y)
Returns true if the spell is allowed to enter the specified location. If it's blocked (by whatever blocking predicate the spell uses), returns false.


destroy

public void destroy()
Destroys the spell. Default implementation just invokes the dispel() function.

Specified by:
destroy in interface GameObject
Overrides:
destroy in class AbstractCommandable

dispel

public void dispel()
Dispels the spell. Some spells don't need to be dispelled, since their effect is instantaneous, so this method isn't abstract. The default implementation does nothing. Spells that can be dispelled should implement this function. Don't call the destroy() method from inside dispel() or you'll get infinite recursion.

You have to call the superclass version from the subclass or the spell will remain in the caster's active list.

Specified by:
dispel in interface Dispellable

removeFromActiveListIfPresent

public void removeFromActiveListIfPresent()
Gets spell's agent, and removes this spell from "active-spells" list, if it's there.


makeDispellable

public void makeDispellable()
Adds this spell to the agent's active-list, so it can be viewed and dispelled. Only does it for Players. If the spell is invoked with a magic item (wand, scroll, etc) this will NOT add it to the active list, since generally you shouldn't be able to dispel spells from magic items.


fireDirection

public void fireDirection(Commandable agent,
                          int dir)
Tells the spell to fire itself in the specified direction. Default handler simply calls start().

Specified by:
fireDirection in interface Targetable
Parameters:
agent - the agent firing the object
dir - a wyvern.lib.Direction cardinal direction

fireLocation

public void fireLocation(Commandable agent,
                         Point target)
Tells the object to fire itself along the line specified from the agent to a destination point. Default handler simply calls start().

Specified by:
fireLocation in interface Targetable
Parameters:
agent - the agent firing the object
target - the destination point, perhaps chosen using the mouse.

reloadSpells

public 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. This allows us to make changes to spells on the fly and have the changes take effect at runtime.


logUsage

public void logUsage()
Logs the casting of the spell into the spell log. Probably not a good idea to do this for combat spells that are cast all the time.


castingOnSelf

public boolean castingOnSelf()
Returns true if the spell target is the same as the spell agent/caster.

Returns:
true if the target is non-null (only true for spells with individual targets, e.g. blindness, resist spells, strength, etc.) and the target is the caster.

cloneSpell

public static Spell cloneSpell(java.lang.String name)
Clones a spell from its name. This method is simply and alias for SpellRegistry.cloneSpell().

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