com.realtime.crossfire.jxclient.items
Class ItemSet

java.lang.Object
  extended by com.realtime.crossfire.jxclient.items.ItemSet

public class ItemSet
extends java.lang.Object

Model class maintaining the CfItems known to the player.


Field Summary
private  java.util.Map<java.lang.Integer,CfItem> allItems
          Maps item tags to items.
private  HashedEventListenerList itemListeners
          The registered ItemListeners to be notified about changes.
private  java.util.Map<java.lang.Integer,java.util.List<CfItem>> items
          Maps location (=tag) to list of items in that location.
private  javax.swing.event.EventListenerList itemSetListeners
          The list of ItemSetListeners to be notified about changes.
private  int openContainerFloor
          The currently opened container or 0.
private  CfItem player
          The current player object this client controls.
private  java.lang.Object sync
          The synchronization object for XXX.
 
Constructor Summary
ItemSet()
           
 
Method Summary
 void addInventoryListener(int tag, ItemListener listener)
          Adds an ItemListener to be notified about changes.
 void addItem(CfItem item)
          Adds an item.
private  int addItem(CfItem item, boolean notifyListeners)
          Adds a CfItem.
 void addItemSetListener(ItemSetListener listener)
          Adds an ItemSetListener to be notified about changes.
 void cleanInventory(int tag)
          Clears the inventory of an item.
private  java.util.List<CfItem> getInventoryByTag(int tag)
          Returns the inventory of an item.
 CfItem getInventoryItem(int tag, int index)
          Returns a CfItem from the inventory of an item.
 CfItem getItemByTag(int tag)
          Returns an item by tag.
private  CfItem getItemOrPlayer(int tag)
          Returns an item by tag.
 java.util.List<CfItem> getItemsByLocation(int location)
          Returns a list of items in a given location.
 int getNumberOfItemsByLocation(int location)
          Returns the number of items in a given location.
 int getOpenContainer()
          Returns the currently opened container.
 CfItem getPlayer()
          Returns the player object this client controls.
 java.lang.Iterable<CfItem> getPlayerInventory()
          Returns the player's inventory.
 void removeInventoryListener(int tag, ItemListener listener)
          Removes an ItemListener to be notified about changes.
private  int removeItemByTag(int tag, boolean notifyListeners)
          Removes a CfItem.
 void removeItems(int[] tags)
          Deletes items by tag.
 void removeItemSetListener(ItemSetListener listener)
          Removes an ItemSetListener to be notified about changes.
 void reset()
          Resets the manager's state.
private  void setOpenContainer(int openContainerFloor)
          Sets the currently opened container.
 void setPlayer(CfItem player)
          Sets the player object this client controls.
 void updateItem(int flags, int tag, int valLocation, int valFlags, int valWeight, Face valFace, java.lang.String valName, java.lang.String valNamePl, int valAnim, int valAnimSpeed, int valNrof)
          Processes an "upditem" command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allItems

@NotNull
private final java.util.Map<java.lang.Integer,CfItem> allItems
Maps item tags to items. The map contains all items currently known to the client.


itemListeners

@NotNull
private final HashedEventListenerList itemListeners
The registered ItemListeners to be notified about changes.


items

@NotNull
private final java.util.Map<java.lang.Integer,java.util.List<CfItem>> items
Maps location (=tag) to list of items in that location.


itemSetListeners

@NotNull
private final javax.swing.event.EventListenerList itemSetListeners
The list of ItemSetListeners to be notified about changes.


openContainerFloor

private int openContainerFloor
The currently opened container or 0.


player

@Nullable
private CfItem player
The current player object this client controls.


sync

@NotNull
private final java.lang.Object sync
The synchronization object for XXX.

Constructor Detail

ItemSet

public ItemSet()
Method Detail

addInventoryListener

public void addInventoryListener(int tag,
                                 @NotNull
                                 ItemListener listener)
Adds an ItemListener to be notified about changes.

Parameters:
tag - the item tag to watch
listener - the listener to add

addItem

public void addItem(@NotNull
                    CfItem item)
Adds an item.

Parameters:
item - the item to add

