wyvern.lib.classes
Class Corpse

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.BasicBag
              extended bywyvern.lib.classes.Corpse
All Implemented Interfaces:
Applyable, Bag, Broadcaster, Container, GameObject, MethodHookable, PropertyList, SelfExternalizable

public class Corpse
extends BasicBag

This is the generic Corpse interface in the game, the thing that is left behind with a monster/player dies.

Version:
1.0, Aug 05, 1999
Author:
Todd Stumpf

Nested Class Summary
static class Corpse.CorpseState
          Uses the State pattern to represent the state of the corpse, and handle state transitions.
 
Nested classes inherited from class wyvern.lib.Bag
Bag.FullBagException, Bag.InvalidItemException
 
Field Summary
static int DECAY_DELAY
          How fast corpses decay to each successive state, in millis.
static int DEFAULT_CORPSE_CHANCE
          Default chance that a monster will leave a corpse.
static int DEFAULT_POISON_ADJUST
          Default amount to add to poisonousness every time state changes.
static int MAX_CORPSE_TILE_SIZE
          We don't allow corpses larger than this many tiles on a side.
protected  Corpse.CorpseState state_
           
 
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.Bag
BAG_CUT_PERCENT_CAP, BAG_DEFAULT_CAPACITY
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
Corpse()
          Constructs a new Corpse
Corpse(Monster mon)
          Create a good corpse for the supplied monster
 
Method Summary
 void apply(Commandable agent)
          Eats the corpse instead of getting all.
protected  int computeNutritionValue()
          Returns the food amount for this corpse, for the "eat" command.
 void curseRandomItem()
          Curses a random item on the corpse.
protected  void ensurePoisonAdjustProperty(Monster monster)
          Copies the "corpse-poison-adjust" property from the monster, if any.
 void finishStateChange()
          Called when we switch states (except for going from putrid to destroying the corpse).
static int getCorpseChance(GameObject monster)
          Returns the chance (in 100) that the monster will leave a corpse.
 int getPoisonAdjust()
          Returns amount by which to increase poison for this corpse.
 int getPoisonAmount()
          Returns the value of the "poison-corpse" int property.
 Corpse.CorpseState getState()
          Returns the current decay-state of the corpse.
 void increasePoison()
          Increases the poison-level of the corpse by getPoisonIncrease().
 void initialize()
          Initializes the object's default properties.
 boolean isPoisoned()
          Returns true if the corpse has a nonzero "poison-corpse" property.
static boolean makeCorpse(Monster monster, GameObject attacker)
          Makes a corpse from the monster.
protected  void makePoisonousIfNecessary(Monster monster)
          Transfers the "poison-corpse" property from the monster to the corpse, if any.
 void remove()
          Removes from map (and decay timer).
 void setCorpseName(Monster mon)
          Initializes the corpse name from the monster name.
 void setMap(GameMap map, int x, int y)
          Sets the corpse in the map - starts decay timer.
 void setMonster(Monster mon)
          Sets the monster that this corpse came from.
 void setPoisonAdjust(int adjust)
          Sets the amount to add to "poison-corpse" each time corpse changes state.
 void setSizeFromImage(java.awt.Image img)
          Sets the size from specified image's dimensions.
 void setSizeFromImage(java.lang.String path)
          Sets the size of the corpse to match the size of the image.
static boolean shouldSkipCorpse(Monster monster)
          Returns true if we should skip the corpse creation for this monster.
 void timerExpired()
          Decay timer went off.
 
Methods inherited from class wyvern.lib.classes.BasicBag
add, addGroupable, adjust, canHoldMore, checkFilter, checkWeight, contains, filter, find, findByName, getCapacity, getEmptyTitle, getItems, getItemWeight, getMaxCount, getPosition, getRemainingCapacity, getTitle, getWeight, hasRoomFor, hasRoomFor, indexOf, initContents, initFilter, insert, invalidate, isBag, isEmpty, isInventory, isMap, iterator, objectAt, printItemList, readData, remove, remove, removeAll, removeAll, removeFirst, removeFirst, setCapacity, setCapacity, setCapacity, setContainer, setObjectAt, setUplinks, shouldWrite, size, updateDescription, visitObjects, writeData, writeItemList
 
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, 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, 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, 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, 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, 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, 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, removeContainerChangeListener, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDirection, setImage, setImage, setLayer, setLocations, 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
 

Field Detail

DEFAULT_CORPSE_CHANCE

public static final int DEFAULT_CORPSE_CHANCE
Default chance that a monster will leave a corpse. This default can be overridden by setting an int property on the monster called "corpse-chance".

See Also:
Constant Field Values

DECAY_DELAY

public static final int DECAY_DELAY
How fast corpses decay to each successive state, in millis. Cannot be overridden, since corpses all decay on a single game-wide timer.

See Also:
Constant Field Values

MAX_CORPSE_TILE_SIZE

public static final int MAX_CORPSE_TILE_SIZE
We don't allow corpses larger than this many tiles on a side.

See Also:
Constant Field Values

DEFAULT_POISON_ADJUST

public static final int DEFAULT_POISON_ADJUST
Default amount to add to poisonousness every time state changes. Can be overridden by putting a "corpse-poison-adjust" property on the monster (or the corpse).

See Also:
Constant Field Values

state_

protected Corpse.CorpseState state_
Constructor Detail

Corpse

public Corpse()
Constructs a new Corpse


Corpse

public Corpse(Monster mon)
Create a good corpse for the supplied monster

Parameters:
mon - the monster to make a corpse for
Method Detail

makeCorpse

public static boolean makeCorpse(Monster monster,
                                 GameObject attacker)
Makes a corpse from the monster. If "no-corpse" property is set, no corpse is created. Puts the corpse on the ground, and if no corpse is created, the monster's inventory drops to the ground instead.

Parameters:
monster - the Monster to make a corpse for
attacker - the thing that killed the monster. Sets the attacker's toString() in a "killed-by" property on the corpse.
Returns:
true if we made a corpse, false if we skipped it and just dropped the inventory

shouldSkipCorpse

public static boolean shouldSkipCorpse(Monster monster)
Returns true if we should skip the corpse creation for this monster.

Parameters:
monster - the monster to maybe make a corpse for
Returns:
true if we should skip making the corpse, false if we should leave one. If the monster has "no-corpse", always returns true. Otherwise returns true if we fail the die-roll for getCorpseChance().

getCorpseChance

public static int getCorpseChance(GameObject monster)
Returns the chance (in 100) that the monster will leave a corpse.

Returns:
the chance in 100. Use Range.percent() and try to roll less than this chance, to see if you should leave a corpse.

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 BasicBag

setMonster

public void setMonster(Monster mon)
Sets the monster that this corpse came from.


setCorpseName

public void setCorpseName(Monster mon)
Initializes the corpse name from the monster name.

Parameters:
mon - the monster we're using to initialize the corpse

setSizeFromImage

public void setSizeFromImage(java.lang.String path)
Sets the size of the corpse to match the size of the image. Defaults to 1x1 if any problems are encountered.

Parameters:
path - the relative path to the image, under wyvern/wiz/ or wyvern/art/game/.

setSizeFromImage

public void setSizeFromImage(java.awt.Image img)
Sets the size from specified image's dimensions. Does nothing if the image is invalid.

Parameters:
img - the image to set the size from.

timerExpired

public void timerExpired()
Decay timer went off. Default behavior is to transition to the next CorpseState.


finishStateChange

public void finishStateChange()
Called when we switch states (except for going from putrid to destroying the corpse). Default behavior is to curse a random item in the corpse's inventory.


increasePoison

public void increasePoison()
Increases the poison-level of the corpse by getPoisonIncrease(). Called whenever corpse state changes.


getPoisonAmount

public int getPoisonAmount()
Returns the value of the "poison-corpse" int property.


getPoisonAdjust

public int getPoisonAdjust()
Returns amount by which to increase poison for this corpse.

Returns:
the value of the "corpse-poison-adjust" int property

setPoisonAdjust

public void setPoisonAdjust(int adjust)
Sets the amount to add to "poison-corpse" each time corpse changes state.

Parameters:
adjust - the amount to add to the poison you take from eating the corpse.

curseRandomItem

public void curseRandomItem()
Curses a random item on the corpse.


getState

public Corpse.CorpseState getState()
Returns the current decay-state of the corpse.


setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Sets the corpse in the map - starts decay timer.

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

remove

public void remove()
Removes from map (and decay timer).

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

apply

public void apply(Commandable agent)
Eats the corpse instead of getting all.

Specified by:
apply in interface Applyable
Overrides:
apply in class BasicBag

computeNutritionValue

protected int computeNutritionValue()
Returns the food amount for this corpse, for the "eat" command. You can override this by setting the "edible" property.


makePoisonousIfNecessary

protected void makePoisonousIfNecessary(Monster monster)
Transfers the "poison-corpse" property from the monster to the corpse, if any.


ensurePoisonAdjustProperty

protected void ensurePoisonAdjustProperty(Monster monster)
Copies the "corpse-poison-adjust" property from the monster, if any. If there's none, sets "corpse-poison-adjust" to DEFAULT_POISON_ADJUST.


isPoisoned

public boolean isPoisoned()
Returns true if the corpse has a nonzero "poison-corpse" property.