wyvern.lib.classes.weapons
Class WeaponImpl

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.weapons.WeaponImpl
All Implemented Interfaces:
Applyable, Attack, Broadcaster, Damageable, GameObject, MethodHookable, Movable, PickupInterest, PropertyList, Readyable, Weapon
Direct Known Subclasses:
HurledWeapon, MeleeWeapon, Missile, RangeWeapon

public abstract class WeaponImpl
extends MapObject
implements Weapon, PickupInterest, Applyable

Superclass for all weapons. The three basic classes that derive from Weapon are MeleeWeapon, RangeWeapon and HurledWeapon. Missiles also derive from weapon, although they're a special case.

Version:
1.0, Sep 07, 1997
Author:
Steve Yegge

Field Summary
static int DEFAULT_WEAPON_HP
           
protected  java.util.List wcs_
          The list of damage types done by this weapon.
 
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
 
Constructor Summary
WeaponImpl()
           
 
Method Summary
 java.util.List addSlayWC()
          Adds the slay-wc to the list of standard WCs for this weapon and returns it.
 void adjustHP(int adjust)
          Adjusts the object's hit points upwards or downwards.
 void apply(Commandable agent)
          Called by the ApplyCommand when the agent performs "apply".
 boolean canReady(Commandable agent)
          Checks if the specified Commandable may ready the object.
 boolean canUnready(Commandable agent)
          Checks whether the specified agent may unready the object, assuming they've already got it readied.
 java.lang.String checkDrop(Commandable agent, Container dest)
          Checks whether the object can be dropped, thrown, given away, put in a bag, or otherwise disposed of by the bearer.
 CommandEvent checkHit(Monster m)
          Code for throwing your weapon at something.
 void destroy()
          Destroys the weapon, unwielding it and removing it from the parent inventory, bag, or map.
 void didDamage(DamageEvent event)
          Notification that the weapon just did some damage.
 void dropped(Commandable agent)
          Notifies the object that the specified agent has dropped it.
 void forceUnwield()
          Forcibly unwields the weapon, even if it's cursed.
 java.lang.String getDescription()
          Returns the long description for the object.
 int getHP()
          Returns the object's current hit points.
 int getMaxHP()
          Returns the object's maximum hit points.
 java.lang.Class[] getRequiredSlots()
          Returns a list of the slots that this armor requires in order to be worn.
 int getToHit()
          Returns the base chance to hit for the weapon, against all attackers.
 java.util.List getWC(GameObject opponent)
          Returns the damage(s) to use against the specified opponent.
protected  boolean hitMonster(Monster m)
          Invokes the HitCommand to check if we hit the monster.
 void initialize()
          Initializes the object's default properties.
 boolean isReadied()
          Returns true if this object is currently readied.
 boolean isWielded()
          Returns true if the weapon has the "wielded" property
 void kill(GameObject attacker)
          Destroys the weapon and removes it from the agent's inventory and attacks list.
 void notifyReady(Commandable agent)
          Notifies the Readyable object that the agent has readied it.
 void notifyUnready(Commandable agent)
          Unreadies the object.
 void pickedUp(Commandable agent)
          Notifies the object that the specified agent has picked it up.
 void recomputeWCs()
          If you set any "wc-*" property on the weapon directly, bypassing the setWC() function, you need to call this or the WC won't be recomputed.
protected  void setDefaultHP()
          Initializes HP for the weapon.
 void setShowAttackerMessage(boolean show)
          Toggles showing the attacker message for the damage event.
 void setToHit(int tohit)
          Sets the base chance to hit for the weapon, against all attackers.
 void setWC(java.lang.String name, int wc)
          Sets the base weapon-class of this weapon.
 boolean setWielded(boolean wielded, Commandable agent)
          Notifies the weapon it's being wielded.
 boolean shouldStop(Point loc)
          Function called on every move for a thrown/fired weapon or missile.
 boolean showAttackerMessage()
          Returns true if we show the attacker message.
 java.lang.String toString()
          Returns the name plus "(wielded)" if wielded.
protected  boolean tryGettingCaught(Monster mon)
          If the object is catchable, try sticking it in the Monster's inventory.
 
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, curse, cycleFrame, 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, getValue, 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, 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, curse, cycleFrame, 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, getValue, 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
 
Methods inherited from interface wyvern.lib.Attack
getWeaponSkill
 

Field Detail

DEFAULT_WEAPON_HP

public static final int DEFAULT_WEAPON_HP
See Also:
Constant Field Values

wcs_

protected java.util.List wcs_
The list of damage types done by this weapon.

Constructor Detail

WeaponImpl

public WeaponImpl()
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 MapObject

setDefaultHP

protected void setDefaultHP()
Initializes HP for the weapon. If it has a max-hp property, it just returns. You can set the max-hp and hp differently in the archetype (or a subclass) if you always want the weapon to start out damaged.


setWielded

public boolean setWielded(boolean wielded,
                          Commandable agent)
Description copied from interface: Weapon
Notifies the weapon it's being wielded.

NOTE: don't call this to try to wield a weapon. You should command the agent to wield the weapon - this will invoke the WieldCommand and make sure the agent has enough body parts available to wield the weapon. This setWielded() function will be called automatically by the WieldCommand. Don't use it to unwield a weapon either - use forceUnwield().

This method runs a method hook called "setWielded". It passes the wielder as the data parameter. You can call isWielded() on the weapon in the method hook to see if it was being wielded or unwielded. If isWielded() returns false, it was being unwielded. The setWielded method-hook is run *after* this method executes, right before the return statement, so all the bonuses are already applied.

Specified by:
setWielded in interface Weapon
Parameters:
wielded - true if it's wielded, else false
Returns:
true if the weapon is OK with being wielded or unwielded. If false, the weapon should consider issuing a message to the agent about why the operation failed.

isWielded

public boolean isWielded()
Description copied from interface: Weapon
Returns true if the weapon has the "wielded" property

Specified by:
isWielded in interface Weapon
Returns:
true if the weapon is being wielded

getRequiredSlots

public java.lang.Class[] getRequiredSlots()
Description copied from interface: Weapon
Returns a list of the slots that this armor requires in order to be worn. Usually the list has only one slot: a HoldingSlot. Weapons can override this method to require more (or different) slots.

Specified by:
getRequiredSlots in interface Weapon
Returns:
a Class[] containing references to the ItemSlot classes required to wield the weapon.

pickedUp

public void pickedUp(Commandable agent)
Description copied from interface: PickupInterest
Notifies the object that the specified agent has picked it up.

Specified by:
pickedUp in interface PickupInterest
Parameters:
agent - the agent picking up the object

dropped

public void dropped(Commandable agent)
Description copied from interface: PickupInterest
Notifies the object that the specified agent has dropped it.

Specified by:
dropped in interface PickupInterest
Parameters:
agent - the agent that dropped the object

getWC

public java.util.List getWC(GameObject opponent)
Description copied from interface: Attack
Returns the damage(s) to use against the specified opponent. The default behavior is to ignore the opponent parameter and return a list of the damages this weapon does.

Specified by:
getWC in interface Attack
Parameters:
opponent - the thing being attacked. Can be null! The weapon should check for this case. The weapon is free to ignore the opponent and return the same wc for every opponent.
Returns:
a list of DamageType objects, with the appropriate wc set in each one. Can return null if no attacks are appropriate.

addSlayWC

public java.util.List addSlayWC()
Adds the slay-wc to the list of standard WCs for this weapon and returns it.


setWC

public void setWC(java.lang.String name,
                  int wc)
Description copied from interface: Attack
Sets the base weapon-class of this weapon.

Specified by:
setWC in interface Attack
Parameters:
wc - the new base wc for the weapon
name - the damage type, e.g. "cut", "smash", "fire".

recomputeWCs

public void recomputeWCs()
Description copied from interface: Attack
If you set any "wc-*" property on the weapon directly, bypassing the setWC() function, you need to call this or the WC won't be recomputed. The WC for a weapon is cached since it's fairly expensive to compute.

Specified by:
recomputeWCs in interface Attack

getToHit

public int getToHit()
Returns the base chance to hit for the weapon, against all attackers.

Specified by:
getToHit in interface Attack
Returns:
the chance to hit, which for Weapons is stored in their "to-hit" property.

setToHit

public void setToHit(int tohit)
Sets the base chance to hit for the weapon, against all attackers.

Specified by:
setToHit in interface Attack
Parameters:
tohit - the chance to hit, which for Weapons is stored in their "to-hit" property.

didDamage

public void didDamage(DamageEvent event)
Description copied from interface: Attack
Notification that the weapon just did some damage. Does nothing by default, but hooks and subclasses can use it if they want.

This method runs a method hook called "didDamage", and passes the event along as the data parameter.

Specified by:
didDamage in interface Attack
Parameters:
event - the damage-event associated with the damage. The event will have parameters set by the combat system (by the DamageCommand, in particular), including the hit location, attacker, defender, total damage, and others.

apply

public void apply(Commandable agent)
Description copied from interface: Applyable
Called by the ApplyCommand when the agent performs "apply".

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

getHP

public int getHP()
Description copied from interface: Damageable
Returns the object's current hit points.

Specified by:
getHP in interface Damageable

getMaxHP

public int getMaxHP()
Description copied from interface: Damageable
Returns the object's maximum hit points.

