rlgamekit.equipment
Class Equipment<E>

java.lang.Object
  extended by rlgamekit.equipment.Equipment<E>

public class Equipment<E>
extends java.lang.Object

Equipment collection for player and non-player characters. Slots can be guarded by constraints.

See Also:
EquipmentListener, Constraint

Field Summary
 java.lang.String[] slotNames
          Each slot can have a name.
 
Constructor Summary
Equipment(java.lang.String[] slotNames)
          Create a new equipment structure.
 
Method Summary
 void addListener(EquipmentListener l)
          Add a listener to be called upon equipment changes.
 E getItem(int slot)
          Get the item from a particular equipment slot.
 void removeListener(EquipmentListener l)
          Remove a listener from the listener list.
 void setConstraint(int slot, Constraint<E> constraint)
          Set a constraint for an equipment slot.
 boolean setItem(int slot, E item)
          Try to place an item into an equipment slot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

slotNames

public final java.lang.String[] slotNames
Each slot can have a name. Useful for displaying equipment overviews.

Constructor Detail

Equipment

public Equipment(java.lang.String[] slotNames)
Create a new equipment structure.

Parameters:
slotNames - Array with all slot names.
Method Detail

getItem

public E getItem(int slot)
Get the item from a particular equipment slot.

Parameters:
slot - The slot
Returns:
The item or null if there is no item in this slot.

setItem

public boolean setItem(int slot,
                       E item)
Try to place an item into an equipment slot. Will override any item previously in that slot.

Parameters:
slot - The slot
item - The item
Returns:
true if the item fits, false otherwise.

setConstraint

public void setConstraint(int slot,
                          Constraint<E> constraint)
Set a constraint for an equipment slot.

Parameters:
slot - The slot
constraint - The constraint

addListener

public void addListener(EquipmentListener l)
Add a listener to be called upon equipment changes.

Parameters:
l - The listener to add.

removeListener

public void removeListener(EquipmentListener l)
Remove a listener from the listener list.

Parameters:
l - The listener to remove.