org.starhope.appius.user
Class InventoryItem

java.lang.Object
  extended by org.starhope.appius.util.ManagedReferenceHolder
      extended by org.starhope.appius.sql.SQLPeerDatum
          extended by org.starhope.appius.user.InventoryItem
Direct Known Subclasses:
ClothingItem, GameEquipItem, HomeDecorItem, MusicItem

public abstract class InventoryItem
extends SQLPeerDatum

The InventoryItem is an abstract superclass for all items which can be placed into the user's inventory. It also has interface elements for the common behaviour of “equipping” the item in some way, giving and receiving items (including purchasing them and trading with other players), and so forth. Subclasses are ClothingItem, HomeDecorItem, MusicItem , GameEquipItem

Author:
brpocock

Field Summary
protected  boolean active
           
protected  int id
           
protected  int ownerID
          user owning this item
protected  int slotNumber
          The slot/series in which this occurs in the player's inventory
static int Type_Backpacks
           
static int Type_Ceiling
           
static int Type_Ceiling_Furniture
           
static int Type_Dresses
           
static int Type_Ears
           
static int Type_Eyes
           
static int Type_Floor_Furniture
           
static int Type_Flooring
           
static int Type_Music
           
static int Type_Neck
           
static int Type_Orbitz
           
static int Type_Pants
           
static int Type_Pattern
           
static int Type_Pivitz
           
static int Type_Shirts
           
static int Type_Tops
           
static int Type_Wall_Furniture
           
static int Type_Wallpaper
           
protected  int typeID
           
 
Constructor Summary
InventoryItem()
           
 
Method Summary
 ClothingItem asClothing()
           
 HomeDecorItem asHomeDecorItem()
           
protected abstract  void assertValidTypeID(long testTypeID)
          This is for subclasses to validate the type ID of their members.
 void flush()
          This is an overriding method.
static InventoryItem getByID(int idByWhichToGet)
          Get an inventory item based upon the database ID
static InventoryItem getByID(int id, boolean isActive, int slotNum)
          WRITEME: document this method (brpocock, Aug 28, 2009)
 String getCacheUniqueID()
           
 Class<? extends InventoryItem> getClassForThisType()
           
static Class<? extends InventoryItem> getClassForType(int theTypeID)
          Find the class to which a type of item belongs.
 int getID()
           
 Class<? extends InventoryItem> getItemClass()
           
 String getMountPoint()
           
 User getOwner()
           
 int getOwnerID()
           
 int getSlotNumber()
           
 int getTypeID()
           
static int[] getTypesOfClothing()
           
static int[] getTypesOfFurniture()
           
static int[] getTypesOfStructure()
           
static int[] getTypesOfWearables()
           
 boolean identifiesAs(String typeString)
           
 boolean isActive()
          WRITEME: document this method (brpocock, Aug 28, 2009)
 boolean isClothingOnly()
           
 boolean isFurniture()
           
 boolean isMusic()
           
 boolean isPattern()
           
 boolean isPivitz()
           
 boolean isStructure()
           
 boolean isWearable()
           
 void setActive(boolean beActive)
           
 void setOwner(User user)
           
 void setOwnerID(int ownerID)
           
 void setSlotNumber(int slot)
           
 void setTypeID(int typeID)
           
 org.json.JSONObject toJSON()
           
 String toString()
           
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, get, prepare, prepare, saveInCache, set, set
 
Methods inherited from class org.starhope.appius.util.ManagedReferenceHolder
deref, setRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Type_Backpacks

public static final int Type_Backpacks
See Also:
Constant Field Values

Type_Ceiling

public static final int Type_Ceiling
See Also:
Constant Field Values

Type_Ceiling_Furniture

public static final int Type_Ceiling_Furniture
See Also:
Constant Field Values

Type_Dresses

public static final int Type_Dresses
See Also:
Constant Field Values

Type_Ears

public static final int Type_Ears
See Also:
Constant Field Values

Type_Eyes

public static final int Type_Eyes
See Also:
Constant Field Values

Type_Floor_Furniture

public static final int Type_Floor_Furniture
See Also:
Constant Field Values

Type_Flooring

public static final int Type_Flooring
See Also:
Constant Field Values

Type_Music

public static final int Type_Music
See Also:
Constant Field Values

Type_Neck

public static final int Type_Neck
See Also:
Constant Field Values

Type_Orbitz

public static final int Type_Orbitz
See Also:
Constant Field Values

Type_Pants

public static final int Type_Pants
See Also:
Constant Field Values

Type_Pattern

public static final int Type_Pattern
See Also:
Constant Field Values

Type_Pivitz

public static final int Type_Pivitz
See Also:
Constant Field Values

Type_Shirts

public static final int Type_Shirts
See Also:
Constant Field Values

Type_Tops

public static final int Type_Tops
See Also:
Constant Field Values

Type_Wall_Furniture

public static final int Type_Wall_Furniture
See Also:
Constant Field Values

