jurpe.items
Class BasicItem

java.lang.Object
  extended by jurpe.items.BasicItem
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
Direct Known Subclasses:
Armor, Item, MoneyBag, Shield, Weapon

public abstract class BasicItem
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

Base class for every PHYSICAL OBJECT of the game, ie: weapons, shields, armors, rings and so on.

Author:
Alessio Saltarin
See Also:
Serialized Form

Constructor Summary
BasicItem(ItemType itemType, java.lang.String oNome, int oCosto, int oPeso)
          Constructor for wearable/not usable objects
BasicItem(ItemType itemType, java.lang.String oNome, int oCosto, int oPeso, boolean usable, boolean wearable)
          Generic Constructor
 
Method Summary
 java.lang.Object clone()
          Clone BasicItem.
 int compareTo(java.lang.Object rv)
          Adds comparability to all derived classes Comparing is always made on cost
 java.lang.String getCommonDescription()
          Returns cost and weight of an BasicItem.
 int getCost()
          Returns cost of object
 java.lang.String getDescription()
          Every object is able to describe himself
 java.lang.String getName()
          Get the name of the object
 ItemType getType()
          Returns type of item, such as: BasicItem.WEAPON, BasicItem.ARMOR, BasicItem.SHIELD, BasicItem.OTHER or BasicItem.ITEM.
 int getWeight()
          Returns weight of object
 boolean isItemRandom()
          If this item was randomly created
 boolean isItemUsable()
          If this item is usable (character can use it)
 boolean isItemWearable()
          If this item is wearable (character can wear it)
 void setRandom(boolean rnd)
          Set if this item was randomly created
 java.lang.String toString()
          Object's name
 java.lang.String toStringWCost()
          Object's name and cost
 void unwear(PCharacter pc)
          Every object is able to unwear itself
 boolean use(PCharacter pc)
          Use this object onto given character
 java.lang.String warningMessage()
          Every time an BasicItem needs to send a message back, this field can be used.
 boolean wear(PCharacter pc)
          Every object is able to wear itself in the correct position of a character (ie: arms in right hand).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicItem

public BasicItem(ItemType itemType,
                 java.lang.String oNome,
                 int oCosto,
                 int oPeso)
Constructor for wearable/not usable objects

Parameters:
itemType - Describes item type. Use BasicItem.WEAPON, BasicItem.ARMOR, BasicItem.SHIELD, BasicItem.OTHER or BasicItem.ITEM
oNome - Name of object
oCosto - Cost of object
oPeso - Weight of object

BasicItem

public BasicItem(ItemType itemType,
                 java.lang.String oNome,
                 int oCosto,
                 int oPeso,
                 boolean usable,
                 boolean wearable)
Generic Constructor

Parameters:
itemType - Describes item type. Use BasicItem.WEAPON, BasicItem.ARMOR, BasicItem.SHIELD, BasicItem.OTHER or BasicItem.ITEM
oNome - Name of object
oCosto - Cost of object
oPeso - Weight of object
usable - If this object is usable by a character (ie: potion)
wearable - If this object can be worn by a character (ie: ring)
Method Detail

getCost

public int getCost()
Returns cost of object

Returns:
The cost of object (in abstract units)

getType

public ItemType getType()
Returns type of item, such as: BasicItem.WEAPON, BasicItem.ARMOR, BasicItem.SHIELD, BasicItem.OTHER or BasicItem.ITEM.

Returns:
type of item.

isItemUsable

public boolean isItemUsable()
If this item is usable (character can use it)

Returns:
true, if this object is usable

isItemWearable

public boolean isItemWearable()
If this item is wearable (character can wear it)

Returns:
true, if this object is wearable

isItemRandom

public boolean isItemRandom()
If this item was randomly created

Returns:
true, if this item was not read from an xml file, but rather randomly created.

getWeight

public int getWeight()
Returns weight of object

Returns:
Object's weight.

getName

public java.lang.String getName()
Get the name of the object

Returns:
Object's name

warningMessage

public java.lang.String warningMessage()
Every time an BasicItem needs to send a message back, this field can be used.

Returns:
A message string

getCommonDescription

public java.lang.String getCommonDescription()
Returns cost and weight of an BasicItem. (Every object MUST have a cost and weight associated).

Returns:
String containing cost and weight, separated by \n

getDescription

public java.lang.String getDescription()
Every object is able to describe himself

Returns:
String containing object name, cost, weight and other properties.

wear

public boolean wear(PCharacter pc)
Every object is able to wear itself in the correct position of a character (ie: arms in right hand). Returns false if object is not wearable

Parameters:
pc - PCharacter who is wearing this object
Returns:
true if character correctly wore BasicItem

unwear

public void unwear(PCharacter pc)
Every object is able to unwear itself

Parameters:
pc - PCharacter who is unwearing this object

use

public boolean use(PCharacter pc)
Use this object onto given character

Parameters:
pc - PCharacter who is using this object
Returns:
true, if object was correctly used. If false, call this.warningMessage to discover why.

toString

public java.lang.String toString()
Object's name

Overrides:
toString in class java.lang.Object
Returns:
Object's name

toStringWCost

public java.lang.String toStringWCost()
Object's name and cost

Returns:
Name and cost of the object

clone

public java.lang.Object clone()
Clone BasicItem.

Overrides:
clone in class java.lang.Object
Returns:
Cloned BasicItem

compareTo

public int compareTo(java.lang.Object rv)
Adds comparability to all derived classes Comparing is always made on cost

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
rv - Compared BasicItem
Returns:
0 if objects are equals (they have the same cost). -1 if this object has minor cost that rv 1 if this object costs more than rv

setRandom

public void setRandom(boolean rnd)
Set if this item was randomly created

Parameters:
rnd - true if this item has been generated at random

Jurpe - Java Universal Role Playing Engine - http://jurpe.sourceforge.net