wyvern.kernel.player
Class PlayerInventory

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

public class PlayerInventory
extends MonsterInventory
implements SelfExternalizable

A basic implementation of the Inventory interface. It handles updating the client when its contents change. Currently it's only capable of updating a single client; it would be impossible for a Wiz client to have a "spy" view of a client's inventory. We should fix this.

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

Nested Class Summary
 
Nested classes inherited from class wyvern.lib.Bag
Bag.FullBagException, Bag.InvalidItemException
 
Field Summary
protected  RemoteInventory client_
           
protected  long lastWallet_
           
static int MAX_ITEMS
          We don't allow players to carry more than this many items in their top-level inventory, because it has performance issues.
 
Fields inherited from class wyvern.kernel.monsters.MonsterInventory
owner_
 
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
PlayerInventory()
           
PlayerInventory(RemoteInventory client, Player p)
           
 
Method Summary
 GameObject add(GameObject obj)
          Adds an item to the bag (at the end).
 void adjust(GameObject obj, int index)
          Adjusts the position of an item in the list without removing it and adding it (thereby skipping the encumbrance and other checks).
 boolean canHoldMore()
          Returns true if we're not at our max count for this bag.
protected  void checkWeight(GameObject item)
          Wiz inventories have no weight restrictions.
 void computeEncumbrance()
          Computes the encumbrance level of the monster associated with this inventory.
 java.lang.Object createClone()
           
 long getCapacity()
          Returns the carrying capacity of this inventory.
 java.lang.String getCommands(GameObject obj)
          Returns a string containing the commands valid for this object, for displaying in a popup menu on the client when click on the object in inventory.
 int getMaxCount()
          Returns the maximum number of items that can be stored in this bag.
 boolean hasRoomFor(GameObject obj)
          Returns true if the specified object could be added to the bag's current contents without exceeding the bag's weight capacity.
 void insert(GameObject obj, int index)
          Inserts an item into the bag at the specified index.
 void invalidate(GameObject obj)
          Visually invalidates the specified object in the container.
protected  void notifyDropped(GameObject obj)
          Notifies Readyable objects that they've been unreadied.
 void readData(org.w3c.dom.Node bean)
          Tells the object to parse its externalized representation from a list of lines.
 boolean remove(GameObject target)
          Removes an item from the bag; does nothing if the item isn't in the bag.
 java.util.List removeAll()
          Removes and returns all the items from 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.
 GameObject setObjectAt(int index, GameObject item)
          Replaces the object at the specified index with a new object.
 void setOwner(Player p)
          Sets the player for this inventory.
 void setRemoteInventory(RemoteInventory inv)
          Sets a new RemoteInventory to talk to, e.g. after a reconnect from net-death.
 java.lang.String toString()
          Returns a String representation of the inventory.
protected  void updateGold()
          Updates the gold-display on the client when coins enter or leave the inventory.
 java.util.List writeData()
          Tells the object to write its properties out to a text file.
 
Methods inherited from class wyvern.kernel.monsters.MonsterInventory
checkAddCommand, checkRemoveCommand, findByHashcode, findByHashcode, getByIndex, getCommand, getMap, getOwner, isInventory, objects, remove, removeFirst, setContainer, setOwner, shouldWrite
 
Methods inherited from class wyvern.lib.classes.BasicBag
addGroupable, apply, checkFilter, contains, filter, find, findByName, getEmptyTitle, getItems, getItemWeight, getPosition, getRemainingCapacity, getTitle, getWeight, hasRoomFor, indexOf, initContents, initFilter, initialize, isBag, isEmpty, isMap, iterator, objectAt, printItemList, 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.properties.SelfExternalizable
shouldWrite
 
Methods inherited from interface wyvern.lib.Bag
contains, filter, find, findByName, getItemWeight, getPosition, getRemainingCapacity, hasRoomFor, indexOf, 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
 
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.Container
isBag, isMap
 

Field Detail

MAX_ITEMS

public static final int MAX_ITEMS
We don't allow players to carry more than this many items in their top-level inventory, because it has performance issues. Whenever you type any command, including moving around and casting spells, the game searches everything in your top-level inventory to see if you're carrying something that wants to handle or override the command. This is slow, so we force players to put stuff in bags.

See Also:
Constant Field Values

client_

protected RemoteInventory client_

lastWallet_

protected long lastWallet_
Constructor Detail

PlayerInventory

public PlayerInventory()

PlayerInventory

public PlayerInventory(RemoteInventory client,
                       Player p)
Method Detail

setOwner

public void setOwner(Player p)
Sets the player for this inventory.


setRemoteInventory

public void setRemoteInventory(RemoteInventory inv)
Sets a new RemoteInventory to talk to, e.g. after a reconnect from net-death.

Parameters:
inv - the new RemoteInventory to talk to

add

public GameObject add(GameObject obj)
               throws Bag.FullBagException
Description copied from class: MonsterInventory
Adds an item to the bag (at the end). Handles groupable items.

Specified by:
add in interface Bag
Overrides:
add in class MonsterInventory
Parameters:
obj - a GameObject to add
Returns:
the added item, or group if it was added to a group
Throws:
Bag.FullBagException

remove

