ManaPlus
Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes
Item Class Reference

#include <item.h>

Inheritance diagram for Item:
ComplexItem ShopItem

Public Member Functions

 Item (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 ~Item ()
 
void setId (const int id, const ItemColor color)
 
int getId () const
 
ImagegetImage () const
 
void setQuantity (const int quantity)
 
void increaseQuantity (const int amount)
 
int getQuantity () const
 
void setEquipment (const Equipm equipment)
 
Equipm isEquipment () const
 
void setEquipped (const Equipped equipped)
 
Equipped isEquipped () const
 
void setRefine (const uint8_t refine)
 
uint8_t getRefine () const
 
void setInEquipment (const bool inEquipment)
 
bool isInEquipment () const
 
void setInvIndex (const int index)
 
int getInvIndex () const
 
const ItemInfogetInfo () const
 
std::string getName () const
 
bool isHaveTag (const int tagId) const
 
ItemColor getColor () const
 
void setColor (const ItemColor color)
 
const std::string & getDescription () const
 
void setIdentified (const Identified b)
 
Identified getIdentified () const
 
void setDamaged (const Damaged b)
 
Damaged getDamaged () const
 
void setFavorite (const Favorite b)
 
Favorite getFavorite () const
 
void setCard (const int index, const int id)
 
int getCard (const int index) const
 
void setCards (const int *const cards, const int size)
 
const int * getCards () const
 
void setOptions (const ItemOptionsList *const options)
 
const ItemOptionsListgetOptions () const
 
void setType (const ItemTypeT type)
 
ItemTypeT getType () const
 
void setTag (const int tag)
 
int getTag () const
 
void addCard (const int card)
 
void updateColor ()
 

Static Public Member Functions

static ImagegetImage (const int id, const ItemColor color)
 
static bool isItem (const int id)
 

Data Fields

int mId
 
ItemColor mColor
 
int mQuantity
 
int mTag
 

Protected Attributes

ImagemImage
 
std::string mDescription
 
std::map< int, int > mTags
 
int mCards [4]
 
const ItemOptionsListmOptions
 
uint8_t mRefine
 
int mInvIndex
 
ItemTypeT mType
 
Equipm mEquipment
 
Equipped mEquipped
 
bool mInEquipment
 
Identified mIdentified
 
Damaged mDamaged
 
Favorite mFavorite
 

Detailed Description

Represents one or more instances of a certain item type.

Definition at line 49 of file item.h.

Constructor & Destructor Documentation

◆ Item()

Item::Item ( 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 
)

Constructor.

Definition at line 46 of file item.cpp.

55  :
56  mId(0),
58  mQuantity(quantity),
59  mTag(0),
60  mImage(nullptr),
61  mDescription(),
62  mTags(),
63  mCards(),
64  mOptions(nullptr),
65  mRefine(refine),
66  mInvIndex(0),
67  mType(type),
68  mEquipment(equipment),
69  mEquipped(equipped),
70  mInEquipment(false),
71  mIdentified(identified),
72  mDamaged(damaged),
73  mFavorite(favorite)
74 {
75  setId(id, color);
76  for (int f = 0; f < maxCards; f ++)
77  mCards[f] = 0;
78 }
#define maxCards
Definition: cards.h:25
Identified mIdentified
Definition: item.h:263
int mQuantity
Definition: item.h:248
Damaged mDamaged
Definition: item.h:264
int mInvIndex
Definition: item.h:258
int mTag
Definition: item.h:249
ItemColor mColor
Definition: item.h:247
const ItemOptionsList * mOptions
Definition: item.h:256
uint8_t mRefine
Definition: item.h:257
int mId
Definition: item.h:246
void setId(const int id, const ItemColor color)
Definition: item.cpp:91
bool mInEquipment
Definition: item.h:262
Equipm mEquipment
Definition: item.h:260
ItemTypeT mType
Definition: item.h:259
Equipped mEquipped
Definition: item.h:261
Image * mImage
Definition: item.h:252
std::map< int, int > mTags
Definition: item.h:254
std::string mDescription
Definition: item.h:253
Favorite mFavorite
Definition: item.h:265
int mCards[4]
Definition: item.h:255
const ItemColor ItemColor_zero
Definition: itemcolor.h:30

References maxCards, mCards, and setId().

◆ ~Item()

Item::~Item ( )
virtual

Destructor.

Definition at line 80 of file item.cpp.

81 {
82  if (mImage != nullptr)
83  {
84  mImage->decRef();
85  mImage = nullptr;
86  }
88  dragDrop.clearItem(this);
89 }
void clearItem(const Item *const item)
Definition: dragdrop.h:228
#define delete2(var)
Definition: delete2.h:25
DragDrop dragDrop(0, DragDropSource::Empty)

References DragDrop::clearItem(), delete2, dragDrop, mImage, and mOptions.

Member Function Documentation

◆ addCard()

void Item::addCard ( const int  card)

Definition at line 177 of file item.cpp.

178 {
179  for (int f = 0; f < maxCards; f ++)
180  {
181  if (mCards[f] == 0)
182  {
183  mCards[f] = card;
184  return;
185  }
186  }
187 }

References maxCards, and mCards.

Referenced by EAthena::InventoryRecv::processPlayerInsertCard().

◆ getCard()

int Item::getCard ( const int  index) const

Definition at line 159 of file item.cpp.

160 {
161  if (index < 0 || index >= maxCards)
162  return 0;
163  return mCards[index];
164 }

References maxCards, and mCards.

Referenced by PopupMenu::showDropPopup(), PopupMenu::showItemPopup(), PopupMenu::showPopup(), and PopupMenu::showUndressPopup().

◆ getCards()

const int* Item::getCards ( ) const
inline

◆ getColor()

ItemColor Item::getColor ( ) const
inline

◆ getDamaged()

Damaged Item::getDamaged ( ) const
inline

◆ getDescription()

const std::string& Item::getDescription ( ) const
inline

Definition at line 187 of file item.h.

188  { return mDescription; }

References mDescription.

◆ getFavorite()

Favorite Item::getFavorite ( ) const
inline

◆ getId()

int Item::getId ( ) const
inline

Returns the item id.

Definition at line 81 of file item.h.

82  { return mId; }

References mId.

Referenced by BuyDialog::action(), InventoryWindow::action(), NpcDialog::action(), ShopWindow::action(), TradeWindow::action(), ShopWindow::addBuyItem(), ComplexItem::addChild(), MailEditWindow::addItem(), SellDialog::addItem(), ShopWindow::addSellItem(), ComplexInventory::addVirtualItem(), Inventory::addVirtualItem(), ShopWindow::announce(), EAthena::CashShopHandler::buyItems(), EAthena::BarterHandler::buyItems(), EAthena::MarketHandler::buyItems(), EAthena::NpcHandler::buyItems(), TradeWindow::checkItem(), OutfitWindow::copyFromEquiped(), EAthena::BuyingStoreHandler::create(), DragDrop::dragItem(), ItemContainer::draw(), ShopListBox::draw(), PlayerInfo::dropItem(), EAthena::PetHandler::evolution(), ShopItems::findItem(), ShopWindow::findShopItem(), ShopWindow::giveList(), TradeWindow::initTrade(), InventoryWindow::mouseClicked(), ItemContainer::mousePressed(), ItemContainer::mouseReleased(), ItemSoundManager::playSfx(), EAthena::InventoryRecv::processPlayerCartAdd(), EAthena::InventoryRecv::processPlayerInsertCard(), EAthena::InventoryRecv::processPlayerInventoryAdd(), TmwAthena::InventoryRecv::processPlayerInventoryAdd(), ShopWindow::processRequest(), EAthena::TradeRecv::processTradeItemAddResponse(), TmwAthena::TradeRecv::processTradeItemAddResponse(), EAthena::RefineHandler::refineItem(), ItemContainer::safeDraw(), ShopWindow::saveList(), DragDrop::select(), EAthena::BuyingStoreHandler::sell(), BuyingStoreSellDialog::sellAction(), NpcSellDialog::sellAction(), ShopSellDialog::sellAction(), TmwAthena::BuySellHandler::sendBuyRequest(), MailEditWindow::sendMail(), TmwAthena::BuySellHandler::sendSellRequest(), ItemPopup::setItem(), ItemShortcut::setItemSelected(), ShortcutBase::setItemSelected(), PopupMenu::showDropPopup(), PopupMenu::showItemPopup(), PopupMenu::showPopup(), PopupMenu::showUndressPopup(), ShopWindow::sumAmount(), OutfitWindow::unequipNotInOutfit(), ItemContainer::updateMatrix(), PlayerInfo::useEquipItem(), PlayerInfo::useEquipItem2(), EAthena::InventoryHandler::useItem(), and TmwAthena::InventoryHandler::useItem().

◆ getIdentified()

Identified Item::getIdentified ( ) const
inline

◆ getImage() [1/2]

Image* Item::getImage ( ) const
inline

◆ getImage() [2/2]

Image * Item::getImage ( const int  id,
const ItemColor  color 
)
static

Definition at line 127 of file item.cpp.

129 {
130  const ItemInfo &info = ItemDB::get(id);
132  "itemIcons"), info.getDisplay().image),
133  info.getDyeIconColorsString(color)));
134 
135  if (image == nullptr)
136  image = Theme::getImageFromTheme("unknown-item.png");
137  return image;
138 }
std::string getStringValue(const std::string &key) const
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:655
Configuration paths
bool info(InputEvent &event)
Definition: commands.cpp:57
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:86
std::string combineDye2(std::string file, const std::string &dye)
std::string pathJoin(std::string str1, const std::string &str2)

