wyvern.kernel.monsters
Class MonsterInventory
java.lang.Object
wyvern.kernel.properties.PList
wyvern.kernel.maps.MapObject
wyvern.lib.classes.BasicBag
wyvern.kernel.monsters.MonsterInventory
- All Implemented Interfaces:
- Applyable, Bag, Broadcaster, Container, GameObject, Inventory, MethodHookable, PropertyList, SelfExternalizable
- Direct Known Subclasses:
- PlayerInventory
- public class MonsterInventory
- extends BasicBag
- implements Inventory
This class implements a simple Inventory object so that monsters
can hold things.
- Version:
- 1.0, Sep 26, 1997
- Author:
- Steve Yegge
Method Summary |
GameObject |
add(GameObject item)
Adds an item to the bag (at the end). |
protected void |
checkAddCommand(GameObject obj)
Checks if the object being added is a Command, and if
so, adds it to our set of Commands currently in
inventory. |
protected void |
checkRemoveCommand(GameObject obj)
Checks if the object being removed is a Command. |
void |
computeEncumbrance()
Computes the encumbrance level of the monster associated
with this inventory. |
GameObject |
findByHashcode(int hashcode)
Returns an object in the inventory matching the passed hashcode.
|
GameObject |
findByHashcode(java.lang.String hashcode)
Returns an object in the inventory matching the passed hashcode.
|
GameObject |
getByIndex(java.lang.String num)
Returns an item specified as a string index "#number" |
long |
getCapacity()
Returns the carrying capacity of this inventory. |
Command |
getCommand(CommandEvent event,
Commandable agent)
Iterates over the objects in the inventory, looking for an
object implementing the Command interface that claims to
know the command. |
GameMap |
getMap()
Returns the map we're in - our owner's map, or null if
we're not attached to a monster yet. |
Commandable |
getOwner()
Returns the owner of this Inventory. |
void |
insert(GameObject item,
int index)
Inserts an item into the bag at the specified index. |
boolean |
isInventory()
Overrides Container.isInventory(). |
protected void |
notifyDropped(GameObject obj)
If the object is a PickupInterest, and we have an owner,
notifies the object that it was dropped. |
GameObject[] |
objects()
Returns an array of objects from the inventory. |
boolean |
remove(GameObject item)
Removes an item from the bag; does nothing if the item isn't
in the bag. |
GameObject |
remove(int index)
Removes and returns the object at the specified index. |
java.util.List |
removeAll()
Removes and returns all the items from the bag. |
GameObject |
removeFirst()
Removes and returns the first object in the bag. |
GameObject |
removeFirst(Predicate p)
Removes the first instance of an object satisfying a Predicate. |
void |
resend(int index)
Tells the inventory that an item's appearance has changed, so
it needs to be re-sent to the client. |
void |
resendAll()
Re-sends all the inventory. |
protected void |
setContainer(GameObject obj)
Notifies the object it's being placed in the inventory,
e.g. from being picked up, or received in some way. |
GameObject |
setObjectAt(int index,
GameObject item)
Replaces the object at the specified index with a new object. |
void |
setOwner(Commandable owner)
Sets the new owner for the inventory. |
boolean |
shouldWrite()
Returns true if we should write the object at all. |
java.lang.String |
toString()
Returns a String representation of the inventory. |
java.util.List |
writeData()
Tells the object to write its properties out to a text file. |
Methods inherited from class wyvern.lib.classes.BasicBag |
addGroupable, adjust, apply, canHoldMore, checkFilter, checkWeight, contains, filter, find, findByName, getEmptyTitle, getItems, getItemWeight, getMaxCount, getPosition, getRemainingCapacity, getTitle, getWeight, hasRoomFor, hasRoomFor, indexOf, initContents, initFilter, initialize, invalidate, isBag, isEmpty, isMap, iterator, objectAt, printItemList, readData, removeAll, setCapacity, setCapacity, setCapacity, setUplinks, size, updateDescription, visitObjects, 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, 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, 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.Bag |
adjust, canHoldMore, contains, filter, find, findByName, getItemWeight, getMaxCount, getPosition, getRemainingCapacity, hasRoomFor, hasRoomFor, indexOf, invalidate, isEmpty, iterator, objectAt, printItemList, removeAll, setCapacity, setCapacity, size, visitObjects |
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, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, inContainer, initialize, 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 |
owner_
protected Commandable owner_
MonsterInventory
public MonsterInventory()
- Constructs a new MonsterInventory
isInventory
public boolean isInventory()
- Overrides Container.isInventory().
- Specified by:
isInventory
in interface Container
- Overrides:
isInventory
in class BasicBag
- Returns:
- true
resend
public void resend(int index)
- Tells the inventory that an item's appearance has changed, so
it needs to be re-sent to the client.
- Specified by:
resend
in interface Inventory
- Parameters:
index
- the index of the item to resend.
resendAll
public void resendAll()
- Re-sends all the inventory.
- Specified by:
resendAll
in interface Inventory
objects
public GameObject[] objects()
- Returns an array of objects from the inventory.
- Specified by:
objects
in interface Inventory
- Returns:
- an array of the GameObjects in the inventory
toString
public java.lang.String toString()
- Returns a String representation of the inventory. Used mostly
for examining the inventory from a debugger.
- Overrides:
toString
in class MapObject
- Returns:
- a short String describing this object. If the object
represents a group of items, such as coins, the returned
description will be a modified version of the description
that includes quantity information.
getOwner
public Commandable getOwner()
- Returns the owner of this Inventory.
- Specified by:
getOwner
in interface Inventory
- Returns:
- the monster or player we're connected to, or null
if we're being used for nefarious coding purposes.
setOwner
public void setOwner(Commandable owner)
- Sets the new owner for the inventory. Notifies all of the
objects in the inventory that they've been added to this
container.
- Specified by:
setOwner
in interface Inventory
- Parameters:
owner
- the new owner. Usually only called once,
when the inventory is created.
getMap
public GameMap getMap()
- Returns the map we're in - our owner's map, or null if
we're not attached to a monster yet.
- Specified by:
getMap
in interface GameObject
- Overrides:
getMap
in class MapObject
getCommand
public Command getCommand(CommandEvent event,
Commandable agent)
- Iterates over the objects in the inventory, looking for an
object implementing the Command interface that claims to
know the command. Returns the first object that says it
knows the command.
- Specified by:
getCommand
in interface Inventory
- Parameters:
agent
- the agent doing the commandevent
- the event to look for a handler for
- Returns:
- a Command to handle the command, or null if no
Command was registered for that command where the agent is at.
add
public GameObject add(GameObject item)
throws Bag.FullBagException
- Adds an item to the bag (at the end). Handles groupable items.
- Specified by:
add
in interface Bag
- Overrides:
add
in class BasicBag
- Parameters:
item
- a GameObject to add
- Returns:
- the added item, or group if it was added to a group
- Throws:
Bag.FullBagException
insert
public void insert(GameObject item,
int index)
throws Bag.FullBagException
- Inserts an item into the bag at the specified index.
- Specified by:
insert
in interface Bag
- Overrides:
insert
in class BasicBag
- Parameters:
index
- the index to insert at. An index less than zero
will be changed to zero (put obj at front), and an index larger
than the size of the bag will put the object at the end.
- Throws:
Bag.FullBagException
setContainer
protected void setContainer(GameObject obj)
- Notifies the object it's being placed in the inventory,
e.g. from being picked up, or received in some way.
- Overrides:
setContainer
in class BasicBag
- Parameters:
obj
- the object being placed in the inventory
remove
public GameObject remove(int index)
- Removes and returns the object at the specified index.
- Specified by:
remove
in interface Bag
- Overrides:
remove
in class BasicBag
- Parameters:
index
- the 0-based index of the element to remove.
- Returns:
- the element previously at the specified position
- Throws:
java.lang.IndexOutOfBoundsException
- if the index is out of bounds
remove
public boolean remove(GameObject item)
- Removes an item from the bag; does nothing if the item isn't
in the bag.
- Specified by:
remove
in interface Bag
- Overrides:
remove
in class BasicBag
- Parameters:
item
- the item to remove
- Returns:
- true if the item was removed
removeFirst
public GameObject removeFirst()
- Removes and returns the first object in the bag.
- Specified by:
removeFirst
in interface Bag
- Overrides:
removeFirst
in class BasicBag
- Returns:
- the first object, or null if the bag is empty
removeFirst
public GameObject removeFirst(Predicate p)
- Removes the first instance of an object satisfying a Predicate.
- Specified by:
removeFirst
in interface Bag
- Overrides:
removeFirst
in class BasicBag
- Parameters:
p
- a Predicate that returns true if the object is "the one"
- Returns:
- the first object satisfying the predicate, or null
if it didn't find any objects that satisfied the predicate
- See Also:
Predicate
removeAll
public java.util.List removeAll()
- Removes and returns all the items from the bag.
- Specified by:
removeAll
in interface Bag
- Overrides:
removeAll
in class BasicBag
- Returns:
- a List containing all the GameObjects from the bag;
the bag will be empty after this call.
setObjectAt
public GameObject setObjectAt(int index,
GameObject item)
throws Bag.FullBagException
- Replaces the object at the specified index with a new object.
- Specified by:
setObjectAt
in interface Bag
- Overrides:
setObjectAt
in class BasicBag
- Parameters:
index
- the index to replace; if greater than the end of
the list, the object will be appended; if less than zero, the
object will be prepended.item
- the object to replace
- Returns:
- the replaced object, or null if none was replaced
- Throws:
Bag.FullBagException
findByHashcode
public GameObject findByHashcode(java.lang.String hashcode)
- Returns an object in the inventory matching the passed hashcode.
Used to target specific objects (e.g. using mouse actions) when
more than one object might have the same description.
- Specified by:
findByHashcode
in interface Inventory
- Parameters:
hashcode
- the hashcode for the object (as a string)
- Returns:
- the matching object, or null if not found
findByHashcode
public GameObject findByHashcode(int hashcode)
- Returns an object in the inventory matching the passed hashcode.
Used to target specific objects (e.g. using mouse actions) when
more than one object might have the same description.
- Specified by:
findByHashcode
in interface Inventory
- Parameters:
hashcode
- the hashcode for the object
- Returns:
- the matching object, or null if not found
getByIndex
public GameObject getByIndex(java.lang.String num)
- Returns an item specified as a string index "#number"
- Specified by:
getByIndex
in interface Inventory
- Parameters:
num
- the input string, e.g. "#3".
- Returns:
- the object at that index, or null if the index
is out of bounds
notifyDropped
protected void notifyDropped(GameObject obj)
- If the object is a PickupInterest, and we have an owner,
notifies the object that it was dropped.
- Parameters:
obj
- the object to notify
getCapacity
public long getCapacity()
- Returns the carrying capacity of this inventory.
- Specified by:
getCapacity
in interface Bag
- Overrides:
getCapacity
in class BasicBag
- Returns:
- the carrying capacity in grams
shouldWrite
public boolean shouldWrite()
- Returns true if we should write the object at all.
- Specified by:
shouldWrite
in interface SelfExternalizable
- Overrides:
shouldWrite
in class BasicBag
- Returns:
- false if the inventory is empty; no point in writing
out an empty inventory
computeEncumbrance
public void computeEncumbrance()
- Computes the encumbrance level of the monster associated
with this inventory. Whenever something is added or removed,
the monster's encumbrance is recalculated (which in turn
affects the monster's move-speed). If you change the monster's
strength on the fly, you should call the inventory's setCapacity()
method, which will call this to recompute the encumbrance level.
- Specified by:
computeEncumbrance
in interface Inventory
writeData
public java.util.List writeData()
throws java.lang.Exception
- Tells the object to write its properties out to a text file.
- Specified by:
writeData
in interface SelfExternalizable
- Overrides:
writeData
in class BasicBag
- Returns:
- a String representation that can be written to the
text file.
- Throws:
java.lang.Exception
checkAddCommand
protected void checkAddCommand(GameObject obj)
- Checks if the object being added is a Command, and if
so, adds it to our set of Commands currently in
inventory.
checkRemoveCommand
protected void checkRemoveCommand(GameObject obj)
- Checks if the object being removed is a Command. If
so, removes it from our set of Commands currently in
inventory.