wyvern.lib.classes.magic
Class BoltSpell

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.kernel.commands.AbstractCommandable
              extended bywyvern.lib.classes.magic.Spell
                  extended bywyvern.lib.classes.magic.BoltSpell
All Implemented Interfaces:
Broadcaster, Command, Commandable, Dispellable, GameObject, Hookable, HookCallback, MethodHookable, PropertyList, RemoteAudio, Targetable
Direct Known Subclasses:
DeathRay, Dig, Firefrost, MagicDart, Petrify

public abstract class BoltSpell
extends Spell
implements Command, HookCallback

Generic, parameterizable bolt/ray spell. Can travel any cardinal direction. Parameters are "speed" (in millis), "duration" (number turns it propagates) and "length" (max length of the bolt).

Version:
1.0, Nov 28, 1999
Author:
Steve Yegge

Nested Class Summary
 
Nested classes inherited from class wyvern.lib.classes.magic.Spell
Spell.DamageVisitor, Spell.UsableReagentPredicate
 
Field Summary
static int DEFAULT_BOLT_DURATION
          Number of turns the bolt will propagate.
static int DEFAULT_BOLT_MAX_LENGTH
          Default length of the bolt if it encounters no obstructions.
static int DEFAULT_BOLT_SPEED
          Default rate (in millis) at which the bolt propagates.
static java.lang.Object DUMMY_LIGHT
           
 
Fields inherited from class wyvern.lib.classes.magic.Spell
AIR, AIR_AND_DEATH, AIR_AND_LIFE, AIR_AND_MIND, AIR_AND_SPIRIT, ART_MANA_REDUCTIONS, bitmaps_, CONJURATION, damager_, DEATH, DEATH_AND_MIND, DEATH_AND_SPIRIT, EARTH, EARTH_AND_AIR, EARTH_AND_DEATH, EARTH_AND_LIFE, EARTH_AND_MIND, EARTH_AND_SPIRIT, ENCHANTMENT, EVOCATION, FIRE, FIRE_AND_AIR, FIRE_AND_DEATH, FIRE_AND_EARTH, FIRE_AND_LIFE, FIRE_AND_MIND, FIRE_AND_SPIRIT, FIRE_AND_WATER, INCANTATION, LIFE, LIFE_AND_DEATH, LIFE_AND_MIND, LIFE_AND_SPIRIT, MIND, MIND_AND_SPIRIT, SELF_DAMAGE_CHANCE, SPIRIT, WATER, WATER_AND_AIR, WATER_AND_DEATH, WATER_AND_EARTH, WATER_AND_LIFE, WATER_AND_MIND, 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
BoltSpell()
           
 
Method Summary
 void addLight(Point p)
          Adds a light source to the map for one of our locations.
 void bounced(GameObject blocker, int x, int y)
          Called if the spell bounces off of a blocking object.
protected  boolean canPutInMap(GameMap map, int x, int y)
          Returns true if the spell can be placed in the passed map at the specified location.
protected  void clearDamageCache()
          Resets the cache of monsters we've damaged this turn.
protected  void clearVariables()
          Nulls out all instance variables.
protected  void computeAngle()
          Figures out the angle the bolt is travelling at (basically, dX and dY).
 CommandEvent createEvent(CommandEvent initial)
          Creates an event to propagate the bolt spell.
 void damageMonster(Damageable obj, Spell spell)
          Makes sure we only damage a monster one time per propagation cycle, regardless of how big it is.
 void damageMonsters()
          Damages all monsters in areas we occupy.
protected  boolean determineMap()
          Figures out which map we're supposed to be in, and where.
 void dispel()
          Shuts off the spell.
 boolean doesBounce()
          Returns whether or not the bolt is set to bounce off of things.
 void dumpList()
          Lists all occupied squares for debugging.
 boolean execute(CommandEvent event)
          Propagates the bolt.
 int getAge()
          Returns the current age of the bolt.
 Rectangle getBounds()
          Returns the bounds of the spell.
 Command getCommand(CommandEvent event)
          Handle our "bolt" command ourselves.
 int getDuration()
          Returns the number of turns the bolt will propagate.
 int[] getImageDescriptors()
          Returns the appearance of the spell.
 java.util.List getLocations()
          Returns the locations occupied by this spell.
 int getMaxLength()
          Returns the max length for the bolt.
 java.util.Set getPoints()
          Returns the locations occupied by this spell.
 int getSpeed()
          Returns the speed at which this bolt propagates.
 int getTile(int x, int y)
          Returns the image number to use at (x, y)
 void hookEvent(java.lang.String hookname, CommandEvent event)
          When one of the concentration-hooks is called, stops the spell.
 void initialize()
          Adds class-default properties.
 boolean knowsCommand(java.lang.String cmd)
          Returns true if this Command wants to handle the command.
