ManaPlus
Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes
Inventory Class Reference

#include <inventory.h>

Inheritance diagram for Inventory:
ComplexInventory

Public Member Functions

 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)
 
virtual 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)
 
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
 
virtual bool addVirtualItem (const Item *const item, int index, const int amount)
 
void virtualRemove (Item *const item, const int amount)
 
void virtualRestore (const Item *const item, const int amount)
 
void restoreVirtuals ()
 

Static Public Attributes

static const int NO_SLOT_INDEX = -1
 

Protected Types

typedef std::list< InventoryListener * > InventoryListenerList
 

Protected Member Functions

void distributeSlotsChangedEvent ()
 

Protected Attributes

InventoryListenerList mInventoryListeners
 
IntMap mVirtualRemove
 
InventoryTypeT mType
 
unsigned mSize
 
Item ** mItems
 
int mUsed
 

Detailed Description

Definition at line 53 of file inventory.h.

Member Typedef Documentation

◆ InventoryListenerList

typedef std::list<InventoryListener*> Inventory::InventoryListenerList
protected

Definition at line 208 of file inventory.h.

Constructor & Destructor Documentation

◆ Inventory()

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

Constructor.

Parameters
sizethe number of items that fit in the inventory

Definition at line 60 of file inventory.cpp.

61  :
64  mType(type),
65  mSize(size1 == -1 ? CAST_U32(
67  : CAST_U32(size1)),
68  mItems(new Item*[mSize]),
69  mUsed(0)
70 {
71  std::fill_n(mItems, mSize, static_cast<Item*>(nullptr));
72 }
#define CAST_U32
Definition: cast.h:31
unsigned mSize
Definition: inventory.h:215
int mUsed
Definition: inventory.h:217
IntMap mVirtualRemove
Definition: inventory.h:213
InventoryTypeT mType
Definition: inventory.h:214
InventoryListenerList mInventoryListeners
Definition: inventory.h:209
Item ** mItems
Definition: inventory.h:216
Definition: item.h:50
virtual size_t getSize(const InventoryTypeT type) const =0
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89

References mItems, and mSize.

◆ ~Inventory()

Inventory::~Inventory ( )
virtual

Destructor.

Definition at line 74 of file inventory.cpp.

75 {
76  for (unsigned i = 0; i < mSize; i++)
77  delete mItems[i];
78 
79  delete [] mItems;
80  mItems = nullptr;
81 }

References mItems, and mSize.

Member Function Documentation

◆ addInventoyListener()

void Inventory::addInventoyListener ( InventoryListener *const  listener)

◆ addItem()

int Inventory::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 
)

Adds a new item in a free slot.

Definition at line 115 of file inventory.cpp.

125 {
126  const int slot = getFreeSlot();
127  setItem(slot,
128  id,
129  type,
130  quantity,
131  refine,
132  color,
133  identified,
134  damaged,
135  favorite,
136  equipment,
137  equipped);
138  return slot;
139 }
virtual 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)
Definition: inventory.cpp:141
int getFreeSlot() const
Definition: inventory.cpp:282

References getFreeSlot(), and setItem().

Referenced by TradeWindow::addItem(), MailEditWindow::addItem(), TradeWindow::addItem2(), ComplexInventory::addVirtualItem(), addVirtualItem(), EAthena::Mail2Recv::processAddItemResult(), EAthena::Mail2Recv::processReadMail(), and EAthena::MailRecv::processReadMail().

◆ addVirtualItem()

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

Reimplemented in ComplexInventory.

Definition at line 439 of file inventory.cpp.