addItem

private int addItem(@NotNull
                    CfItem item,
                    boolean notifyListeners)
Adds a CfItem.

Parameters:
item - the item to add
notifyListeners - whether listeners should be notified about the addition
Returns:
the index where the item has been inserted

addItemSetListener

public void addItemSetListener(@NotNull
                               ItemSetListener listener)
Adds an ItemSetListener to be notified about changes.

Parameters:
listener - the listener to add

cleanInventory

public void cleanInventory(int tag)
Clears the inventory of an item.

Parameters:
tag - the item tag

getInventoryByTag

@NotNull
private java.util.List<CfItem> getInventoryByTag(int tag)
Returns the inventory of an item.

Parameters:
tag - the item's tag
Returns:
the inventory items; the list cannot be modified

getInventoryItem

@Nullable
public CfItem getInventoryItem(int tag,
                                        int index)
Returns a CfItem from the inventory of an item.

Parameters:
tag - the item's tag
index - the index of the inventory item to return
Returns:
the inventory item or null if the index does not exist

getItemByTag

@Nullable
public CfItem getItemByTag(int tag)
Returns an item by tag.

Parameters:
tag - the tag
Returns:
the item or null if no such items exists

getItemOrPlayer

@Nullable
private CfItem getItemOrPlayer(int tag)
Returns an item by tag. This function may return the player object.

Parameters:
tag - The tag.
Returns:
the item or null if no such item exists

getItemsByLocation

@NotNull
public java.util.List<CfItem> getItemsByLocation(int location)
Returns a list of items in a given location. The returned list may not be modified by the caller.

Parameters:
location - the location
Returns:
the list of items

getNumberOfItemsByLocation

public int getNumberOfItemsByLocation(int location)
Returns the number of items in a given location. Undefined locations return 0.

Parameters:
location - the location to check
Returns:
the number of items

getOpenContainer

public int getOpenContainer()
Returns the currently opened container.

Returns:
the opened container's tag

getPlayer

@Nullable
public CfItem getPlayer()
Returns the player object this client controls.

Returns:
the player object

getPlayerInventory

@NotNull
public java.lang.Iterable<CfItem> getPlayerInventory()
Returns the player's inventory.

Returns:
the inventory items; the list cannot be modified

removeInventoryListener

public void removeInventoryListener(int tag,
                                    @NotNull
                                    ItemListener listener)
Removes an ItemListener to be notified about changes.

Parameters:
tag - the item tag to watch
listener - the listener to add

removeItemByTag

private int removeItemByTag(int tag,
                            boolean notifyListeners)
Removes a CfItem.

Parameters:
tag - the item's tag to remove
notifyListeners - whether listeners should be notified about the removal
Returns:
the index where the item has been removed from or -1

removeItems

public void removeItems(@NotNull
                        int[] tags)
Deletes items by tag.

Parameters:
tags - the tags to delete

removeItemSetListener

public void removeItemSetListener(@NotNull
                                  ItemSetListener listener)
Removes an ItemSetListener to be notified about changes.

Parameters:
listener - the listener to remove

reset

public void reset()
Resets the manager's state.


setOpenContainer

private void setOpenContainer(int openContainerFloor)
Sets the currently opened container.

Parameters:
openContainerFloor - the opened container's tag or 0

setPlayer

public void setPlayer(@Nullable
                      CfItem player)
Sets the player object this client controls.

Parameters:
player - the new player object

updateItem

public void updateItem(int flags,
                       int tag,
                       int valLocation,
                       int valFlags,
                       int valWeight,
                       Face valFace,
                       @NotNull
                       java.lang.String valName,
                       @NotNull
                       java.lang.String valNamePl,
                       int valAnim,
                       int valAnimSpeed,
                       int valNrof)
Processes an "upditem" command.

Parameters:
flags - the changed values
tag - the item's tag
valLocation - the item's location
valFlags - the item's flags
valWeight - the item's weight
valFace - the item's face
valName - the item's singular name
valNamePl - the item's plural name
valAnim - the item's animation ID
valAnimSpeed - the item's animation speed
valNrof - the number of items