wyvern.lib.classes
Class BasicBag
java.lang.Object
wyvern.kernel.properties.PList
wyvern.kernel.maps.MapObject
wyvern.lib.classes.BasicBag
- All Implemented Interfaces:
- Applyable, Bag, Broadcaster, Container, GameObject, MethodHookable, PropertyList, SelfExternalizable
- Direct Known Subclasses:
- Chest, CoinPurse, Corpse, HiddenObject, MonsterInventory, PurseOfHolding, Quiver, RockPouch, Scabbard, StaticBag, TrenchcoatPocket
- public class BasicBag
- extends MapObject
- implements Bag, SelfExternalizable, Applyable
This is a customizable implementation of the Bag interface; most
standard game containers (chests, packs, sacks, jars, etc.) will
derive from this class.
- Version:
- 1.0, Jun 12, 1998
- Author:
- Steve Yegge
Method Summary |
GameObject |
add(GameObject item)
Adds an item to the bag (at the end). |
protected GameObject |
addGroupable(GameObject item)
Adds a groupable item to the bag. |
void |
adjust(GameObject item,
int index)
Adjusts the position of an item in the list without removing it
and adding it (thereby skipping the encumbrance and other checks). |
void |
apply(Commandable agent)
Someone's trying to get stuff from the chest. |
boolean |
canHoldMore()
Returns true if we're not at our max count for this bag.
|
protected void |
checkFilter(GameObject item)
Make sure it's a valid item for this container |
protected void |
checkWeight(GameObject item)
Checks if the object, when added to the container, would
cause the bag's weight capacity to be exceeded. |
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 the first object matching the passed Predicate. |
GameObject |
findByName(java.lang.String name)
Returns the first object that matches the passed name.
|
long |
getCapacity()
Returns the capacity of this bag. |
protected java.lang.String |
getEmptyTitle()
Returns the description for when the bag is empty. |
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. |
int |
getPosition(GameObject item)
Returns the position of the specified item in the list. |
long |
getRemainingCapacity()
Returns how much more weight we can hold, in grams. |
protected java.lang.String |
getTitle()
Returns the first line of the description, such as "The bag
contains:". |
long |
getWeight()
Returns the weight of the bag, in grams. |
boolean |
hasRoomFor(GameObject obj)
Returns true if the object could be placed in the bag. |
boolean |
hasRoomFor(long weight)
Returns true if the weight could be added to the bag |
int |
indexOf(GameObject item)
Returns the index of the specified object in the bag. |
protected void |
initContents()
Makes sure we have a "contents" ItemList. |
protected void |
initFilter()
Checks for a "prop-filter", "arch-filter", or "class-filter" property
on the bag. |
void |
initialize()
Initializes the object's default properties. |
void |
insert(GameObject item,
int index)
Inserts an item into the bag at the specified index. |
void |
invalidate(GameObject obj)
Visually invalidates an object inside the bag. |
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. |
void |
readData(org.w3c.dom.Node bean)
Tells the object to parse its externalized representation from
a list of lines. |
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. |
java.util.List |
removeAll(Predicate p)
Removes all items matching the specified Predicate
and returns them as a list. |
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 |
setCapacity(long capacity)
Sets the carrying capacity for the bag, in grams. |
void |
setCapacity(java.lang.String weight)
Sets the capacity of the bag. |
void |
setCapacity(Weight w)
Sets the capacity of the bag. |
protected void |
setContainer(GameObject obj)
Sets this bag as the container for the passed object.
|
GameObject |
setObjectAt(int index,
GameObject item)
Replaces the object at the specified index with a new object. |
protected void |
setUplinks(java.util.List contents)
Goes through the contents-list handed to us by the map loader
and sets the container link for each of them. |
boolean |
shouldWrite()
Returns true if we should write the object at all. |
int |
size()
Returns the number of objects in the bag. |
protected void |
updateDescription()
Makes the long-description property show all the items. |
void |
visitObjects(Visitor v)
Visits the objects in the bag with the passed Visitor. |
java.util.List |
writeData()
Tells the object to write its properties out to a text file. |
void |
writeItemList(java.util.List items,
java.util.List lines)
Writes out the contents of the bag. |
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, 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, 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, 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 |
BasicBag
public BasicBag()
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
initFilter
protected void initFilter()
- Checks for a "prop-filter", "arch-filter", or "class-filter" property
on the bag. If it finds a "prop-filter", it expects the value to
be a string that's a property to look for on the item, and
it constructs a PropertyPredicate that's used in filter().
If it finds a "class-filter", it expects a fully-qualified
java classname (e.g. "wyvern.wiz.foo.bar.MyThing"). If it finds
an "arch-filter" property, it checks for a string archetype path,
e.g. "weapons/arrow".
initContents
protected void initContents()
- Makes sure we have a "contents" ItemList. Subclasses can
provide their own item-container class.
setUplinks
protected void setUplinks(java.util.List contents)
- Goes through the contents-list handed to us by the map loader
and sets the container link for each of them.
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
- 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:
Bag.FullBagException
- bag doesn't have space for the item
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 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
- 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.item
- the item to insert
getPosition
public int getPosition(GameObject item)
- Returns the position of the specified item in the list.
- 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
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
- Returns:
- true if the item was removed, false if not found
removeFirst
public GameObject removeFirst()
- Removes and returns the first object in the bag.
- Specified by:
removeFirst
in interface Bag
- 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
- 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
- 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 as 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.
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
hasRoomFor
public boolean hasRoomFor(GameObject obj)
- Returns true if the object could be placed in the bag.
- 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 weight could be added to the bag
- 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).
find
public GameObject find(Predicate p)
- Returns the first object matching the passed Predicate.
- 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
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
isEmpty
public boolean isEmpty()
- Returns true if the bag contains no items.
- Specified by:
isEmpty
in interface Bag
- Returns:
- whether the bag is empty
iterator
public java.util.Iterator iterator()
- Returns an Iterator over the items in the bag. You *must*
use a "synchronized (getItems())" statement around the item list
returned by this method, just in case the item list is being
shared (e.g. purse of holding).
WARNING: if you remove the object from the bag by calling the
remove() method of this iterator, you must call
obj.setContainer(null/None) or it will still think it's
in the bag. (Realistically we probably shouldn't allow this
iterator method at all for this reason.)
- 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
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 bag with the passed Visitor.
- Specified by:
visitObjects
in interface Bag
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 replacement object. If null, the item to
replace is actually removed.
- Returns:
- the replaced object, or null if none was replaced
- Throws:
Bag.FullBagException
getCapacity
public long getCapacity()
- Returns the capacity of this bag. Capacity is stored in
the "capacity" property as a Weight object.
- Specified by:
getCapacity
in interface Bag
- Returns:
- the capacity (in grams)
getRemainingCapacity
public long getRemainingCapacity()
- Returns how much more weight we can hold, in grams.
- 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
setCapacity
public void setCapacity(long capacity)
- Sets the carrying capacity for the bag, in grams.
- Specified by:
setCapacity
in interface Bag
- Parameters:
capacity
- the new weight capacity in grams
setCapacity
public void setCapacity(Weight w)
- Sets the capacity of the bag.
- Specified by:
setCapacity
in interface Bag
- Parameters:
w
- the new weight it can carry
setCapacity
public void setCapacity(java.lang.String weight)
- Sets the capacity of the bag.
- Parameters:
weight
- a weight specifier such as "100lb"
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 MapObject
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
invalidate
public void invalidate(GameObject obj)
- Visually invalidates an object inside the bag.
- Specified by:
invalidate
in interface Bag
- Parameters:
obj
- the object to invalidate
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
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
The default implementation uses a PropertyPredicate, ArchetypePredicate,
or ClassPredicate, if it found a "prop-filter", "arch-filter", or
"class-filter" String property on the bag in initialize(), respectively.
updateDescription
protected void updateDescription()
- Makes the long-description property show all the items.
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
getTitle
protected java.lang.String getTitle()
- Returns the first line of the description, such as "The bag
contains:". Looks for a property called "desc-title", and
if it doesn't find it, uses the short description.
getEmptyTitle
protected java.lang.String getEmptyTitle()
- Returns the description for when the bag is empty. Looks
for the property "empty-title", and failing that, uses the
short description: "The is empty.";
checkWeight
protected void checkWeight(GameObject item)
throws Bag.FullBagException
- Checks if the object, when added to the container, would
cause the bag's weight capacity to be exceeded.
- Parameters:
item
- the object to check
- Throws:
FullBagException
- if the object is too heavy to add
Bag.FullBagException
addGroupable
protected GameObject addGroupable(GameObject item)
throws Bag.FullBagException
- Adds a groupable item to the bag. Checks to see if another
item of that type is in the bag, and if so, groups them. If not,
it simply adds the item to the bag.
- Parameters:
item
- the groupable item. Someone must have already
ascertained that the item has the "groupable" property, since
we don't check here.
- Returns:
- the item, or group if it was added to a group
- Throws:
Bag.FullBagException
getItems
protected java.util.List getItems()
- Returns the actual list in which the items are contained.
setContainer
protected void setContainer(GameObject obj)
- Sets this bag as the container for the passed object.
Runs a method-hook for the object, in case anyone wants
to know when the object is placed in a container. The
corresponding method-hook for removing it is currently
run by MapCell.class.
- Parameters:
obj
- the object to set/notify
checkFilter
protected void checkFilter(GameObject item)
- Make sure it's a valid item for this container
- Throws:
InvalidItemException
readData
public void readData(org.w3c.dom.Node bean)
throws java.lang.Exception
- Tells the object to parse its externalized representation from
a list of lines.
- Specified by:
readData
in interface SelfExternalizable
- Parameters:
bean
- the DOM Node representing the bean
- Throws:
java.lang.Exception
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
- Returns:
- a String representation that can be written to the
text file.
- Throws:
java.lang.Exception
writeItemList
public void writeItemList(java.util.List items,
java.util.List lines)
throws java.lang.Exception
- Writes out the contents of the bag. Called by writeData()
and by subclasses.
- Parameters:
items
- our ItemList, from getProperty("contents")lines
- the list to add the lines to
- Throws:
java.lang.Exception
shouldWrite
public boolean shouldWrite()
- Returns true if we should write the object at all.
- Specified by:
shouldWrite
in interface SelfExternalizable
- Returns:
- true - it's OK to have an empty bag
apply
public void apply(Commandable agent)
- Someone's trying to get stuff from the chest.
- Specified by:
apply
in interface Applyable
- Parameters:
agent
- the person applying the object
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