442 {
443  if ((item != nullptr) && !PlayerInfo::isItemProtected(item->getId()))
444  {
445  if (index >= 0 && index < CAST_S32(mSize))
446  {
447  if (mItems[index] != nullptr)
448  return false;
449  setItem(index,
450  item->getId(),
451  item->getType(),
452  amount,
453  1,
454  item->getColor(),
455  item->getIdentified(),
456  item->getDamaged(),
457  item->getFavorite(),
458  Equipm_false,
460  }
461  else
462  {
463  index = addItem(item->getId(),
464  item->getType(),
465  amount,
466  1,
467  item->getColor(),
468  item->getIdentified(),
469  item->getDamaged(),
470  item->getFavorite(),
471  Equipm_false,
473  }
474  if (index == -1)
475  return false;
476 
477  Item *const item2 = getItem(index);
478  if (item2 != nullptr)
479  item2->setTag(item->getInvIndex());
480  return true;
481  }
482  return false;
483 }
#define CAST_S32
Definition: cast.h:30
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
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 addItem(), CAST_S32, Equipm_false, Equipped_false, Item::getColor(), Item::getDamaged(), Item::getFavorite(), Item::getId(), Item::getIdentified(), Item::getInvIndex(), getItem(), Item::getType(), PlayerInfo::isItemProtected(), mItems, mSize, setItem(), and Item::setTag().

Referenced by NpcDialog::action(), and ItemContainer::mouseReleased().

◆ clear()

void Inventory::clear ( )

◆ contains()

bool Inventory::contains ( const Item *const  item) const

Checks if the given item is in the inventory.

Definition at line 266 of file inventory.cpp.

267 {
268  if (item == nullptr)
269  return false;
270 
271  const int id = item->mId;
272  for (unsigned i = 0; i < mSize; i++)
273  {
274  const Item *const item1 = mItems[i];
275  if ((item1 != nullptr) && item1->mId == id)
276  return true;
277  }
278 
279  return false;
280 }
int mId
Definition: item.h:246

References Item::mId, mItems, and mSize.

◆ distributeSlotsChangedEvent()

void Inventory::distributeSlotsChangedEvent ( )
protected

Definition at line 312 of file inventory.cpp.

313 {
314  FOR_EACH (InventoryListenerList::const_iterator, i, mInventoryListeners)
315  (*i)->slotsChanged(this);
316 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, and mInventoryListeners.

Referenced by moveItem(), removeItemAt(), ComplexInventory::setItem(), and setItem().

◆ findIndexByTag()

int Inventory::findIndexByTag ( const int  tag) const

Definition at line 412 of file inventory.cpp.

413 {
414  for (unsigned i = 0; i < mSize; i++)
415  {
416  const Item *const item = mItems[i];
417  if ((item != nullptr) && item->mTag == tag)
418  return i;
419  }
420 
421  return -1;
422 }
int mTag
Definition: item.h:249

References mItems, mSize, and Item::mTag.

Referenced by EAthena::Mail2Recv::processRemoveItemResult().

◆ findItem()

Item * Inventory::findItem ( const int  itemId,
const ItemColor  color 
) const

Searches for the specified item by it's id.

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

Definition at line 94 of file inventory.cpp.

96 {
97  for (unsigned i = 0; i < mSize; i++)
98  {
99  Item *const item = mItems[i];
100  if ((item != nullptr) && item->mId == itemId)
101  {
102  if (color == ItemColor_zero ||
103  item->mColor == color ||
104  (color == ItemColor_one &&
105  item->mColor <= ItemColor_one))
106  {
107  return item;
108  }
109  }
110  }
111 
112  return nullptr;
113 }
ItemColor mColor
Definition: item.h:247
const ItemColor ItemColor_one
Definition: itemcolor.h:30
const ItemColor ItemColor_zero
Definition: itemcolor.h:30

References ItemColor_one, ItemColor_zero, Item::mColor, Item::mId, mItems, and mSize.

Referenced by EquipmentWindow::action(), ShopWindow::action(), LocalPlayer::changeEquipmentBeforeAttack(), TradeWindow::checkItem(), ItemShortcutContainer::draw(), VirtShortcutContainer::draw(), OutfitWindow::draw(), DropShortcut::dropFirst(), DropShortcut::dropItem(), ItemShortcut::equipItem(), ShopWindow::giveList(), TradeWindow::initTrade(), ItemShortcutContainer::mouseDragged(), VirtShortcutContainer::mouseDragged(), OutfitWindow::mouseDragged(), ItemShortcutContainer::mouseMoved(), VirtShortcutContainer::mouseMoved(), VirtShortcutContainer::mousePressed(), EquipmentWindow::mouseReleased(), EAthena::BuyingStoreRecv::processBuyingStoreItemsList(), ShopWindow::processRequest(), ItemShortcutContainer::safeDraw(), VirtShortcutContainer::safeDraw(), OutfitWindow::safeDraw(), BuyingStoreSellDialog::sellAction(), MailEditWindow::sendMail(), PopupMenu::showItemPopup(), ShopWindow::showList(), ItemShortcut::unequipItem(), ItemShortcut::useItem(), and OutfitWindow::wearOutfit().

◆ findItemBySprite()

const Item * Inventory::findItemBySprite ( std::string  spritePath,
const GenderT  gender,
const BeingTypeId  race 
) const

Definition at line 318 of file inventory.cpp.

321 {
322  spritePath = removeSpriteIndex(spritePath);
323 
324  const std::string spritePathShort = extractNameFromSprite(spritePath);
325  int partialIndex = -1;
326 
327  for (unsigned i = 0; i < mSize; i++)
328  {
329  const Item *const item = mItems[i];
330  if (item != nullptr)
331  {
332  std::string path = item->getInfo().getSprite(gender, race);
333  if (!path.empty())
334  {
335  path = removeSpriteIndex(path);
336  if (spritePath == path)
337  return item;
338 
339  path = extractNameFromSprite(path);
340  if (spritePathShort == path)
341  partialIndex = i;
342  }
343  }
344  }
345  if (partialIndex != -1)
346  return mItems[partialIndex];
347 
348  return nullptr;
349 }
const std::string & getSprite(const GenderT gender, const BeingTypeId race) const
Definition: iteminfo.cpp:100
const ItemInfo & getInfo() const
Definition: item.h:171
std::string removeSpriteIndex(std::string str)
std::string extractNameFromSprite(std::string str)

References extractNameFromSprite(), Item::getInfo(), ItemInfo::getSprite(), mItems, mSize, and removeSpriteIndex().

Referenced by LocalPlayer::imitateOutfit().

◆ findItemByTag()

Item * Inventory::findItemByTag ( const int  tag) const

Definition at line 424 of file inventory.cpp.

425 {
426  for (unsigned i = 0; i < mSize; i++)
427  {
428  Item *const item = mItems[i];
429  if (item != nullptr &&
430  item->mTag == tag)
431  {
432  return item;
433  }
434  }
435 
436  return nullptr;
437 }

References mItems, mSize, and Item::mTag.

Referenced by EAthena::Mail2Recv::processAddItemResult().

◆ getFreeSlot()

int Inventory::getFreeSlot ( ) const

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

Definition at line 282 of file inventory.cpp.

283 {
284  Item *const *const i = std::find_if(mItems,
285  mItems + mSize,
286  std::not1(SlotUsed()));
287  return (i == mItems + mSize) ? -1
288  : CAST_S32(i - mItems);
289 }

References CAST_S32, mItems, and mSize.

Referenced by TradeWindow::action(), and addItem().

◆ getItem()

Item * Inventory::getItem ( const int  index) const

Returns the item at the specified index.

Definition at line 83 of file inventory.cpp.

84 {
85  if (index < 0 || index >= CAST_S32(mSize) || (mItems[index] == nullptr)
86  || mItems[index]->mQuantity <= 0)
87  {
88  return nullptr;
89  }
90 
91  return mItems[index];
92 }

References CAST_S32, mItems, EAthena::TradeRecv::mQuantity, and mSize.

Referenced by NpcDialog::action(), ComplexInventory::addVirtualItem(), addVirtualItem(), TradeWindow::changeQuantity(), Ea::EquipBackend::clear(), InventoryWindow::combineItems(), OutfitWindow::copyFromEquiped(), ItemContainer::draw(), Ea::EquipBackend::getEquipment(), Actions::getItemByInvIndex(), ItemContainer::getSelectedItem(), TradeWindow::increaseQuantity(), ItemContainer::mouseMoved(), ItemContainer::mousePressed(), ItemContainer::mouseReleased(), ShopListBox::mouseReleased(), EAthena::InventoryRecv::processBindItem(), EAthena::BuyingStoreRecv::processBuyingStoreDeleteItem(), EAthena::PetRecv::processEggsList(), EAthena::InventoryRecv::processItemMoveFailed(), Ea::InventoryRecv::processItemUseResponse(), Ea::BuySellRecv::processNpcSell(), EAthena::InventoryRecv::processPlayerCartAdd(), EAthena::InventoryRecv::processPlayerCartRemove(), EAthena::InventoryRecv::processPlayerInsertCard(), EAthena::InventoryRecv::processPlayerInventoryAdd(), TmwAthena::InventoryRecv::processPlayerInventoryAdd(), EAthena::InventoryRecv::processPlayerInventoryRemove(), TmwAthena::InventoryRecv::processPlayerInventoryRemove(), EAthena::InventoryRecv::processPlayerInventoryRemove2(), EAthena::InventoryRecv::processPlayerInventoryUse(), TmwAthena::InventoryRecv::processPlayerInventoryUse(), EAthena::InventoryRecv::processPlayerItemRentalExpired(), EAthena::InventoryRecv::processPlayerRefine(), EAthena::InventoryRecv::processPlayerUseCard(), EAthena::Mail2Recv::processRemoveItemResult(), EAthena::VendingRecv::processReport(), EAthena::TradeRecv::processTradeItemAddResponse(), TmwAthena::TradeRecv::processTradeItemAddResponse(), ItemContainer::safeDraw(), MailEditWindow::sendMail(), Ea::EquipBackend::setEquipment(), ShopWindow::sumAmount(), OutfitWindow::unequipNotInOutfit(), and ItemContainer::updateMatrix().

◆ getLastUsedSlot()

int Inventory::getLastUsedSlot ( ) const

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

Definition at line 291 of file inventory.cpp.

292 {
293  for (int i = mSize - 1; i >= 0; i--)
294  {
295  if (SlotUsed()(mItems[i]))
296  return i;
297  }
298 
299  return -1;
300 }

References mItems, and mSize.

Referenced by ItemContainer::logic(), and MailViewWindow::updateAttachButton().

◆ getName()

std::string Inventory::getName ( ) const

Definition at line 351 of file inventory.cpp.

352 {
353  switch (mType)
354  {
358  default:
359  {
360  // TRANSLATORS: inventory type name
361  return N_("Inventory");
362  }
364  {
365  // TRANSLATORS: inventory type name
366  return N_("Storage");
367  }
368  case InventoryType::Npc:
369  {
370  // TRANSLATORS: inventory type name
371  return N_("Npc");
372  }
373  case InventoryType::Cart:
374  {
375  // TRANSLATORS: inventory type name
376  return N_("Cart");
377  }
380  {
381  // TRANSLATORS: inventory type name
382  return N_("Mail");
383  }
385  {
386  // TRANSLATORS: inventory type name
387  return N_("Craft");
388  }
390  {
391  // TRANSLATORS: inventory type name
392  return N_("Trade");
393  }
394  }
395 }
#define N_(s)
Definition: gettext.h:36

References InventoryType::Cart, InventoryType::Craft, InventoryType::Inventory, InventoryType::MailEdit, InventoryType::MailView, mType, N_, InventoryType::Npc, InventoryType::Storage, InventoryType::Trade, InventoryType::TypeEnd, and InventoryType::Vending.

Referenced by InventoryWindow::InventoryWindow().

◆ getNumberOfSlotsUsed()

int Inventory::getNumberOfSlotsUsed ( ) const
inline

Get the number of slots filled with an item

Definition at line 164 of file inventory.h.

165  { return mUsed; }

References mUsed.

Referenced by MiniStatusWindow::mouseMoved(), InventoryWindow::slotsChanged(), and StatusWindow::updateInvSlotsBar().

◆ getSize()

unsigned Inventory::getSize ( ) const
inline

◆ getType()

InventoryTypeT Inventory::getType ( ) const
inline

◆ isMainInventory()

bool Inventory::isMainInventory ( ) const
inline

◆ moveItem()

void Inventory::moveItem ( const int  index1,
const int  index2 
)

Definition at line 537 of file inventory.cpp.

539 {
540  if (index1 < 0 ||
541  index1 >= CAST_S32(mSize) ||
542  index2 < 0 ||
543  index2 >= CAST_S32(mSize))
544  {
545  return;
546  }
547 
548  Item *const item1 = mItems[index1];
549  Item *const item2 = mItems[index2];
550  if (item1 != nullptr)
551  item1->setInvIndex(index2);
552  if (item2 != nullptr)
553  item2->setInvIndex(index1);
554  mItems[index1] = item2;
555  mItems[index2] = item1;
557 }
void distributeSlotsChangedEvent()
Definition: inventory.cpp:312
void setInvIndex(const int index)
Definition: item.h:159

References CAST_S32, distributeSlotsChangedEvent(), mItems, mSize, and Item::setInvIndex().

Referenced by ItemContainer::mouseReleased().

◆ removeInventoyListener()

void Inventory::removeInventoyListener ( InventoryListener *const  listener)

◆ removeItem()

void Inventory::removeItem ( const int  id)

Remove a item from the inventory.

Definition at line 244 of file inventory.cpp.

245 {
246  for (unsigned i = 0; i < mSize; i++)
247  {
248  const Item *const item = mItems[i];
249  if ((item != nullptr) && item->mId == id)
250  removeItemAt(i);
251  }
252 }

References Item::mId, mItems, mSize, and removeItemAt().

◆ removeItemAt()

void Inventory::removeItemAt ( const int  index)

◆ resize()

void Inventory::resize ( const unsigned int  newSize)

Definition at line 397 of file inventory.cpp.

398 {
399  clear();
400  if (mSize == newSize)
401  return;
402 
403  for (unsigned i = 0; i < mSize; i++)
404  delete mItems[i];
405  delete [] mItems;
406 
407  mSize = newSize;
408  mItems = new Item*[CAST_SIZE(mSize)];
409  std::fill_n(mItems, mSize, static_cast<Item*>(nullptr));
410 }
#define CAST_SIZE
Definition: cast.h:34
void clear()
Definition: inventory.cpp:238

References CAST_SIZE, clear(), mItems, and mSize.

Referenced by NpcDialog::itemCraftRequest(), NpcDialog::itemIndexRequest(), NpcDialog::itemRequest(), EAthena::InventoryRecv::processCartInfo(), and EAthena::InventoryRecv::processInventoryExpansionInfo().

◆ restoreVirtuals()

void Inventory::restoreVirtuals ( )

Definition at line 500 of file inventory.cpp.

501 {
502  const int sz = CAST_S32(mSize);
503 
505  {
506  const int index = (*it).first;
507  if (index < 0 || index >= sz)
508  continue;
509  Item *const item = mItems[index];
510  if (item == nullptr)
511  continue;
512  item->mQuantity += (*it).second;
513  }
514  mVirtualRemove.clear();
515 }
std::map< int, int >::const_iterator IntMapCIter
Definition: being.cpp:150
int mQuantity
Definition: item.h:248

References CAST_S32, FOR_EACH, mItems, Item::mQuantity, mSize, and mVirtualRemove.

Referenced by NpcDialog::restoreVirtuals().

◆ setCards()

void Inventory::setCards ( const int  index,
const int *const  cards,
const int  size 
) const

◆ setItem()

void Inventory::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 in ComplexInventory.

Definition at line 141 of file inventory.cpp.

152 {
153  if (index < 0 || index >= CAST_S32(mSize))
154  {
155  reportAlways("Warning: invalid inventory index: %d",
156  index)
157  return;
158  }
159 
160  Item *const item1 = mItems[index];
161  if ((item1 == nullptr) && id > 0)
162  {
163  Item *const item = new Item(id,
164  type,
165  quantity,
166  refine,
167  color,
168  identified,
169  damaged,
170  favorite,
171  equipment,
172  equipped);
173  item->setInvIndex(index);
174  mItems[index] = item;
175  mUsed++;
177  }
178  else if (id > 0 && (item1 != nullptr))
179  {
180  item1->setId(id, color);
181  item1->setQuantity(quantity);
182  item1->setRefine(refine);
183  item1->setEquipment(equipment);
184  item1->setIdentified(identified);
185  item1->setDamaged(damaged);
186  item1->setFavorite(favorite);
187  }
188  else if (item1 != nullptr)
189  {
190  removeItemAt(index);
191  }
192 }
void setQuantity(const int quantity)
Definition: item.h:93
void setIdentified(const Identified b)
Definition: item.h:190
void setRefine(const uint8_t refine)
Definition: item.h:135
void setDamaged(const Damaged b)
Definition: item.h:196
void setId(const int id, const ItemColor color)
Definition: item.cpp:91
void setEquipment(const Equipm equipment)
Definition: item.h:111
void setFavorite(const Favorite b)
Definition: item.h:202

References CAST_S32, distributeSlotsChangedEvent(), MailMessageType::Item, mItems, mSize, mUsed, removeItemAt(), reportAlways, Item::setDamaged(), Item::setEquipment(), Item::setFavorite(), Item::setId(), Item::setIdentified(), Item::setInvIndex(), Item::setQuantity(), and Item::setRefine().

Referenced by addItem(), addVirtualItem(), ItemContainer::mouseReleased(), EAthena::InventoryRecv::processCartInfo(), EAthena::InventoryRecv::processInventoryEndContinue(), EAthena::InventoryRecv::processPlayerCartAdd(), EAthena::InventoryRecv::processPlayerEquipment(), TmwAthena::InventoryRecv::processPlayerEquipment(), EAthena::InventoryRecv::processPlayerInventory(), TmwAthena::InventoryRecv::processPlayerInventory(), EAthena::InventoryRecv::processPlayerInventoryAdd(), TmwAthena::InventoryRecv::processPlayerInventoryAdd(), EAthena::InventoryRecv::processPlayerStorageAdd(), TmwAthena::InventoryRecv::processPlayerStorageAdd(), and Ea::InventoryRecv::processPlayerStorageStatus().

◆ setOptions()

void Inventory::setOptions ( const int  index,
const ItemOptionsList *const  options 
)

Definition at line 210 of file inventory.cpp.

212 {
213  if (index < 0 || index >= CAST_S32(mSize))
214  {
215  reportAlways("Warning: invalid inventory index: %d",
216  index)
217  return;
218  }
219  Item *const item1 = mItems[index];
220  if (item1 != nullptr)
221  item1->setOptions(options);
222 }
void setOptions(const ItemOptionsList *const options)
Definition: item.cpp:189

References CAST_S32, mItems, mSize, reportAlways, and Item::setOptions().

Referenced by TradeWindow::addItem2(), EAthena::Mail2Recv::processAddItemResult(), EAthena::InventoryRecv::processInventoryEndContinue(), EAthena::InventoryRecv::processPlayerCartAdd(), EAthena::InventoryRecv::processPlayerEquipment(), EAthena::InventoryRecv::processPlayerInventoryAdd(), EAthena::InventoryRecv::processPlayerStorageAdd(), and EAthena::Mail2Recv::processReadMail().

◆ setTag()

void Inventory::setTag ( const int  index,
const int  tag 
)

Definition at line 224 of file inventory.cpp.

226 {
227  if (index < 0 || index >= CAST_S32(mSize))
228  {
229  reportAlways("Warning: invalid inventory index: %d",
230  index)
231  return;
232  }
233  Item *const item1 = mItems[index];
234  if (item1 != nullptr)
235  item1->setTag(tag);
236 }

References CAST_S32, mItems, mSize, reportAlways, and Item::setTag().

Referenced by EAthena::Mail2Recv::processAddItemResult().

◆ virtualRemove()

void Inventory::virtualRemove ( Item *const  item,
const int  amount 
)

Definition at line 485 of file inventory.cpp.

487 {
488  if ((item == nullptr) || item->mQuantity < amount)
489  return;
490 
491  const int index = item->getInvIndex();
492  const IntMapCIter it = mVirtualRemove.find(index);
493  if (it == mVirtualRemove.end())
494  mVirtualRemove[index] = amount;
495  else
496  mVirtualRemove[index] += amount;
497  item->mQuantity -= amount;
498 }

References Item::getInvIndex(), Item::mQuantity, and mVirtualRemove.

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

◆ virtualRestore()

void Inventory::virtualRestore ( const Item *const  item,
const int  amount 
)

Definition at line 517 of file inventory.cpp.

519 {
520  const int index = item->getTag();
521  const IntMapCIter it = mVirtualRemove.find(index);
522  if (it != mVirtualRemove.end())
523  {
524  mVirtualRemove[index] -= amount;
525  if (mVirtualRemove[index] < 0)
526  mVirtualRemove.erase(index);
527  if (index < 0 ||
528  index >= CAST_S32(mSize) ||
529  mItems[index] == nullptr)
530  {
531  return;
532  }
533  mItems[index]->mQuantity += amount;
534  }
535 }
int getTag() const
Definition: item.h:231

References CAST_S32, Item::getTag(), mItems, Item::mQuantity, mSize, and mVirtualRemove.

Referenced by ItemContainer::mouseReleased().

Field Documentation

◆ mInventoryListeners

InventoryListenerList Inventory::mInventoryListeners
protected

◆ mItems

Item** Inventory::mItems
protected

◆ mSize

unsigned Inventory::mSize
protected

◆ mType

InventoryTypeT Inventory::mType
protected

Definition at line 214 of file inventory.h.

Referenced by getName(), getType(), and isMainInventory().

◆ mUsed

int Inventory::mUsed
protected

THe number of slots in use

Definition at line 217 of file inventory.h.

Referenced by getNumberOfSlotsUsed(), removeItemAt(), ComplexInventory::setItem(), and setItem().

◆ mVirtualRemove

IntMap Inventory::mVirtualRemove
protected

Definition at line 213 of file inventory.h.

Referenced by restoreVirtuals(), virtualRemove(), and virtualRestore().

◆ NO_SLOT_INDEX

const int Inventory::NO_SLOT_INDEX = -1
static

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