Specified by:
getMaxHP in interface Damageable

adjustHP

public void adjustHP(int adjust)
Description copied from interface: Damageable
Adjusts the object's hit points upwards or downwards.

Specified by:
adjustHP in interface Damageable
Parameters:
adjust - a number (usually negative) to add to the object's hp

kill

public void kill(GameObject attacker)
Destroys the weapon and removes it from the agent's inventory and attacks list.

Specified by:
kill in interface Damageable
Parameters:
attacker - the thing that destroyed it

destroy

public void destroy()
Destroys the weapon, unwielding it and removing it from the parent inventory, bag, or map.

Runs a method-hook called "destroy" with no args after the item is destroyed (and unwielded).

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

forceUnwield

public void forceUnwield()
Description copied from interface: Weapon
Forcibly unwields the weapon, even if it's cursed. This method just calls WieldCommand.forceUnwield() on the agent currently wielding the weapon. Does nothing if not wielded.

Specified by:
forceUnwield in interface Weapon

checkHit

public CommandEvent checkHit(Monster m)
Code for throwing your weapon at something. Returns true if we should hit (and damage) the specified monster.

Parameters:
m - the monster to shoot at

shouldStop

public boolean shouldStop(Point loc)
Description copied from interface: Movable
Function called on every move for a thrown/fired weapon or missile. Checks if it should stop moving at this square. If so, possibly damages a monster or object there.

Specified by:
shouldStop in interface Movable
Parameters:
loc - the point the object currently occupies
Returns:
true if it should stop moving, either because it it something, or it ran out of steam and fell. If it's stopping, the weapon should handle any stop cases here, such as hitting a monster and doing damage.

tryGettingCaught

protected boolean tryGettingCaught(Monster mon)
If the object is catchable, try sticking it in the Monster's inventory. If it fails, drop it on the ground.

Parameters:
mon - the monster we hit, and stopped at.

hitMonster

protected boolean hitMonster(Monster m)
Invokes the HitCommand to check if we hit the monster. If so, creates a HitEvent and pushes it at the front of the monster's queue.

Parameters:
m - the monster we may hit
Returns:
true if we hit the monster, false to keep going

canReady

public boolean canReady(Commandable agent)
Description copied from interface: Readyable
Checks if the specified Commandable may ready the object.

Specified by:
canReady in interface Readyable
Parameters:
agent - the Commandable trying to ready the object
Returns:
true if it's allowed to do so.

canUnready

public boolean canUnready(Commandable agent)
Description copied from interface: Readyable
Checks whether the specified agent may unready the object, assuming they've already got it readied. For instance, if the object is cursed, it might not be unreadiable.

Specified by:
canUnready in interface Readyable
Parameters:
agent - the person who has the item readied
Returns:
true if we can unready it

notifyReady

public void notifyReady(Commandable agent)
Description copied from interface: Readyable
Notifies the Readyable object that the agent has readied it.

Specified by:
notifyReady in interface Readyable
Parameters:
agent - the agent using it

notifyUnready

public void notifyUnready(Commandable agent)
Description copied from interface: Readyable
Unreadies the object. If you call this on the object directly, make sure to remove the agent's "@readied" property as well, or they'll still be able to use the object.

Specified by:
notifyUnready in interface Readyable
Parameters:
agent - the agent using the object

isReadied

public boolean isReadied()
Description copied from interface: Readyable
Returns true if this object is currently readied.

Specified by:
isReadied in interface Readyable

checkDrop

public java.lang.String checkDrop(Commandable agent,
                                  Container dest)
Description copied from interface: GameObject
Checks whether the object can be dropped, thrown, given away, put in a bag, or otherwise disposed of by the bearer. Handles checks for, e.g. cursed weapons, worn armor, etc. If you override this method, don't forget to call the superclass version, which prevents dropping auctioned items outside of auction houses, and prevents dropping kept (non-auctioned) items at all.

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

setShowAttackerMessage

public void setShowAttackerMessage(boolean show)
Description copied from interface: Attack
Toggles showing the attacker message for the damage event.

Specified by:
setShowAttackerMessage in interface Attack
Parameters:
show - true to show the attacker message, false to hide it.

showAttackerMessage

public boolean showAttackerMessage()
Description copied from interface: Attack
Returns true if we show the attacker message.

Specified by:
showAttackerMessage in interface Attack
Returns:
true, by default (subclass can override.)

getDescription

public java.lang.String getDescription()
Returns the long description for the object. Shows the level requirement, if any.

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

toString

public java.lang.String toString()
Returns the name plus "(wielded)" if wielded. Also supports the "enchantment" property directly by prepending the level of enchantment if nonzero.

Overrides:
toString in class MapObject
Returns:
the short description for the weapon