wyvern.lib.magic.armor
Class Trenchcoat

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.armor.ArmorImpl
              extended bywyvern.lib.classes.armor.Cloak
                  extended bywyvern.lib.magic.armor.Trenchcoat
All Implemented Interfaces:
Armor, Bag, Broadcaster, Container, Damageable, GameObject, MethodHookable, PickupInterest, PropertyList

public class Trenchcoat
extends Cloak
implements Bag

A cloak that can hold things in internal pockets, reducing their weight. You have to admit, this class would have been a piece of cake if Java supported multiple inheritance, or even delegation. C'mon, admit it.

Version:
1.0, Dec 12, 1999
Author:
Steve Yegge

Nested Class Summary
 
Nested classes inherited from class wyvern.lib.Bag
Bag.FullBagException, Bag.InvalidItemException
 
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.Bag
BAG_CUT_PERCENT_CAP, BAG_DEFAULT_CAPACITY
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
Trenchcoat()
           
 
Method Summary
 GameObject add(GameObject item)
          Adds an item to the bag (at the end).
 void adjust(GameObject item, int index)
          Adjusts an item in the bag to the specified index.
 boolean canHoldMore()
          Returns true if we're not at our max count for this bag.
 boolean contains(GameObject item)
          Returns true if the container contains the passed item.
 boolean filter(GameObject item)
          Returns true if the container can hold this type of item.
 GameObject find(Predicate p)
          Returns an object satisfying the specified Predicate, without actually removing the object.
 GameObject findByName(java.lang.String name)
          Returns the first object that matches the passed name.
 long getCapacity()
          Returns the carrying capacity of the bag.
protected  java.util.List getItems()
          Returns the actual list in which the items are contained.
 long getItemWeight()
          Returns the (unadjusted) weight of the items in this bag.
 int getMaxCount()
          Returns the maximum number of items that can be stored in this bag.
 TrenchcoatPocket getPocket()
          Gets or creates the pocket container.
 int getPosition(GameObject item)
          Returns position of item in bag.
 long getRemainingCapacity()
          Returns how much more can be put in the bag.
 long getWeight()
          Returns the weight of the bag, in grams.
 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.
 boolean hasRoomFor(long weight)
          Returns true if the specified weight could be added to the bag's current contents without exceeding the bag's weight capacity.
 int indexOf(GameObject item)
          Returns the index of the specified object in the bag.
 void initialize()
          MapObject initialization.
 void insert(GameObject item, int index)
          Inserts an item into the bag at the specified index.
 void invalidate(GameObject item)
          Visually invalidates the specified object in the container.
 boolean isBag()
          Returns true if this container is a Bag (or Inventory, or other implementation of the Bag interface).
 boolean isEmpty()
          Returns true if the bag contains no items.
 boolean isInventory()
          Returns true if this container is an Inventory
 boolean isMap()
          Returns true if this container is a GameMap.
 java.util.Iterator iterator()
          Returns an Iterator over the items in the bag.
 GameObject objectAt(int index)
          Returns the object at the specified index, or null if the index is out-of-bounds.
 java.lang.String printItemList()
          Prints a list of the items in the container, without any heading.
 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 all items and returns them as a list.
 java.util.List removeAll(Predicate p)
          Removes all items matching the specified Predicate and returns them in a List.
 GameObject removeFirst()
          Removes and returns the first object from the inventory.
 GameObject removeFirst(Predicate p)
          Removes the first instance of an object satisfying a Predicate.
 void setCapacity(long capacity)
          Sets the max carrying-capacity of the bag.
 void setCapacity(Weight w)
          Sets the max carrying-capacity of the bag.
 GameObject setObjectAt(int index, GameObject item)
          Replaces the object at the specified index with a new object.
 int size()
          Returns the number of objects in the bag.
 void updateDescription(java.lang.String desc)
          Copies the internal bag description, so we can see what's inside the cloak.
 void visitObjects(Visitor v)
          Visits the objects in the inventory with the passed Visitor.
 
Methods inherited from class wyvern.lib.classes.armor.Cloak
getRequiredSlots
 
