org.starhope.appius.game.inventory
Class InventoryItem

java.lang.Object
  extended by org.starhope.appius.util.SimpleDataRecord<InventoryItem>
      extended by org.starhope.appius.game.inventory.InventoryItem
All Implemented Interfaces:
com.whirlycott.cache.Cacheable, Serializable, Comparable<InventoryItem>, CTime, DataRecord, HasSubversionRevision

public class InventoryItem
extends SimpleDataRecord<InventoryItem>

The InventoryItem is the main class 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.

WRITEME — ItemEffects InventoryItemType, GenericItemReference, and how they all get along

Author:
brpocock@star-hope.org
See Also:
Serialized Form

Field Summary
protected  boolean active
          if true, the item is equipped/active
(package private)  List<Colour> colours
          The colours that define the appearance of this item.
private  String facing
          WRITEME: Document this brpocock@star-hope.org
private  BigDecimal health
          The health of the item
protected  int itemID
          the item ID
protected  int ownerID
          user owning this item
private  int roomNumber
          room number (of all rooms owned by the given owner)
private static long serialVersionUID
          Java serialisation unique ID
protected  int slotNumber
          The slot/series in which this occurs in the player's inventory
protected  InventoryItemType type
          WRITEME
private  double x
          WRITEME: Document this brpocock@star-hope.org
private  double y
          WRITEME: Document this brpocock@star-hope.org
private  double z
          WRITEME: Document this brpocock@star-hope.org
 
Fields inherited from class org.starhope.appius.util.SimpleDataRecord
myLoader, timeLastChanged, timeLastSaved
 
Constructor Summary
InventoryItem()
          WRITEME: Document this constructor brpocock@star-hope.org
InventoryItem(RecordLoader<InventoryItem> loader)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
 void changeHealth(int delta)
           
private  void checkEquipChange()
          Check whether the user needs an equipment update
 void destroy()
          Destroy an item altogether.
 boolean equals(Object obj)
           
 void equip()
          WRITEME: document this method (brpocock@star-hope.org, Nov 24, 2009)
static InventoryItem getByID(int idByWhichToGet)
          get the inventory item with the given inventory slot ID
static InventoryItem getByID(RecordLoader<InventoryItem> loader, int idByWhichToGet)
          Get an inventory item based upon the database ID
 int getCacheableID()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 String getCacheableIdent()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 Colour getColor()
           
 Colour getColour()
           
 Colour getColour(int index)
           
 List<Colour> getColours()
           
 String getFacing()
          WRITEME: Document this method brpocock@star-hope.org
 GenericItemReference getGenericItem()
           
 BigDecimal getHealth()
           
 int getID()
           
 ItemEffects getItemEffects()
          Get an ItemEffects class for this item, if any
 int getItemID()
           
private  AbstractUser getOnlineOwner()
          If the owner is online, get the owner
 AbstractUser getOwner()
           
 int getOwnerID()
           
 int getRoomIndex()
           
 int getSlotNumber()
           
 String getSubversionRevision()
           Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.
 InventoryItemType getType()
           
 int getTypeID()
           
 double getX()
           
 double getY()
           
 double getZ()
           
 int hashCode()
          This is an overriding method.
 boolean isActive()
           
private  void reportBug(String bug, Throwable e)
          Report a bug via AppiusClaudiusCaecus with the slot number for convenience in debugging
 void setActive(boolean beActive)
           
 void setColour(Colour newColour)
          Deprecated. use setColour(List) or setColour(int, Colour)
 void setColour(int newColour)
          Deprecated. use setColour(List) or setColour(int, Colour)
 void setColour(int index, Colour newColour)
          Set a particular colour.
 void setColour(List<Colour> newColours)
          Set the colours of a multi-colour item.
 void setFacing(String newFacing)
          Set the facing direction of this item (typically furniture)
 void setHealth(BigDecimal newHealth)
           
 void setItemID(int newID)
           
 void setOwner(AbstractUser owner)
           
 void setOwnerID(int ownerID1)
           
 void setRoom(Room room)
           
 void setRoomNumber(int i)
           
 void setSlotHarsh(int slotNumber_force)
          This is only to be used by addItem.
 void setSlotNumber(int slot)
           
 void setType(InventoryItemType newType)
          set the InventoryItemType of this item
 void setTypeID(int newTypeID)
           
 void setX(double newX)
          set the X ordinate of this item, within its container.
 void setY(double newY)
          set the Y abcessa of this item, within its container.
 void setZ(double newZ)
          set the Z ordinate of this item, within its container.
 org.json.JSONObject toJSON()
           
 String toString()
          This is an overriding method.
 void unequip()
          un-equip an item (set it to be inactive)
 void unsetRoom(Room room)
          remove the variable(s) set in the room to represent this item.
 