Type_Wallpaper

public static final int Type_Wallpaper
See Also:
Constant Field Values

active

protected boolean active

id

protected int id

ownerID

protected int ownerID
user owning this item


slotNumber

protected int slotNumber
The slot/series in which this occurs in the player's inventory


typeID

protected int typeID
Constructor Detail

InventoryItem

public InventoryItem()
Method Detail

getByID

public static InventoryItem getByID(int idByWhichToGet)
Get an inventory item based upon the database ID

Parameters:
idByWhichToGet - the database ID of an inventory item of any kind
Returns:
the item in a class extending this one

getByID

public static InventoryItem getByID(int id,
                                    boolean isActive,
                                    int slotNum)
WRITEME: document this method (brpocock, Aug 28, 2009)

Parameters:
id -
isActive -
slotNum -
Returns:

getClassForType

public static Class<? extends InventoryItem> getClassForType(int theTypeID)
Find the class to which a type of item belongs.

Parameters:
theTypeID - The ID number for a type of item
Returns:
a Class which can fully instantiate items of that type, with any special properties, which extends InventoryItem

getTypesOfClothing

public static int[] getTypesOfClothing()
Returns:
an array of items that can be worn as clothing, excluding Patterns and Pivitz

getTypesOfFurniture

public static int[] getTypesOfFurniture()
Returns:
an array of furniture items that can be placed in the house

getTypesOfStructure

public static int[] getTypesOfStructure()
Returns:
an array of structure items of a room

getTypesOfWearables

public static int[] getTypesOfWearables()
Returns:
an array of all items that can be worn, including Pivitz and patterns

asClothing

public ClothingItem asClothing()
Returns:
the item as a ClothingItem

asHomeDecorItem

public HomeDecorItem asHomeDecorItem()
Returns:
the item as a HomeDecorItem

assertValidTypeID

protected abstract void assertValidTypeID(long testTypeID)
                                   throws GameLogicException
This is for subclasses to validate the type ID of their members. If the specific class being instantiated can't handle the type of item, it should throw an exception.

Parameters:
testTypeID - The type ID to be checked
Throws:
GameLogicException - if the type ID is not of the types supported by this class

flush

public void flush()
This is an overriding method.

Specified by:
flush in class SQLPeerDatum
See Also:
SQLPeerDatum.flush()

getCacheUniqueID

public String getCacheUniqueID()
Specified by:
getCacheUniqueID in class SQLPeerDatum
Returns:
The local (Stringified) version of an unique ID; usually the database ID column
See Also:
SQLPeerDatum.getCacheUniqueID()

getClassForThisType

public Class<? extends InventoryItem> getClassForThisType()
Returns:
the subclass that can best represent this item

getID

public int getID()
Returns:
the item's ID

getItemClass

public Class<? extends InventoryItem> getItemClass()
Returns:
the class which best (most specifically) represents the given item type

getMountPoint

public String getMountPoint()
Returns:
the mount point of the clothing item, or the encoded string describing the location of a furniture item

getOwner

public User getOwner()
Returns:
owner

getOwnerID

public int getOwnerID()
Returns:
owner's userID

getSlotNumber

public int getSlotNumber()
Returns:
slotNumber

getTypeID

public int getTypeID()
Returns:
the type ID

identifiesAs

public boolean identifiesAs(String typeString)
Parameters:
typeString - the type of item from the following list of strings: "clothes" "patterns" "pivitz" "furniture" "structure" "music"
Returns:
true if the item is of the specified type

isActive

public boolean isActive()
WRITEME: document this method (brpocock, Aug 28, 2009)

Returns:
true, if the item is active/in use

isClothingOnly

public boolean isClothingOnly()
Returns:
true for clothing only (not including patterns and Pivitz)

isFurniture

public boolean isFurniture()
Returns:
true for furniture

isMusic

public boolean isMusic()
Returns:
true for music

isPattern

public boolean isPattern()
Returns:
true for patterns

isPivitz

public boolean isPivitz()
Returns:
true for Pivitz

isStructure

public boolean isStructure()
Returns:
true for structure

isWearable

public boolean isWearable()
Returns:
true for clothing, Pivitz, and patterns

setActive

public void setActive(boolean beActive)
Parameters:
beActive - true if the item is active

setOwner

public void setOwner(User user)
Parameters:
user - owner

setOwnerID

public void setOwnerID(int ownerID)
Parameters:
ownerID - owner's userID

setSlotNumber

public void setSlotNumber(int slot)
Parameters:
slot - new slot number

setTypeID

public void setTypeID(int typeID)
               throws GameLogicException
Parameters:
typeID - the new type ID
Throws:
GameLogicException - if the type ID is not valid

toJSON

public org.json.JSONObject toJSON()
Overrides:
toJSON in class SQLPeerDatum
Returns:
See Also:
SQLPeerDatum.toJSON()

toString

public String toString()
Overrides:
toString in class Object