public boolean remove(GameObject target)
Description copied from class: MonsterInventory
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 MonsterInventory
Parameters:
target - the item to remove
Returns:
true if the item was removed

removeFirst

public GameObject removeFirst(Predicate p)
Description copied from class: MonsterInventory
Removes the first instance of an object satisfying a Predicate.

Specified by:
removeFirst in interface Bag
Overrides:
removeFirst in class MonsterInventory
Parameters:
p - a Predicate that returns true if the object is "the one"
See Also:
Predicate

removeAll

public java.util.List removeAll()
Description copied from class: MonsterInventory
Removes and returns all the items from the bag.

Specified by:
removeAll in interface Bag
Overrides:
removeAll in class MonsterInventory
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
Description copied from class: MonsterInventory
Replaces the object at the specified index with a new object.

Specified by:
setObjectAt in interface Bag
Overrides:
setObjectAt in class MonsterInventory
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

hasRoomFor

public boolean hasRoomFor(GameObject obj)
Description copied from interface: Bag
Returns true if the specified object could be added to the bag's current contents without exceeding the bag's weight capacity.

Specified by:
hasRoomFor in interface Bag
Overrides:
hasRoomFor in class BasicBag

canHoldMore

public boolean canHoldMore()
Description copied from interface: Bag
Returns true if we're not at our max count for this bag. Some bags have a maximum number of items allowed, even if they can hold more weight.

Specified by:
canHoldMore in interface Bag
Overrides:
canHoldMore in class BasicBag
Returns:
true if we're below our max count yet.

getMaxCount

public int getMaxCount()
Description copied from interface: Bag
Returns the maximum number of items that can be stored in this bag.

Specified by:
getMaxCount in interface Bag
Overrides:
getMaxCount in class BasicBag
Returns:
the max count (Integer.MAX_VALUE, usually).

resend

public void resend(int index)
Description copied from class: MonsterInventory
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
Overrides:
resend in class MonsterInventory
Parameters:
index - the index of the item to resend.

resendAll

public void resendAll()
Description copied from class: MonsterInventory
Re-sends all the inventory.

Specified by:
resendAll in interface Inventory
Overrides:
resendAll in class MonsterInventory

invalidate

public void invalidate(GameObject obj)
Description copied from interface: Bag
Visually invalidates the specified object in the container.

Specified by:
invalidate in interface Bag
Overrides:
invalidate in class BasicBag
Parameters:
obj - the object to invalidate

toString

public java.lang.String toString()
Description copied from class: MonsterInventory
Returns a String representation of the inventory. Used mostly for examining the inventory from a debugger.

Overrides:
toString in class MonsterInventory

notifyDropped

protected void notifyDropped(GameObject obj)
Notifies Readyable objects that they've been unreadied.

Overrides:
notifyDropped in class MonsterInventory
Parameters:
obj - the object to drop

updateGold

protected void updateGold()
Updates the gold-display on the client when coins enter or leave the inventory. The gold-display is the only "stat" shown in the client that's dependent on the contents of the player's inventory, which is why "updateGold" calls are present in all the add/remove/update methods of this class.


computeEncumbrance

public void computeEncumbrance()
Description copied from class: MonsterInventory
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
Overrides:
computeEncumbrance in class MonsterInventory

writeData

public java.util.List writeData()
                         throws java.lang.Exception
Description copied from interface: SelfExternalizable
Tells the object to write its properties out to a text file.

Specified by:
writeData in interface SelfExternalizable
Overrides:
writeData in class MonsterInventory
Returns:
a String representation that can be written to the text file.
Throws:
java.lang.Exception

checkWeight

protected void checkWeight(GameObject item)
                    throws Bag.FullBagException
Wiz inventories have no weight restrictions.

Overrides:
checkWeight in class BasicBag
Parameters:
item - the object to check
Throws:
Bag.FullBagException

getCapacity

public long getCapacity()
Description copied from class: MonsterInventory
Returns the carrying capacity of this inventory.

Specified by:
getCapacity in interface Bag
Overrides:
getCapacity in class MonsterInventory
Returns:
the carrying capacity in grams

createClone

public java.lang.Object createClone()

insert

public void insert(GameObject obj,
                   int index)
            throws Bag.FullBagException
Description copied from class: MonsterInventory
Inserts an item into the bag at the specified index.

Specified by:
insert in interface Bag
Overrides:
insert in class MonsterInventory
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

adjust

public void adjust(GameObject obj,
                   int index)
Description copied from interface: Bag
Adjusts the position of an item in the list without removing it and adding it (thereby skipping the encumbrance and other checks).

Specified by:
adjust in interface Bag
Overrides:
adjust in class BasicBag
Parameters:
index - the index to move it to. 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.
obj - the item to insert

getCommands

public java.lang.String getCommands(GameObject obj)
Returns a string containing the commands valid for this object, for displaying in a popup menu on the client when click on the object in inventory.


readData

public void readData(org.w3c.dom.Node bean)
              throws java.lang.Exception
Description copied from interface: SelfExternalizable
Tells the object to parse its externalized representation from a list of lines.

Specified by:
readData in interface SelfExternalizable
Overrides:
readData in class BasicBag
Parameters:
bean - the DOM Node representing the bean
Throws:
java.lang.Exception