Methods inherited from class wyvern.lib.classes.armor.ArmorImpl
adjustHP, applyBonus, applyBonuses, applySpecial, canWear, checkDrop, destroy, dropped, forceRemoval, getAC, getDescription, getHP, getMaxHP, getValue, isWorn, kill, pickedUp, setWorn, toString
 
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, 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, 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, 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

Trenchcoat

public Trenchcoat()
Method Detail

initialize

public void initialize()
MapObject initialization.

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

add

public GameObject add(GameObject item)
               throws Bag.FullBagException
Adds an item to the bag (at the end).

Specified by:
add in interface Bag
Parameters:
item - a GameObject to add
Returns:
the object that was added, or, if the item was added to a group, returns the group.
Throws:
FullBagException - bag doesn't have space for the item
Bag.FullBagException

contains

public boolean contains(GameObject item)
Returns true if the container contains the passed item.

Specified by:
contains in interface Bag
Returns:
true if the item is in the container

filter

public boolean filter(GameObject item)
Returns true if the container can hold this type of item.

Specified by:
filter in interface Bag
Returns:
true if the item can be placed in the container Default implementation always returns true, but subclasses like reagent pouches, wallets or quivers can implement their own rules.

find

public GameObject find(Predicate p)
Returns an object satisfying the specified Predicate, without actually removing the object.

Specified by:
find in interface Bag
Parameters:
p - a Predicate returning true or false for a given object
Returns:
the first object that satisfies the predicate
See Also:
Predicate

getCapacity

public long getCapacity()
Returns the carrying capacity of the bag.

Specified by:
getCapacity in interface Bag
Returns:
the capacity (in grams)

getRemainingCapacity

public long getRemainingCapacity()
Returns how much more can be put in the bag.

Specified by:
getRemainingCapacity in interface Bag
Returns:
the total capacity of the bag, minus the total weight of the items in the bag so far

hasRoomFor

public 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.

Specified by:
hasRoomFor in interface Bag
Parameters:
obj - the object to check
Returns:
true if the bag has sufficient capacity to hold obj

hasRoomFor

public boolean hasRoomFor(long weight)
Returns true if the specified weight could be added to the bag's current contents without exceeding the bag's weight capacity.

Specified by:
hasRoomFor in interface Bag

canHoldMore

public boolean canHoldMore()
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
Returns:
true if we're below our max count yet.

getMaxCount

public int getMaxCount()
Returns the maximum number of items that can be stored in this bag.

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

indexOf

public int indexOf(GameObject item)
Returns the index of the specified object in the bag.

Specified by:
indexOf in interface Bag
Parameters:
item - the object to look for
Returns:
the index (zero-based), or -1 if not found

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
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.
item - the item to insert
Throws:
Bag.FullBagException

adjust

public void adjust(GameObject item,
                   int index)
Adjusts an item in the bag to the specified index.

Specified by:
adjust in interface Bag
Parameters:
index - the index to adjust 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.
item - the item to adjust

isEmpty

public boolean isEmpty()
Returns true if the bag contains no items.

Specified by:
isEmpty in interface Bag
Returns:
true if the container is empty

invalidate

public void invalidate(GameObject item)
Visually invalidates the specified object in the container.

Specified by:
invalidate in interface Bag
Parameters:
item - the item whose appearance has changed in some way

iterator

public java.util.Iterator iterator()
Returns an Iterator over the items in the bag.

Warning: You *MUST* place iteration in a "synchronized (list)" block during the iteration, as others may also be going through the item list.

Specified by:
iterator in interface Bag
Returns:
an iterator that can be cast as a ListIterator

objectAt

public GameObject objectAt(int index)
Returns the object at the specified index, or null if the index is out-of-bounds.

Specified by:
objectAt in interface Bag
Parameters:
index - the index to retrieve
Returns:
the object at that index, or null if not found

remove

public GameObject remove(int index)
Removes and returns the object at the specified index.

Specified by:
remove in interface Bag
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
Parameters:
item - the item to remove, or null if not found
Returns:
true if the item was removed, false if not found

removeAll

public java.util.List removeAll()
Removes all items and returns them as a list.

