|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Main container interface in the game, for bags, quivers, scabbards, reagent pouches, backpacks, chests, and so on.
The generic bag type can hold any sort of object, but has a maximum size object that it can contain.
Bags' contents are stored in a sequential list; i.e. each item in the bag has an index, to facilitate removing otherwise identical items.
If you don't want people to take stuff from the bag, set a "no-get-from" property on it whose value is a message to print, such as "You cannot take things from this bag." A supported variation on this is "no-get-from-inv", which prevents the user from taking things from the container while it's in the user's inventory.
Nested Class Summary | |
static class |
Bag.FullBagException
This exception is thrown when someone tries to put something in a bag that can't hold any more items. |
static class |
Bag.InvalidItemException
Thrown when someone tries to put an item in the bag that isn't appropriate for this bag, as defined by the bag's filter() method. |
Field Summary | |
static int |
BAG_CUT_PERCENT_CAP
Bags aren't allowed to reduce weight more than this. |
static long |
BAG_DEFAULT_CAPACITY
If a bag is missing its "capacity" property, it makes more sense to have it hold a default value rather than nothing at all. |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Method Summary | |
GameObject |
add(GameObject item)
Adds an item to the bag (at the end). |
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). |
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. |
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. |
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 |
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 |
isEmpty()
Returns true if the bag contains no items. |
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 as 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 |
visitObjects(Visitor v)
Visits the objects in the inventory with the passed Visitor. |
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, isInventory, isMap |
Field Detail |
public static final int BAG_CUT_PERCENT_CAP
public static final long BAG_DEFAULT_CAPACITY
Method Detail |
public GameObject add(GameObject item) throws Bag.FullBagException
item
- a GameObject to add
Bag.FullBagException
- bag doesn't have space for the itempublic boolean contains(GameObject item)
public boolean filter(GameObject item)
public GameObject find(Predicate p)
p
- a Predicate returning true or false for a given object
Predicate
public long getCapacity()
public long getRemainingCapacity()
public boolean hasRoomFor(GameObject obj)
obj
- the object to check
public boolean canHoldMore()
public int getMaxCount()
public boolean hasRoomFor(long weight)
public int indexOf(GameObject item)
item
- the object to look for
public void insert(GameObject item, int index) throws Bag.FullBagException
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
Bag.FullBagException
public void adjust(GameObject item, int index)
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 insertpublic boolean isEmpty()
public void invalidate(GameObject item)
item
- the item whose appearance has changed in some waypublic java.lang.String printItemList()
public java.util.Iterator iterator()
Warning: You *MUST* place iteration in a "synchronized (bag)" block during the iteration, as others may also be going through the bag's contents.
public GameObject objectAt(int index)
index
- the index to retrieve
public GameObject remove(int index)
index
- the 0-based index of the element to remove.
java.lang.IndexOutOfBoundsException
- if the index is out of boundspublic boolean remove(GameObject item)
item
- the item to remove, or null if not found
public java.util.List removeAll()
public java.util.List removeAll(Predicate p)
public GameObject removeFirst()
java.lang.IndexOutOfBoundsException
- if the list is emptypublic GameObject removeFirst(Predicate p)
p
- a Predicate that returns true if the object is "the one"Predicate
public void setCapacity(long capacity)
capacity
- the new capacity, stored in "capacity" property
as a Weight object.public void setCapacity(Weight w)
w
- the weight to use as the new capacitypublic GameObject setObjectAt(int index, GameObject item) throws Bag.FullBagException
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
Bag.FullBagException
public int size()
public void visitObjects(Visitor v)
public GameObject findByName(java.lang.String name)
name
- the name substring to match
public int getPosition(GameObject item)
item
- the item to look for
public long getItemWeight()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |