Inventory Class Reference

Class used to handle Character possessions and prepare outgoing messages. More...

#include <inventory.hpp>

List of all members.

Public Member Functions

 Inventory (Character *, bool delayed=false)
 Creates a view on the possessions of a character.
 ~Inventory ()
 Commits delayed changes.
void commit ()
 Commits delayed changes.
void cancel ()
 Cancels delayed changes.
void sendFull () const
 Sends a complete inventory update to the client.
void initialize ()
 Ensures the inventory is sane and apply equipment modifiers.
void equip (int slot)
 Equips item from given inventory slot.
void unequip (int slot)
 Unequips item from given equipment slot.
int fireProjectile ()
 Gets the ID of projectiles.
int insert (int itemId, int amount)
 Inserts some items into the inventory.
int remove (int itemId, int amount)
 Removes some items from inventory.
int move (int slot1, int slot2, int amount)
 Moves some items from the first slot to the second one.
int removeFromSlot (int slot, int amount)
 Removes some items from inventory.
int count (int itemId) const
 Counts number of items with given ID.
int getItem (int slot) const
 Gets the ID of the items in a given slot.
bool changeMoney (int)
 Changes amount of money.


Detailed Description

Class used to handle Character possessions and prepare outgoing messages.

Definition at line 64 of file inventory.hpp.


Constructor & Destructor Documentation

Inventory::Inventory ( Character p,
bool  delayed = false 
)

Creates a view on the possessions of a character.

Parameters:
delayed true if changes have to be cancelable.

Definition at line 33 of file inventory.cpp.

Inventory::~Inventory (  ) 

Commits delayed changes.

Sends the update message to the client.

Definition at line 39 of file inventory.cpp.

References MessageOut::getLength(), and GameHandler::sendTo().


Member Function Documentation

void Inventory::initialize (  ) 

Ensures the inventory is sane and apply equipment modifiers.

Should be run only once and the very first time.

Definition at line 144 of file inventory.cpp.

References Possessions::equipment, Character::getDatabaseID(), and Possessions::inventory.

int Inventory::fireProjectile (  ) 

Gets the ID of projectiles.

Removes one of these projectiles from inventory.

int Inventory::insert ( int  itemId,
int  amount 
)

Inserts some items into the inventory.

Returns:
number of items not inserted (to be dropped on floor?).

Definition at line 289 of file inventory.cpp.

References Possessions::inventory, MessageOut::writeByte(), and MessageOut::writeShort().

Referenced by equip(), GameHandler::processMessage(), and unequip().

int Inventory::remove ( int  itemId,
int  amount 
)

Removes some items from inventory.

Returns:
number of items not removed.

Definition at line 407 of file inventory.cpp.

References InventoryItem::amount, Possessions::inventory, InventoryItem::itemId, MessageOut::writeByte(), and MessageOut::writeShort().

int Inventory::move ( int  slot1,
int  slot2,
int  amount 
)

Moves some items from the first slot to the second one.

Returns:
number of items not moved.

Definition at line 447 of file inventory.cpp.

References InventoryItem::amount, Possessions::inventory, InventoryItem::itemId, MessageOut::writeByte(), and MessageOut::writeShort().

int Inventory::removeFromSlot ( int  slot,
int  amount 
)

Removes some items from inventory.

Returns:
number of items not removed.

Definition at line 601 of file inventory.cpp.

References InventoryItem::amount, Possessions::inventory, InventoryItem::itemId, MessageOut::writeByte(), and MessageOut::writeShort().

Referenced by GameHandler::processMessage().

bool Inventory::changeMoney ( int  amount  ) 

Changes amount of money.

Returns:
false if not enough money.

Definition at line 349 of file inventory.cpp.

References Possessions::money, MessageOut::writeByte(), and MessageOut::writeLong().


The documentation for this class was generated from the following files:

Generated on Sun Apr 26 17:30:46 2009 for TMW Server Collection by  doxygen 1.5.5