References combineDye2(), ItemDB::get(), Loader::getImage(), Theme::getImageFromTheme(), Configuration::getStringValue(), Actions::info(), pathJoin(), and paths.

◆ getInfo()

const ItemInfo& Item::getInfo ( ) const
inline

◆ getInvIndex()

int Item::getInvIndex ( ) const
inline

Returns the inventory index of this item.

Definition at line 165 of file item.h.

166  { return mInvIndex; }

References mInvIndex.

Referenced by InventoryWindow::action(), ShopWindow::action(), ComplexItem::addChild(), EAthena::RefineHandler::addItem(), EAthena::Mail2Handler::addItem(), EAthena::TradeHandler::addItem(), TmwAthena::TradeHandler::addItem(), SellDialog::addItem(), ComplexInventory::addVirtualItem(), Inventory::addVirtualItem(), EAthena::VendingHandler::buyItems(), InventoryWindow::combineItems(), NpcDialog::complexItemToStr(), EAthena::VendingHandler::createShop(), EAthena::InventoryHandler::dropItem(), TmwAthena::InventoryHandler::dropItem(), EAthena::InventoryHandler::equipItem(), TmwAthena::InventoryHandler::equipItem(), EAthena::InventoryHandler::favoriteItem(), ItemAmountWindow::finish(), EAthena::InventoryHandler::identifyItem(), InventoryWindow::mouseClicked(), ItemContainer::mouseReleased(), anonymous_namespace{itemcontainer.cpp}::SortItemAlphaFunctor::operator()(), EAthena::RefineHandler::refineItem(), EAthena::InventoryHandler::selectEgg(), EAthena::BuyingStoreHandler::sell(), InsertCardDialog::sellAction(), MailEditWindow::sendMail(), EAthena::AuctionHandler::setItem(), PopupMenu::showDropPopup(), PopupMenu::showItemPopup(), PopupMenu::showPopup(), PopupMenu::showUndressPopup(), EAthena::InventoryHandler::unequipItem(), TmwAthena::InventoryHandler::unequipItem(), EAthena::InventoryHandler::useCard(), EAthena::InventoryHandler::useItem(), TmwAthena::InventoryHandler::useItem(), and Inventory::virtualRemove().