Methods inherited from class org.starhope.appius.util.SimpleDataRecord
changed, checkStale, compareTo, finalize, getRecordLoader, getTimeLastChanged, getTimeLastSaved, isBeingLoaded, markAsLoaded, markAsSaved, markForReload, onRemove, onRetrieve, onStore, save, setRecordLoader
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialisation unique ID

See Also:
Constant Field Values

active

protected boolean active
if true, the item is equipped/active


colours

final List<Colour> colours
The colours that define the appearance of this item. XXX: only single-colour items are supported in Tootsville™ right now.


facing

private String facing
WRITEME: Document this brpocock@star-hope.org


health

private BigDecimal health
The health of the item


itemID

protected int itemID
the item ID


ownerID

protected int ownerID
user owning this item


roomNumber

private int roomNumber
room number (of all rooms owned by the given owner)


slotNumber

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


type

protected InventoryItemType type
WRITEME


x

private double x
WRITEME: Document this brpocock@star-hope.org


y

private double y
WRITEME: Document this brpocock@star-hope.org


z

private double z
WRITEME: Document this brpocock@star-hope.org

Constructor Detail

InventoryItem

public InventoryItem()
WRITEME: Document this constructor brpocock@star-hope.org


InventoryItem

public InventoryItem(RecordLoader<InventoryItem> loader)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
loader - the loader
Method Detail

getByID

public static InventoryItem getByID(int idByWhichToGet)
get the inventory item with the given inventory slot ID

Parameters:
idByWhichToGet - inventory slot number
Returns:
the item in that slot

getByID

public static InventoryItem getByID(RecordLoader<InventoryItem> loader,
                                    int idByWhichToGet)
Get an inventory item based upon the database ID

Parameters:
loader - record loader to obtain the item
idByWhichToGet - the database ID of an inventory item of any kind
Returns:
the item or null if there's no such item

changeHealth

public void changeHealth(int delta)
Parameters:
delta - the amount by which to change the health

checkEquipChange

private void checkEquipChange()
Check whether the user needs an equipment update


destroy

public void destroy()
Destroy an item altogether.


equals

public boolean equals(Object obj)
Overrides:
equals in class SimpleDataRecord<InventoryItem>
See Also:
Object.equals(java.lang.Object)

equip

public void equip()
WRITEME: document this method (brpocock@star-hope.org, Nov 24, 2009)


getCacheableID

public int getCacheableID()
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Returns:
an unique ID number
See Also:
DataRecord.getCacheableID()

getCacheableIdent

public String getCacheableIdent()
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Returns:
an unique identifier string
See Also:
DataRecord.getCacheableIdent()

getColor

public Colour getColor()
Returns:
the first colour of this item. (the only colour for some items)

getColour

public Colour getColour()
Returns:
the first colour of this item (the only colour for some items), or null if the item is completely uncoloured.

getColour

public Colour getColour(int index)
Parameters:
index - the colour index position
Returns:
the colour at that index, or null

getColours

public List<Colour> getColours()
Returns:
any/all colours applied to this item

getFacing

public String getFacing()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

getGenericItem

public GenericItemReference getGenericItem()
Returns:
get a GenericItemReference of the same kind as this

getHealth

public BigDecimal getHealth()
Returns:
the health of this item

getID

public int getID()
Returns:
the item's ID (as a kind of item)

getItemEffects

public ItemEffects getItemEffects()
                           throws NotFoundException
Get an ItemEffects class for this item, if any

Returns:
item effects class for this item
Throws:
NotFoundException - if no item effects are defined

getItemID

public int getItemID()
Returns:
the store item ID, of which this item is an instance

getOnlineOwner

private AbstractUser getOnlineOwner()
                             throws NotFoundException
If the owner is online, get the owner

Returns:
the online owner's object
Throws:
NotFoundException - if the owner isn't online (or isn't a valid ownerID)

getOwner

public AbstractUser getOwner()
Returns:
owner

getOwnerID

public int getOwnerID()
Returns:
owner's userID

