Mana
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Inventory Class Reference

#include <inventory.h>

Public Types

enum  Type { INVENTORY , STORAGE , TRADE , TYPE_END }
 

Public Member Functions

 Inventory (Type type, int size=-1)
 Constructor.
 
 ~Inventory ()
 
int getSize () const
 Returns the size that this instance is configured for.
 
ItemgetItem (int index) const
 Returns the item at the specified index.
 
ItemfindItem (int itemId) const
 Searches for the specified item by it's id.
 
void addItem (int id, int quantity)
 Adds a new item in a free slot.
 
void setItem (int index, int id, int quantity)
 Sets the item at the given position.
 
void removeItemAt (int index)
 Remove the item at the specified index from the inventory.
 
bool contains (Item *item) const
 Checks if the given item is in the inventory.
 
int getFreeSlot () const
 Returns id of next free slot or -1 if all occupied.
 
void clear ()
 Reset all item slots.
 
int getNumberOfSlotsUsed () const
 Get the number of slots filled with an item.
 
int getLastUsedSlot () const
 Returns the index of the last occupied slot or 0 if none occupied.
 
void addInventoryListener (InventoryListener *listener)
 
void removeInventoryListener (InventoryListener *listener)
 
int getType () const
 
bool isMainInventory () const
 

Static Public Attributes

static const int NO_SLOT_INDEX = -1
 Slot has no index.
 

Protected Member Functions

void distributeSlotsChangedEvent ()
 

Protected Attributes

std::list< InventoryListener * > mInventoryListeners
 
Type mType
 
std::vector< std::unique_ptr< Item > > mItems
 The holder of items.
 
int mUsed = 0
 The number of slots in use.
 

Detailed Description

Definition at line 42 of file inventory.h.

Member Enumeration Documentation

◆ Type

Enumerator
INVENTORY 
STORAGE 
TRADE 
TYPE_END 

Definition at line 47 of file inventory.h.

Constructor & Destructor Documentation

◆ Inventory()

Inventory::Inventory ( Type  type,
int  size = -1 
)

Constructor.

Parameters
sizethe number of items that fit in the inventory

Definition at line 36 of file inventory.cpp.

◆ ~Inventory()

Inventory::~Inventory ( )
default

Member Function Documentation

◆ addInventoryListener()

void Inventory::addInventoryListener ( InventoryListener listener)

Definition at line 140 of file inventory.cpp.

◆ addItem()

void Inventory::addItem ( int  id,
int  quantity 
)

Adds a new item in a free slot.

Definition at line 61 of file inventory.cpp.

◆ clear()

void Inventory::clear ( )

Reset all item slots.

Definition at line 96 of file inventory.cpp.

◆ contains()

bool Inventory::contains ( Item item) const

Checks if the given item is in the inventory.

Definition at line 113 of file inventory.cpp.

◆ distributeSlotsChangedEvent()

void Inventory::distributeSlotsChangedEvent ( )
protected

Definition at line 150 of file inventory.cpp.

◆ findItem()

Item * Inventory::findItem ( int  itemId) const

Searches for the specified item by it's id.

Parameters
itemIdThe id of the item to be searched.
Returns
Item found on success, NULL on failure.

Definition at line 52 of file inventory.cpp.

◆ getFreeSlot()

int Inventory::getFreeSlot ( ) const

Returns id of next free slot or -1 if all occupied.

Definition at line 122 of file inventory.cpp.

◆ getItem()

Item * Inventory::getItem ( int  index) const

Returns the item at the specified index.

Definition at line 44 of file inventory.cpp.

◆ getLastUsedSlot()

int Inventory::getLastUsedSlot ( ) const

Returns the index of the last occupied slot or 0 if none occupied.

Definition at line 131 of file inventory.cpp.

◆ getNumberOfSlotsUsed()

int Inventory::getNumberOfSlotsUsed ( ) const
inline

Get the number of slots filled with an item.

Definition at line 115 of file inventory.h.

◆ getSize()

int Inventory::getSize ( ) const
inline

Returns the size that this instance is configured for.

Definition at line 67 of file inventory.h.

◆ getType()

int Inventory::getType ( ) const
inline

Definition at line 126 of file inventory.h.

◆ isMainInventory()

bool Inventory::isMainInventory ( ) const
inline

Definition at line 129 of file inventory.h.

◆ removeInventoryListener()

void Inventory::removeInventoryListener ( InventoryListener listener)

Definition at line 145 of file inventory.cpp.

◆ removeItemAt()

void Inventory::removeItemAt ( int  index)

Remove the item at the specified index from the inventory.

Definition at line 104 of file inventory.cpp.

◆ setItem()

void Inventory::setItem ( int  index,
int  id,
int  quantity 
)

Sets the item at the given position.

Definition at line 66 of file inventory.cpp.

Member Data Documentation

◆ mInventoryListeners

std::list<InventoryListener *> Inventory::mInventoryListeners
protected

Definition at line 133 of file inventory.h.

◆ mItems

std::vector<std::unique_ptr<Item> > Inventory::mItems
protected

The holder of items.

Definition at line 138 of file inventory.h.

◆ mType

Type Inventory::mType
protected

Definition at line 137 of file inventory.h.

◆ mUsed

int Inventory::mUsed = 0
protected

The number of slots in use.

Definition at line 139 of file inventory.h.

◆ NO_SLOT_INDEX

const int Inventory::NO_SLOT_INDEX = -1
static

Slot has no index.

Definition at line 45 of file inventory.h.


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