◆ getName()

std::string Item::getName ( ) const

◆ getOptions()

const ItemOptionsList* Item::getOptions ( ) const
inline

Definition at line 219 of file item.h.

220  { return mOptions; }

References mOptions.

Referenced by EAthena::TradeRecv::processTradeItemAddResponse(), and ItemPopup::setItem().

◆ getQuantity()

int Item::getQuantity ( ) const
inline

Returns the number of items.

Definition at line 105 of file item.h.

106  { return mQuantity; }

References mQuantity.

Referenced by InventoryWindow::action(), ItemAmountWindow::action(), ShopWindow::action(), PopupMenu::addDrop(), SellDialog::addItem(), PopupMenu::addItemMenu(), ComplexInventory::addVirtualItem(), ShopWindow::announce(), TradeWindow::checkItem(), NpcDialog::complexItemToStr(), EAthena::BuyingStoreHandler::create(), EAthena::VendingHandler::createShop(), ItemContainer::draw(), ItemShortcutContainer::draw(), VirtShortcutContainer::draw(), EquipmentWindow::draw(), DropShortcut::dropFirst(), DropShortcut::dropItem(), ItemShortcut::equipItem(), ShopWindow::findShopItem(), Actions::getAmountFromEvent(), ShopWindow::giveList(), TradeWindow::initTrade(), ItemAmountWindow::ItemAmountWindow(), InventoryWindow::mouseClicked(), ItemContainer::mouseReleased(), InventoryWindow::moveItemToCraft(), EAthena::InventoryRecv::processPlayerCartAdd(), EAthena::InventoryRecv::processPlayerInsertCard(), EAthena::InventoryRecv::processPlayerInventoryAdd(), TmwAthena::InventoryRecv::processPlayerInventoryAdd(), ShopWindow::processRequest(), ItemContainer::safeDraw(), ItemShortcutContainer::safeDraw(), VirtShortcutContainer::safeDraw(), EquipmentWindow::safeDraw(), ShopWindow::saveList(), TmwAthena::BuySellHandler::sendBuyRequest(), MailEditWindow::sendMail(), TmwAthena::BuySellHandler::sendSellRequest(), ShopWindow::showList(), PopupMenu::showPopup(), ItemAmountWindow::showWindow(), ShopWindow::startTrade(), ShopWindow::sumAmount(), ItemShortcut::unequipItem(), StatusWindow::updateArrowsBar(), InventoryWindow::updateButtons(), SellDialog::updateButtonsAndLabels(), BuyDialog::updateButtonsAndLabels(), InventoryWindow::updateDropButton(), ItemContainer::updateMatrix(), ItemShortcut::useItem(), InventoryWindow::valueChanged(), and OutfitWindow::wearOutfit().