getRoomIndex

public int getRoomIndex()
Returns:
the room number in which this item is found, or -1 if it is not placed in a room.

getSlotNumber

public int getSlotNumber()
Returns:
slotNumber

getSubversionRevision

public String getSubversionRevision()
Description copied from interface: HasSubversionRevision

Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.

As an example,the Subversion revision string for this file is "$Rev: 1968 $"

 
 @Override
 public String getSubversionRevision () {
        return "$Rev: ";
 }
 

Returns:
The Subversion revision level for this class's source code file.
See Also:
HasSubversionRevision.getSubversionRevision()

getType

public InventoryItemType getType()
Returns:
the type of item, which this is.

getTypeID

public int getTypeID()
Returns:
the type ID

getX

public double getX()
Returns:
x ordinate

getY

public double getY()
Returns:
y abcessa

getZ

public double getZ()
Returns:
Z ordinate

hashCode

public int hashCode()
This is an overriding method.

Overrides:
hashCode in class SimpleDataRecord<InventoryItem>
See Also:
Object.hashCode()

isActive

public boolean isActive()
Returns:
true, if the item is active/in use/equipped

reportBug

private void reportBug(String bug,
                       Throwable e)
Report a bug via AppiusClaudiusCaecus with the slot number for convenience in debugging

Parameters:
bug - the bug string
e - an exception thrown

setActive

@Setter(getter="isActive")
public void setActive(boolean beActive)
Parameters:
beActive - true if the item is active

setColour

@Deprecated
public void setColour(Colour newColour)
Deprecated. use setColour(List) or setColour(int, Colour)

set the colour of a single-colour item.

Parameters:
newColour - the new colour

setColour

@Deprecated
public void setColour(int newColour)
Deprecated. use setColour(List) or setColour(int, Colour)

set the colour of a single-colour item.

Parameters:
newColour - the new colour, or -1 for no colour.

setColour

public void setColour(int index,
                      Colour newColour)
Set a particular colour.

Parameters:
index - the index position of the colour
newColour - the new colour

setColour

public void setColour(List<Colour> newColours)
Set the colours of a multi-colour item.

Parameters:
newColours - the ordered set of colours

setFacing

@Setter
public void setFacing(String newFacing)
Set the facing direction of this item (typically furniture)

Parameters:
newFacing - the new facing directions

setHealth

@Setter
public void setHealth(BigDecimal newHealth)
Parameters:
newHealth - the health to set

setItemID

@Setter
public void setItemID(int newID)
Parameters:
newID - the item ID represented by this inventory slot

setOwner

public void setOwner(AbstractUser owner)
Parameters:
owner - owner

setOwnerID

@Setter
public void setOwnerID(int ownerID1)
Parameters:
ownerID1 - owner's userID

setRoom

public void setRoom(Room room)
Parameters:
room - the room in which this item is found

setRoomNumber

@Setter(getter="getRoomIndex")
public void setRoomNumber(int i)
Parameters:
i - room index

setSlotHarsh

@Setter(getter="getSlotNumber")
public void setSlotHarsh(int slotNumber_force)
This is only to be used by addItem. Sets the Slot number without flushing the item.

Parameters:
slotNumber_force - The retrieved slot number from an insert.

setSlotNumber

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

setType

public void setType(InventoryItemType newType)
set the InventoryItemType of this item

Parameters:
newType - the new type

setTypeID

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

setX

@Setter
public void setX(double newX)
set the X ordinate of this item, within its container. Has no effect upon items contained by an user (e.g. clothing).

Parameters:
newX - new X

setY

@Setter
public void setY(double newY)
set the Y abcessa of this item, within its container. Has no effect upon items contained by an user (e.g. clothing).

Parameters:
newY - new Y

setZ

@Setter
public void setZ(double newZ)
set the Z ordinate of this item, within its container. Has no effect upon items contained by an user (e.g. clothing).

Parameters:
newZ - new Z

toJSON

public org.json.JSONObject toJSON()
Returns:
a JSON object representing this item
See Also:
CastsToJSON.toJSON()

toString

public String toString()
This is an overriding method.

Overrides:
toString in class SimpleDataRecord<InventoryItem>
See Also:
Object.toString()

unequip

public void unequip()
un-equip an item (set it to be inactive)


unsetRoom

public void unsetRoom(Room room)
remove the variable(s) set in the room to represent this item.

Parameters:
room - some room