org.haphazard.item
Class Item

java.lang.Object
  extended byorg.haphazard.item.Item
All Implemented Interfaces:
Containing
Direct Known Subclasses:
Clothes

public class Item
extends java.lang.Object
implements Containing

A class that denotes an item in the world


Field Summary
protected  Container mContainer
          A container (if the item can contain other things)
protected  java.lang.String mName
          The name of the item
 int mQuality
           
 
Constructor Summary
Item()
          Creates an item
Item(java.lang.String name)
          Creates an item of a certain type
 
Method Summary
 boolean add(Item item)
          Adds an item to this container
 boolean canHold(Item item)
          Checks if this container can hold the specified item
 boolean contains(Item item)
          Checks if this container contains this item
 int getAttackBonus()
          Returns the attack bonus of the item
 Dimension3D getContainerDimension()
          Gets the total volume of the container
 int getContainerWeight()
          Gets the total weight of the container
 int getDamageBonus()
          Gets the items damage bonus The damage bonus is dependant on the items weight and if it is solid and has edges
 int getDefenceBonus()
          Returns the defence bonus of the item
 java.lang.String getDescription()
          Gets the description of the item
 Dimension3D getDimension()
          Gets this objects dimension
 int getFreeSpecializationSlots()
          Gets the number of free slots
 int getFreeVolume()
          Gets the total free volume of the inventory
 GeneralItem getGeneralItem()
          Gets the general item of this type from Global Items
 java.lang.String getName()
          Returns the type of the item
 java.util.Vector getRestrictions()
          Gets a vector with the restrictions for equipping this object.
 java.lang.String getSkill()
          Gets the attack skill of the item
 javax.swing.tree.DefaultMutableTreeNode getTreeNode()
          Gets the treenode of the item
 int getWeight()
          Gets the weight of the item
 boolean hasEdges()
          Checks if the item has edges
 boolean isContainer()
          Checks if this item is a container
 boolean isSolid()
          Checks if the item is solid
 boolean isSpecialization(Item item)
          Checks if an item is a specialization of this container
 boolean remove(Item item)
          Removes an item from this container
 void setName(java.lang.String name)
          Sets the type of item
 java.lang.String toString()
          Translates this item into a String notation
 java.lang.String toXML(int indent)
          Translates this item into an XML notation
 void wear(int chance)
          Calculates the wear of the item and modifies quality accordingly The higher the quality of the item, the lower the chance of wear to take effect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mName

protected java.lang.String mName
The name of the item


mContainer

protected Container mContainer
A container (if the item can contain other things)


mQuality

public int mQuality
Constructor Detail

Item

public Item()
Creates an item


Item

public Item(java.lang.String name)
Creates an item of a certain type

Parameters:
name - The type of the item to create
Method Detail

setName

public void setName(java.lang.String name)
Sets the type of item

Parameters:
name - The type of the item

getName

public java.lang.String getName()
Returns the type of the item

Returns:
The type of the item

getWeight

public int getWeight()
Gets the weight of the item

Returns:
The weight in grams

getDescription

public java.lang.String getDescription()
Gets the description of the item

Returns:
The description of the item

getDimension

public Dimension3D getDimension()
Gets this objects dimension

Returns:
The objects dimension

wear

public void wear(int chance)
Calculates the wear of the item and modifies quality accordingly The higher the quality of the item, the lower the chance of wear to take effect

Parameters:
chance - The percentage chance of lowering the quality

hasEdges

public boolean hasEdges()
Checks if the item has edges

Returns:
True if the item has edges

isSolid

public boolean isSolid()
Checks if the item is solid

Returns:
True if the item is solid

getRestrictions

public java.util.Vector getRestrictions()
Gets a vector with the restrictions for equipping this object. The restrictions are strings on the form "restriction param1 ... params". For example, the restriction "bodypart Arm" restricts the usage of the object to characters who have an arm.

Returns:
A Vector of Strings (Restrictions), null if no restrictions

getDamageBonus

public int getDamageBonus()
Gets the items damage bonus The damage bonus is dependant on the items weight and if it is solid and has edges

Returns:
A bonus value for the attack

getSkill

public java.lang.String getSkill()
Gets the attack skill of the item

Returns:
Which skill that should be used when attacking with the item

getAttackBonus

public int getAttackBonus()
Returns the attack bonus of the item

Returns:
The attack bonus (0)

getDefenceBonus

public int getDefenceBonus()
Returns the defence bonus of the item

Returns:
The defence bonus (0)

add

public boolean add(Item item)
Adds an item to this container

Specified by:
add in interface Containing
Parameters:
item - The item to add
Returns:
True if the the add went ok

remove

public boolean remove(Item item)
Removes an item from this container

Specified by:
remove in interface Containing
Parameters:
item - The item to remove
Returns:
True if the remove went ok

canHold

public boolean canHold(Item item)
Checks if this container can hold the specified item

Specified by:
canHold in interface Containing
Parameters:
item - The item to check against
Returns:
True if the container can hold the item

contains

public boolean contains(Item item)
Checks if this container contains this item

Specified by:
contains in interface Containing
Parameters:
item - The item to check for
Returns:
True if the item is in this container

getContainerDimension

public Dimension3D getContainerDimension()
Gets the total volume of the container

Specified by:
getContainerDimension in interface Containing
Returns:
The total volume of the container

getFreeSpecializationSlots

public int getFreeSpecializationSlots()
Gets the number of free slots

Specified by:
getFreeSpecializationSlots in interface Containing
Returns:
Gets the number of free specialization slots on this container

isSpecialization

public boolean isSpecialization(Item item)
Checks if an item is a specialization of this container

Specified by:
isSpecialization in interface Containing
Parameters:
item - The item to check

getFreeVolume

public int getFreeVolume()
Gets the total free volume of the inventory

Specified by:
getFreeVolume in interface Containing
Returns:
The total free volume of the inventory

getContainerWeight

public int getContainerWeight()
Gets the total weight of the container

Specified by:
getContainerWeight in interface Containing
Returns:
The total weight of the container

isContainer

public boolean isContainer()
Checks if this item is a container

Returns:
True if the item is a container

toXML

public java.lang.String toXML(int indent)
Translates this item into an XML notation

Parameters:
indent - The indentation level
Returns:
The item in XML syntax

getTreeNode

public javax.swing.tree.DefaultMutableTreeNode getTreeNode()
Gets the treenode of the item

Specified by:
getTreeNode in interface Containing
Returns:
The node of the inventory to be used in a JTree

toString

public java.lang.String toString()
Translates this item into a String notation

Returns:
The item in String syntax

getGeneralItem

public GeneralItem getGeneralItem()
Gets the general item of this type from Global Items

Returns:
The item retrieved, null if none