◆ getRefine()

uint8_t Item::getRefine ( ) const
inline

◆ getTag()

int Item::getTag ( ) const
inline

◆ getType()

ItemTypeT Item::getType ( ) const
inline

◆ increaseQuantity()

void Item::increaseQuantity ( const int  amount)
inline

◆ isEquipment()

Equipm Item::isEquipment ( ) const
inline

◆ isEquipped()

Equipped Item::isEquipped ( ) const
inline

◆ isHaveTag()

bool Item::isHaveTag ( const int  tagId) const

Definition at line 119 of file item.cpp.

120 {
121  const std::map <int, int>::const_iterator it = mTags.find(tagId);
122  if (it == mTags.end())
123  return false;
124  return (*it).second > 0;
125 }

References mTags.

Referenced by ItemContainer::updateMatrix().

◆ isInEquipment()

bool Item::isInEquipment ( ) const
inline

Returns whether this item is in equipment.

Definition at line 153 of file item.h.

154  { return mInEquipment; }

References mInEquipment.

◆ isItem()

static bool Item::isItem ( const int  id)
inlinestatic

Definition at line 238 of file item.h.

239  {
240  return id != 0 &&
241  id != CARD0_FORGE &&
242  id != CARD0_CREATE &&
243  id != CARD0_PET;
244  }
#define CARD0_CREATE
Definition: cards.h:29
#define CARD0_PET
Definition: cards.h:30
#define CARD0_FORGE
Definition: cards.h:28

References CARD0_CREATE, CARD0_FORGE, and CARD0_PET.

Referenced by Being::addItemParticlesCards().

◆ setCard()

void Item::setCard ( const int  index,
const int  id 
)