protected  Point nextPoint()
          Figures out the next point in the bolt's path.
 void propagate()
          Propagates the bolt along its path.
 void removeLight(Point p)
          Removes a light we previously added to the map.
 void setAnimated()
          Disables the standard AnimationParams behavior.
 void setBounce(boolean bounce)
          Sets whether or not the bolt bounces when blocked
 void setDuration(int duration)
          Sets the number of turns this bolt will propagate.
 void setLength(int maxlen)
          Sets the max length for the bolt.
 void setMaxLength(int maxlen)
          Sets the length of the bolt.
 void setSpeed(int speed)
          Sets the propagation speed.
protected  int sign(int s)
          Returns the sign of the integer value passed.
 void start()
          Sets the spell in the map and gets it going.
protected  void startConcentrationHooks()
          Sets up the hook callbacks so that the spell stops if you stop concentrating.
protected  void stopConcentrationHooks()
          Sets up the hook callbacks for spell concentration.
 
Methods inherited from class wyvern.lib.classes.magic.Spell
addReagent, canDamageSelf, canEnter, canEnter, castingOnSelf, cloneSpell, consumeReagents, destroy, ensureAI, ensureDirection, ensureReagents, findTargetObject, findTargetObject, fireDirection, fireLocation, getAgent, getAnimationFrames, getArt, getBlockingPredicate, getCastingDelay, getDescString, getElement, getLevel, getLoreCost, getMagicItem, getReagents, getRequiredMana, getSpellArgs, getSpellDescription, getSpellName, getTarget, getTargetName, getTargetPoint, isBlessed, isConjuration, isCursed, isEnchantment, isEvocation, isIncantation, isPotion, logUsage, makeDispellable, reloadSpells, removeFromActiveListIfPresent, setAgent, setLevel, setMagicItem, setSpellArgs, setTarget, setTargetName, setTargetPoint, tellCaster
 
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, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getLayer, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, 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, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getLayer, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, 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

DEFAULT_BOLT_SPEED

public static final int DEFAULT_BOLT_SPEED
Default rate (in millis) at which the bolt propagates. The property name for this value is "speed".

See Also:
Constant Field Values

DEFAULT_BOLT_MAX_LENGTH

public static final int DEFAULT_BOLT_MAX_LENGTH
Default length of the bolt if it encounters no obstructions. The property name for this value is "max-length".

See Also:
Constant Field Values

DEFAULT_BOLT_DURATION

public static final int DEFAULT_BOLT_DURATION
Number of turns the bolt will propagate. If less than the bolt max length, the "tail" of the bolt will start moving away from the caster before the "head" reaches the endpoint, sort of like a Star Wars laser beam. If the duration is longer than the bolt length, the bolt will become a solid beam along its entire length for (duration-length) turns.

The property name for this value is "duration".

See Also:
Constant Field Values

DUMMY_LIGHT

public static final java.lang.Object DUMMY_LIGHT
Constructor Detail

BoltSpell

public BoltSpell()
Method Detail

initialize

public void initialize()
Adds class-default properties.

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

start

public void start()
Sets the spell in the map and gets it going.

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

startConcentrationHooks

protected void startConcentrationHooks()
Sets up the hook callbacks so that the spell stops if you stop concentrating.


stopConcentrationHooks

protected void stopConcentrationHooks()
Sets up the hook callbacks for spell concentration.


hookEvent

public void hookEvent(java.lang.String hookname,
                      CommandEvent event)
When one of the concentration-hooks is called, stops the spell.

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

determineMap

protected boolean determineMap()
Figures out which map we're supposed to be in, and where.

Returns:
true if we set ourselves in a map

canPutInMap

protected boolean canPutInMap(GameMap map,
                              int x,
                              int y)
Returns true if the spell can be placed in the passed map at the specified location.


computeAngle

protected void computeAngle()
Figures out the angle the bolt is travelling at (basically, dX and dY).


sign

protected int sign(int s)
Returns the sign of the integer value passed.


nextPoint

protected Point nextPoint()
Figures out the next point in the bolt's path.


propagate

public void propagate()
Propagates the bolt along its path.


dumpList

public void dumpList()
Lists all occupied squares for debugging.


bounced