Specified by:
removeAll in interface Bag
Returns:
a List containing all the GameObjects from the bag; the bag will be empty after this call.

removeAll

public java.util.List removeAll(Predicate p)
Removes all items matching the specified Predicate and returns them in a List.

Specified by:
removeAll in interface Bag
Returns:
a List containing all the GameObjects that were removed from the bag. Any object in the bag that passes the passed predicate() function will be removed. An empty list is returned if no objects in the bag matched the predicate.

removeFirst

public GameObject removeFirst()
Removes and returns the first object from the inventory.

Specified by:
removeFirst in interface Bag
Returns:
the first object in the inventory (object is removed)
Throws:
java.lang.IndexOutOfBoundsException - if the list is empty

removeFirst

public GameObject removeFirst(Predicate p)
Removes the first instance of an object satisfying a Predicate.

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

setCapacity

public void setCapacity(long capacity)
Sets the max carrying-capacity of the bag.

Specified by:
setCapacity in interface Bag
Parameters:
capacity - the new capacity, stored in "capacity" property as a Weight object.

setCapacity

public void setCapacity(Weight w)
Sets the max carrying-capacity of the bag.

Specified by:
setCapacity in interface Bag
Parameters:
w - the weight to use as the new capacity

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
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

size

public int size()
Returns the number of objects in the bag.

Specified by:
size in interface Bag
Returns:
the number of distinct objects in the bag. Collection- type objects such as arrows or coins are counted as single objects.

visitObjects

public void visitObjects(Visitor v)
Visits the objects in the inventory with the passed Visitor.

Specified by:
visitObjects in interface Bag

findByName

public GameObject findByName(java.lang.String name)
Returns the first object that matches the passed name. Searches with a standard wyvern.lib.predicates.NameMatchPredicate.

Specified by:
findByName in interface Bag
Parameters:
name - the name substring to match
Returns:
the first object in the inventory matching the name, or null

updateDescription

public void updateDescription(java.lang.String desc)
Copies the internal bag description, so we can see what's inside the cloak.


printItemList

public java.lang.String printItemList()
Prints a list of the items in the container, without any heading.

Specified by:
printItemList in interface Bag
Returns:
a list of the items in the bag

getWeight

public long getWeight()
Returns the weight of the bag, in grams. This is equal to the weight of the bag plus some percentage of the weight of the objects in the bag. For non-magical bags, the percentage is 100; i.e. normal bags don't reduce the weight of the items they're holding. For magical bags, it can be from 0 to 100 (or higher, for cursed bags that increase the item weight).

The reduction percentage is actually stored as an integer property with a default of zero (making the property optional). A value of zero means the weight isn't reduced at all. A positive number is treated as a percentage reduction (with a ceiling of 100). 100 means the items weigh nothing while in the bag. A negative value is treated as a percentage multiplier to add to the weight of the items; for example, a value of -50 tells the bag to add 50% to the weight of the items.

The reduction-percentage int property is "cut-%".

Specified by:
getWeight in interface GameObject
Overrides:
getWeight in class ArmorImpl

getItemWeight

public long getItemWeight()
Returns the (unadjusted) weight of the items in this bag.

Specified by:
getItemWeight in interface Bag
Returns:
the weight of the items in the bag, not including the weight of the bag itself

getItems

protected java.util.List getItems()
Returns the actual list in which the items are contained.


getPosition

public int getPosition(GameObject item)
Returns position of item in bag.

Specified by:
getPosition in interface Bag
Parameters:
item - the item to look for
Returns:
the item's 0-indexed list position, or -1 if not found

getPocket

public TrenchcoatPocket getPocket()
Gets or creates the pocket container.


isMap

public boolean isMap()
Returns true if this container is a GameMap.

Specified by:
isMap in interface Container
Returns:
false

isBag

public boolean isBag()
Returns true if this container is a Bag (or Inventory, or other implementation of the Bag interface).

Specified by:
isBag in interface Container
Returns:
true

isInventory

public boolean isInventory()
Returns true if this container is an Inventory

Specified by:
isInventory in interface Container
Returns:
false