Definition at line 152 of file item.cpp.

153 {
154  if (index < 0 || index >= maxCards)
155  return;
156  mCards[index] = id;
157 }

References maxCards, and mCards.

◆ setCards()

void Item::setCards ( const int *const  cards,
const int  size 
)

Definition at line 166 of file item.cpp.

167 {
168  if (size < 0 || (cards == nullptr))
169  return;
170  int sz = size;
171  if (sz > maxCards)
172  sz = maxCards;
173  for (int f = 0; f < sz; f ++)
174  mCards[f] = cards[f];
175 }
int size()
Definition: emotedb.cpp:306

References maxCards, mCards, and EmoteDB::size().

Referenced by BeingEquipBackend::BeingEquipBackend(), and Inventory::setCards().

◆ setColor()

void Item::setColor ( const ItemColor  color)
inline

Definition at line 184 of file item.h.

185  { mColor = color; }

References mColor.

◆ setDamaged()

void Item::setDamaged ( const Damaged  b)
inline

Definition at line 196 of file item.h.

197  { mDamaged = b; }

References mDamaged.

Referenced by Inventory::setItem().

◆ setEquipment()

void Item::setEquipment ( const Equipm  equipment)
inline

Sets whether this item is considered equipment.

Definition at line 111 of file item.h.

112  { mEquipment = equipment; }

References mEquipment.

Referenced by Inventory::setItem().

◆ setEquipped()

void Item::setEquipped ( const Equipped  equipped)
inline

Sets whether this item is equipped.

Definition at line 123 of file item.h.

124  { mEquipped = equipped; }

References mEquipped.

Referenced by Ea::EquipBackend::clear(), and Ea::EquipBackend::setEquipment().

◆ setFavorite()

void Item::setFavorite ( const Favorite  b)
inline

Definition at line 202 of file item.h.

203  { mFavorite = b; }

References mFavorite.

Referenced by Inventory::setItem().

◆ setId()

void Item::setId ( const int  id,
const ItemColor  color 
)

Sets the item id, color the item type.

Definition at line 91 of file item.cpp.

93 {
94  mId = id;
95  mColor = color;
96 
97  // Types 0 and 1 are not equippable items.
99  >= 2, Equipm);
100 
101  if (mImage != nullptr)
102  mImage->decRef();
103 
104  const ItemInfo &info = getInfo();
105  mTags = info.getTags();
106 
107  const std::string dye = combineDye2(pathJoin(
108  paths.getStringValue("itemIcons"), info.getDisplay().image),
109  info.getDyeIconColorsString(color));
110  mImage = Loader::getImage(dye);
111 
112  if (mImage == nullptr)
113  {
114  mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile",
115  "unknown-item.png"));
116  }
117 }
#define fromBool(val, name)
Definition: booldefines.h:49
#define CAST_S32
Definition: cast.h:30
std::string getValue(const std::string &key, const std::string &deflt) const
ItemTypeT getType() const
Definition: item.h:225
const ItemInfo & getInfo() const
Definition: item.h:171
bool Equipm
Definition: equipm.h:30

References CAST_S32, combineDye2(), fromBool, Loader::getImage(), Theme::getImageFromTheme(), getInfo(), Configuration::getStringValue(), getType(), ConfigurationObject::getValue(), Actions::info(), mColor, mEquipment, mId, mImage, mTags, pathJoin(), and paths.

Referenced by Item(), Inventory::setItem(), and updateColor().

◆ setIdentified()

void Item::setIdentified ( const Identified  b)
inline

Definition at line 190 of file item.h.

191  { mIdentified = b; }

References mIdentified.

Referenced by Inventory::setItem().

◆ setInEquipment()

void Item::setInEquipment ( const bool  inEquipment)
inline

Sets whether this item is in equipment.

Definition at line 147 of file item.h.

148  { mInEquipment = inEquipment; }

References mInEquipment.

◆ setInvIndex()

void Item::setInvIndex ( const int  index)
inline

Sets the inventory index of this item.

Definition at line 159 of file item.h.

160  { mInvIndex = index; }

References mInvIndex.

