wyvern.lib.classes.magic
Class Book

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.DynamicObject
              extended bywyvern.lib.classes.magic.Book
All Implemented Interfaces:
Applyable, Broadcaster, Command, Damageable, GameObject, MethodHookable, PropertyList, Readable

public class Book
extends DynamicObject
implements Readable, Applyable, Command

Spellbook class - you can learn spells from it.

Version:
1.0, May 01, 1998
Author:
Steve Yegge, Eric Weber

Field Summary
 
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.properties.Readable
DEFAULT_READ_DELAY
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
Book()
           
 
Method Summary
 void apply(Commandable agent)
          Someone's applying us.
 void blindAgent(Commandable agent)
          Blinds the agent, if the book is cursed.
protected  java.lang.String constructDescription()
           
 CommandEvent createEvent(CommandEvent initial)
          Creates a CommandEvent that encapsulates all the state necessary to perform the command.
protected  boolean deductLorePoints(Player p, java.lang.String spell)
          Deducts the lore points for learning this spell.
protected  SpellList ensureSpellList(CommandEvent event)
          Finds or creates the SpellList for the player.
 void erase()
          Erases the spell book.
 boolean execute(CommandEvent event)
          Executes the specified CommandEvent.
protected  boolean failsPreconditions(CommandEvent event)
          Checks various preconditions: empty spellbook, unpaid, up for auction, used, etc.
protected  boolean failsRestrictionReason(CommandEvent event)
          Looks for a Predicate bean property called "restriction".
 java.lang.String getDescription()
          Returns the long description for the book.
 java.lang.String getSpell()
          Returns the "spell" property of this book, e.g.
 int getValue()
          Returns the shop price of the book.
static int getValueForLoreLevel(int lore)
          Computes how much a spellbook should cost based on its lore level.
 boolean hasSpell()
          Returns true if we have a spell
 void initialize()
          Initializes the object's default properties.
 boolean isUsed()
          Returns true if this spellbook is used up.
 boolean knowsCommand(java.lang.String command)
          Returns true for "learn" command, if the argument of the command is this book.
static void main(java.lang.String[] args)
          Tests spellbook costs.
 void read(Commandable agent)
          Someone's reading the book.
protected  void setSuccessMessage(CommandEvent event)
          Creates the message to print if the player succeeds in learning the spell.
 
Methods inherited from class wyvern.lib.classes.DynamicObject
adjustHP, computeHP, getHP, getMaxHP, kill
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, 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, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, externalize, getAlpha, getAppearance, getArchetype, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getWeight, inContainer, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, 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.MethodHookable
addMethodHook, removeMethodHook, runMethodHook
 
Methods inherited from interface wyvern.lib.Broadcaster
broadcast, broadcast, broadcast, broadcast, broadcast
 

Constructor Detail

Book

public Book()
Method Detail

initialize

public void initialize()
Description copied from interface: GameObject
Initializes the object's default properties. Any GameObject implementation that wishes to initialize itself should do so here, rather than in the constructor. This is because nearly all game objects inherit from an archetype, and the archetype parent pointer isn't set until the object's constructor finishes. This is a good place to add any class-default properties for an object - properties that the object gets regardless of which archetype it inherits from. WARNING: don't forget to call the superclass' initialize() method, or the object may not function properly. For instance, it won't become animated even if it specifies animation parameters in the archetype.

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

read

public void read(Commandable agent)
Someone's reading the book. Show spell description.

Specified by:
read in interface Readable
Parameters:
agent - the reader

apply

public void apply(Commandable agent)
Someone's applying us. Calls read().

Specified by:
apply in interface Applyable
Parameters:
agent - the person applying the object

knowsCommand

public boolean knowsCommand(java.lang.String command)
Returns true for "learn" command, if the argument of the command is this book.

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

createEvent

public CommandEvent createEvent(CommandEvent initial)
Creates a CommandEvent that encapsulates all the state necessary to perform the command.

Specified by:
createEvent in interface Command
Parameters:
initial - a "blank" CommandEvent.
Returns:
a TargetedEvent encapsulating this command's execution parameters and state.

failsPreconditions

protected boolean failsPreconditions(CommandEvent event)
Checks various preconditions: empty spellbook, unpaid, up for auction, used, etc. Vetoes the event with a custom error message (e.g. "You must pay for it first.") if the spell can't be learned.

Parameters:
event - the "learn" event, a TargetedEvent whose target is this book.
Returns:
true if the event was vetoed

failsRestrictionReason

protected boolean failsRestrictionReason(CommandEvent event)
Looks for a Predicate bean property called "restriction". If present, it passes the event's agent to the predicate.

Parameters:
event - the event for learning the spell.
Returns:
true if there was a "restriction" Predicate and the predicate returned false (meaning the agent didn't meet the restriction.)

ensureSpellList

protected SpellList ensureSpellList(CommandEvent event)
Finds or creates the SpellList for the player.

Parameters:
event - the "learn" TargetedEvent
Returns:
the SpellList for the player. This method will create one for the player if they have the Lore skill but haven't created a SpellList yet. Returns null if the player doesn't have the Lore skill.

setSuccessMessage

protected void setSuccessMessage(CommandEvent event)
Creates the message to print if the player succeeds in learning the spell. Can be retrieved later via event.getSuccessMessage().


execute

public boolean execute(CommandEvent event)
Executes the specified CommandEvent.

Specified by:
execute in interface Command
Parameters:
event - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.

deductLorePoints

protected boolean deductLorePoints(Player p,
                                   java.lang.String spell)
Deducts the lore points for learning this spell.

Parameters:
p - the player learning the spell
spell - the name of the spell, e.g. "frost ward"
Returns:
true if we managed to look up the lore cost and deduct the points. If false, issues a message to the player

blindAgent

public void blindAgent(Commandable agent)
Blinds the agent, if the book is cursed.


erase

public void erase()
Erases the spell book.


getValue

public int getValue()
Returns the shop price of the book.

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

getValueForLoreLevel

public static int getValueForLoreLevel(int lore)
Computes how much a spellbook should cost based on its lore level.

Parameters:
lore - the spell Lore level
Returns:
the shop value of the book

getDescription

public java.lang.String getDescription()
Returns the long description for the book.

Specified by:
getDescription in interface GameObject
Overrides:
getDescription in class MapObject
Returns:
the description

constructDescription

protected java.lang.String constructDescription()

getSpell

public java.lang.String getSpell()
Returns the "spell" property of this book, e.g. "lightning bolt".

Returns:
the display name of the spell, null if it's a blank book

hasSpell

public boolean hasSpell()
Returns true if we have a spell

Returns:
true if there's a spell in the "spell" property - doesn't necessarily have to be in the registry

isUsed

public boolean isUsed()
Returns true if this spellbook is used up.

Returns:
hasProperty("used")

main

public static void main(java.lang.String[] args)
Tests spellbook costs.