ManaPlus
Public Member Functions
ComplexInventory Class Reference

#include <complexinventory.h>

Inheritance diagram for ComplexInventory:
Inventory

Public Member Functions

 ComplexInventory (const InventoryTypeT type, const int size)
 
 ~ComplexInventory ()
 
bool addVirtualItem (const Item *const item, int index, const int amount)
 
void setItem (const int index, const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
 
- Public Member Functions inherited from Inventory
 Inventory (const InventoryTypeT type, const int size)
 
virtual ~Inventory ()
 
unsigned getSize () const
 
ItemgetItem (const int index) const
 
ItemfindItem (const int itemId, const ItemColor color) const
 
int addItem (const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
 
void setCards (const int index, const int *const cards, const int size) const
 
void setOptions (const int index, const ItemOptionsList *const options)
 
void setTag (const int index, const int tag)
 
void moveItem (const int index1, const int index2)
 
void removeItem (const int id)
 
void removeItemAt (const int index)
 
bool contains (const Item *const item) const
 
int getFreeSlot () const
 
void clear ()
 
int getNumberOfSlotsUsed () const
 
int getLastUsedSlot () const
 
void addInventoyListener (InventoryListener *const listener)
 
void removeInventoyListener (InventoryListener *const listener)
 
InventoryTypeT getType () const
 
bool isMainInventory () const
 
const ItemfindItemBySprite (std::string spritePath, const GenderT gender, const BeingTypeId race) const
 
std::string getName () const
 
void resize (const unsigned int newSize)
 
int findIndexByTag (const int tag) const
 
ItemfindItemByTag (const int tag) const
 
void virtualRemove (Item *const item, const int amount)
 
void virtualRestore (const Item *const item, const int amount)
 
void restoreVirtuals ()
 

Additional Inherited Members

- Static Public Attributes inherited from Inventory
static const int NO_SLOT_INDEX = -1
 
- Protected Types inherited from Inventory
typedef std::list< InventoryListener * > InventoryListenerList
 
- Protected Member Functions inherited from Inventory
void distributeSlotsChangedEvent ()
 
- Protected Attributes inherited from Inventory
InventoryListenerList mInventoryListeners
 
IntMap mVirtualRemove
 
InventoryTypeT mType
 
unsigned mSize
 
Item ** mItems
 
int mUsed
 

Detailed Description

Definition at line 31 of file complexinventory.h.

Constructor & Destructor Documentation

◆ ComplexInventory()

ComplexInventory::ComplexInventory ( const InventoryTypeT  type,
const int  size 
)

Constructor.

Parameters
sizethe number of items that fit in the inventory

Definition at line 36 of file complexinventory.cpp.

37  :
38  Inventory(type, size1)
39 {
40 }
Inventory(const InventoryTypeT type, const int size)
Definition: inventory.cpp:60

◆ ~ComplexInventory()

ComplexInventory::~ComplexInventory ( )

Destructor.

Definition at line 42 of file complexinventory.cpp.

43 {
44 }

Member Function Documentation

◆ addVirtualItem()

bool ComplexInventory::addVirtualItem ( const Item *const  item,
int  index,
const int  amount 
)
virtual

Reimplemented from Inventory.

Definition at line 46 of file complexinventory.cpp.

49 {
50  if ((item == nullptr) || PlayerInfo::isItemProtected(item->getId()))
51  return false;
52 
53  if (index >= 0 && index < CAST_S32(mSize))
54  {
55  ComplexItem *citem = nullptr;
56  if (mItems[index] != nullptr)
57  {
58  const Item *const item2 = mItems[index];
59  if (item->getId() != item2->getId() ||
60  item->getColor() != item2->getColor())
61  { // not same id or color
62  return false;
63  }
64  citem = dynamic_cast<ComplexItem*>(mItems[index]);
65  if (citem == nullptr)
66  { // if in inventory not complex item, converting it to complex
67  citem = new ComplexItem(item2->getId(),
68  item2->getType(),
69  item2->getQuantity(),
70  item2->getRefine(),
71  item2->getColor(),
72  item2->getIdentified(),
73  item2->getDamaged(),
74  item2->getFavorite(),
77  citem->setTag(item2->getTag());
78  delete mItems[index];
79  mItems[index] = citem;
80  }
81  }
82  else
83  {
84  citem = new ComplexItem(item->getId(),
85  item->getType(),
86  0,
87  item->getRefine(),
88  item->getColor(),
89  item->getIdentified(),
90  item->getDamaged(),
91  item->getFavorite(),
94  mItems[index] = citem;
95  }
96  citem->addChild(item, amount);
97  }
98  else
99  {
100  index = addItem(item->getId(),
101  item->getType(),
102  1,
103  1,
104  item->getColor(),
105  item->getIdentified(),
106  item->getDamaged(),
107  item->getFavorite(),
108  Equipm_false,
110  }
111  if (index == -1)
112  return false;
113 
114  Item *const item2 = getItem(index);
115  if (item2 != nullptr)
116  item2->setTag(item->getInvIndex());
117  return true;
118 }
#define CAST_S32
Definition: cast.h:30
void addChild(const Item *const item, const int amount)
Definition: complexitem.cpp:59
unsigned mSize
Definition: inventory.h:215
Item * getItem(const int index) const
Definition: inventory.cpp:83
int addItem(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: inventory.cpp:115
Item ** mItems
Definition: inventory.h:216
Definition: item.h:50
uint8_t getRefine() const
Definition: item.h:141
int getTag() const
Definition: item.h:231
int getQuantity() const
Definition: item.h:105
int getInvIndex() const
Definition: item.h:165
int getId() const
Definition: item.h:81
Favorite getFavorite() const
Definition: item.h:205
void setTag(const int tag)
Definition: item.h:228
ItemColor getColor() const
Definition: item.h:181
Identified getIdentified() const
Definition: item.h:193
ItemTypeT getType() const
Definition: item.h:225
Damaged getDamaged() const
Definition: item.h:199
const bool Equipm_false
Definition: equipm.h:30
const bool Equipped_false
Definition: equipped.h:30
bool isItemProtected(const int id)
Definition: playerinfo.cpp:515

References ComplexItem::addChild(), Inventory::addItem(), CAST_S32, Equipm_false, Equipped_false, Item::getColor(), Item::getDamaged(), Item::getFavorite(), Item::getId(), Item::getIdentified(), Item::getInvIndex(), Inventory::getItem(), Item::getQuantity(), Item::getRefine(), Item::getTag(), Item::getType(), PlayerInfo::isItemProtected(), Inventory::mItems, Inventory::mSize, and Item::setTag().

Referenced by NpcDialog::action(), and NpcDialog::addCraftItem().

◆ setItem()

void ComplexInventory::setItem ( const int  index,
const int  id,
const ItemTypeT  type,
const int  quantity,
const uint8_t  refine,
const ItemColor  color,
const Identified  identified,
const Damaged  damaged,
const Favorite  favorite,
const Equipm  equipment,
const Equipped  equipped 
)
virtual

Sets the item at the given position.

Reimplemented from Inventory.

Definition at line 120 of file complexinventory.cpp.

131 {
132  if (index < 0 || index >= CAST_S32(mSize))
133  {
134  logger->log("Warning: invalid inventory index: %d", index);
135  return;
136  }
137 
138  const Item *const item1 = mItems[index];
139  if ((item1 == nullptr) && id > 0)
140  {
141  ComplexItem *const item = new ComplexItem(id,
142  type,
143  quantity,
144  refine,
145  color,
146  identified,
147  damaged,
148  favorite,
149  equipment,
150  equipped);
151  item->setInvIndex(index);
152 
153  Item *const item2 = new Item(id,
154  type,
155  quantity,
156  refine,
157  color,
158  identified,
159  damaged,
160  favorite,
161  equipment,
162  equipped);
163  item2->setInvIndex(index);
164  item->addChild(item2, quantity);
165  delete item2;
166 
167  mItems[index] = item;
168  mUsed ++;
170  }
171 }
int mUsed
Definition: inventory.h:217
void distributeSlotsChangedEvent()
Definition: inventory.cpp:312
void setInvIndex(const int index)
Definition: item.h:159
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References ComplexItem::addChild(), CAST_S32, Inventory::distributeSlotsChangedEvent(), MailMessageType::Item, Logger::log(), logger, Inventory::mItems, Inventory::mSize, Inventory::mUsed, and Item::setInvIndex().


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