Referenced by ShopWindow::action(), ComplexItem::addChild(), Inventory::moveItem(), EAthena::VendingRecv::processItemsList(), ComplexInventory::setItem(), Inventory::setItem(), and ShopItem::ShopItem().

◆ setOptions()

void Item::setOptions ( const ItemOptionsList *const  options)

Definition at line 189 of file item.cpp.

190 {
192  mOptions = ItemOptionsList::copy(options);
193 }
static ItemOptionsList * copy(const ItemOptionsList *const options0)

References ItemOptionsList::copy(), delete2, and mOptions.

Referenced by EAthena::VendingRecv::processItemsList(), and Inventory::setOptions().

◆ setQuantity()

void Item::setQuantity ( const int  quantity)
inline

Sets the number of items.

Definition at line 93 of file item.h.

94  { mQuantity = quantity; }

References mQuantity.

Referenced by ShopWindow::action(), TradeWindow::changeQuantity(), and Inventory::setItem().

◆ setRefine()

void Item::setRefine ( const uint8_t  refine)
inline

Sets this item refine level.

Definition at line 135 of file item.h.

136  { mRefine = refine; }

References mRefine.

Referenced by Inventory::setItem().

◆ setTag()

void Item::setTag ( const int  tag)
inline

◆ setType()

void Item::setType ( const ItemTypeT  type)
inline

Definition at line 222 of file item.h.

223  { mType = type; }

References mType.

◆ updateColor()

void Item::updateColor ( )

Field Documentation

◆ mCards

int Item::mCards[4]
protected

Definition at line 255 of file item.h.

Referenced by addCard(), getCard(), getCards(), Item(), setCard(), setCards(), and updateColor().

◆ mColor

ItemColor Item::mColor

◆ mDamaged

Damaged Item::mDamaged
protected

Definition at line 264 of file item.h.

Referenced by getDamaged(), and setDamaged().

◆ mDescription

std::string Item::mDescription
protected

Definition at line 253 of file item.h.

Referenced by getDescription().

◆ mEquipment

Equipm Item::mEquipment
protected

Item is equipment.

Definition at line 260 of file item.h.

Referenced by isEquipment(), setEquipment(), and setId().

◆ mEquipped

Equipped Item::mEquipped
protected

Item is equipped.

Definition at line 261 of file item.h.

Referenced by isEquipped(), and setEquipped().

◆ mFavorite

Favorite Item::mFavorite
protected

Definition at line 265 of file item.h.

Referenced by getFavorite(), and setFavorite().

◆ mId

int Item::mId

◆ mIdentified

Identified Item::mIdentified
protected

Definition at line 263 of file item.h.

Referenced by getIdentified(), and setIdentified().

◆ mImage

Image* Item::mImage
protected

Item image.

Definition at line 252 of file item.h.

Referenced by getImage(), setId(), and ~Item().

◆ mInEquipment

bool Item::mInEquipment
protected

Item is in equipment

Definition at line 262 of file item.h.

Referenced by isInEquipment(), and setInEquipment().

◆ mInvIndex

int Item::mInvIndex
protected

Inventory index.

Definition at line 258 of file item.h.

Referenced by ShopItem::getCurrentInvIndex(), getInvIndex(), and setInvIndex().

◆ mOptions

const ItemOptionsList* Item::mOptions
protected

Definition at line 256 of file item.h.

Referenced by getOptions(), setOptions(), and ~Item().

◆ mQuantity

int Item::mQuantity

◆ mRefine

uint8_t Item::mRefine
protected

Item refine level.

Definition at line 257 of file item.h.

Referenced by getRefine(), and setRefine().

◆ mTag

int Item::mTag

Definition at line 249 of file item.h.

Referenced by Inventory::findIndexByTag(), Inventory::findItemByTag(), getTag(), and setTag().

◆ mTags

std::map<int, int> Item::mTags
protected

Definition at line 254 of file item.h.

Referenced by isHaveTag(), and setId().

◆ mType

ItemTypeT Item::mType
protected

Item type.

Definition at line 259 of file item.h.

Referenced by getType(), and setType().


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