public void bounced(GameObject blocker,
                    int x,
                    int y)
Called if the spell bounces off of a blocking object. You should change the direction of the spell. Pass the blocking object and its x/y loc. The variables to change are dx_ and dy_.


dispel

public void dispel()
Shuts off the spell.

Specified by:
dispel in interface Dispellable
Overrides:
dispel in class Spell

clearVariables

protected void clearVariables()
Nulls out all instance variables.


damageMonsters

public void damageMonsters()
Damages all monsters in areas we occupy.

Overrides:
damageMonsters in class Spell

clearDamageCache

protected void clearDamageCache()
Resets the cache of monsters we've damaged this turn.


damageMonster

public void damageMonster(Damageable obj,
                          Spell spell)
Makes sure we only damage a monster one time per propagation cycle, regardless of how big it is.

Overrides:
damageMonster in class Spell
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.

setSpeed

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

Overrides:
setSpeed in class Spell
Parameters:
speed - the speed (in millis)

getSpeed

public int getSpeed()
Returns the speed at which this bolt propagates.

Overrides:
getSpeed in class Spell
Returns:
propagation speed in millis

setDuration

public void setDuration(int duration)
Sets the number of turns this bolt will propagate.

Parameters:
duration - the number of times the bolt will call propagate()

getDuration

public int getDuration()
Returns the number of turns the bolt will propagate.

Returns:
total number of turns

getAge

public int getAge()
Returns the current age of the bolt. returns int


doesBounce

public boolean doesBounce()
Returns whether or not the bolt is set to bounce off of things. returns boolean


setMaxLength

public void setMaxLength(int maxlen)
Sets the length of the bolt. Alias for setMaxLength.

Parameters:
maxlen - the maximum distance to travel.

setLength

public void setLength(int maxlen)
Sets the max length for the bolt.

Parameters:
maxlen - the maximum distance to travel.

getMaxLength

public int getMaxLength()
Returns the max length for the bolt.

Returns:
the maximum length the bolt will reach if unobstructed

getImageDescriptors

public int[] getImageDescriptors()
Returns the appearance of the spell. Bolt spells have more than one image (one per location, in fact), so they need to manage their own appearance.

Specified by:
getImageDescriptors in interface GameObject
Overrides:
getImageDescriptors in class MapObject
Returns:
the appearance for the client

getLocations

public java.util.List getLocations()
Returns the locations occupied by this spell.

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

getPoints

public java.util.Set getPoints()
Returns the locations occupied by this spell. Called by damageMonsters().

Overrides:
getPoints in class Spell
Returns:
the set of all the points we occupy

setBounce

public void setBounce(boolean bounce)
Sets whether or not the bolt bounces when blocked


getTile

public int getTile(int x,
                   int y)
Returns the image number to use at (x, y)

Specified by:
getTile in interface GameObject
Overrides:
getTile in class MapObject
Parameters:
x - map x coordinate
y - map y coordinate

getBounds

public Rectangle getBounds()
Returns the bounds of the spell.

Specified by:
getBounds in interface GameObject
Overrides:
getBounds in class MapObject
Returns:
our bounds

setAnimated

public void setAnimated()
Disables the standard AnimationParams behavior.


knowsCommand

public boolean knowsCommand(java.lang.String cmd)
Description copied from interface: Command
Returns true if this Command wants to handle the command. The Command can examine the arguments and determine that it doesn't actually understand the command, in which case it should return false.

This method exists to allow more than one game object to implement the same command verb, but with different expected arguments.

If two objects register for the same command and the same arguments, the object that was registered most recently gets to handle at the command.

Specified by:
knowsCommand in interface Command
Parameters:
cmd - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent initial)
Creates an event to propagate the bolt spell.

Specified by:
createEvent in interface Command
Parameters:
initial - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

execute

public boolean execute(CommandEvent event)
Propagates the bolt.

Specified by:
execute in interface Command
Parameters:
event - the propagation event
Returns:
true if we executed it.

getCommand

public Command getCommand(CommandEvent event)
Handle our "bolt" command ourselves. If we don't do this, the spell kinda works, because our superclass getCommand() returns null, so the Executive looks in our map location for an object to handle "bolt", and finds us. It breaks, though, if 2 bolts overlap, so we have to do this. This spell should be rewritten to use a Timer; it would be a lot simpler that way.

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

addLight

public void addLight(Point p)
Adds a light source to the map for one of our locations. The light is kept in a cache so we can retrieve it later.


removeLight

public void removeLight(Point p)
Removes a light we previously added to the map.