ManaPlus
Public Member Functions | Protected Attributes
ComplexItem Class Reference

#include <complexitem.h>

Inheritance diagram for ComplexItem:
Item

Public Member Functions

 ComplexItem (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 ~ComplexItem ()
 
void addChild (const Item *const item, const int amount)
 
const std::vector< Item * > & getChilds () const
 
- Public Member Functions inherited from 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)
 
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 ()
 

Protected Attributes

std::vector< Item * > mChildItems
 
- Protected Attributes inherited from Item
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
 

Additional Inherited Members

- Static Public Member Functions inherited from Item
static ImagegetImage (const int id, const ItemColor color)
 
static bool isItem (const int id)
 
- Data Fields inherited from Item
int mId
 
ItemColor mColor
 
int mQuantity
 
int mTag
 

Detailed Description

Represents one or more instances of a certain item type.

Definition at line 31 of file complexitem.h.

Constructor & Destructor Documentation

◆ ComplexItem()

ComplexItem::ComplexItem ( 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 28 of file complexitem.cpp.

37  :
38  Item(id,
39  type,
40  quantity,
41  refine,
42  color,
43  identified,
44  damaged,
45  favorite,
46  equipment,
47  equipped),
48  mChildItems()
49 {
50 }

Referenced by addChild().

◆ ~ComplexItem()

ComplexItem::~ComplexItem ( )
virtual

Destructor.

Definition at line 52 of file complexitem.cpp.

53 {
55  mChildItems.clear();
56 }

References delete_all(), and mChildItems.

Member Function Documentation

◆ addChild()

void ComplexItem::addChild ( const Item *const  item,
const int  amount 
)

Definition at line 58 of file complexitem.cpp.

60 {
61  if (item == nullptr)
62  return;
63  increaseQuantity(amount);
64  Item *child = nullptr;
65  FOR_EACH (STD_VECTOR<Item*>::iterator, it, mChildItems)
66  {
67  Item *const item1 = *it;
68  if (item1->getId() == item->getId() &&
69  item1->getInvIndex() == item->getInvIndex() &&
70  item1->getTag() == item->getTag())
71  {
72  child = item1;
73  break;
74  }
75  }
76  if (child != nullptr)
77  {
78  child->increaseQuantity(amount);
79  }
80  else
81  {
82  child = new ComplexItem(item->getId(),
83  item->getType(),
84  amount,
85  item->getRefine(),
86  item->getColor(),
87  item->getIdentified(),
88  item->getDamaged(),
89  item->getFavorite(),
92  child->setTag(item->getTag());
93  child->setInvIndex(item->getInvIndex());
94  mChildItems.push_back(child);
95  }
96 }

References ComplexItem(), Equipm_false, Equipped_false, FOR_EACH, Item::getColor(), Item::getDamaged(), Item::getFavorite(), Item::getId(), Item::getIdentified(), Item::getInvIndex(), Item::getRefine(), Item::getTag(), Item::getType(), Item::increaseQuantity(), mChildItems, Item::setInvIndex(), and Item::setTag().

Referenced by ComplexInventory::addVirtualItem(), and ComplexInventory::setItem().

◆ getChilds()

const std::vector<Item*>& ComplexItem::getChilds ( ) const
inline

Definition at line 58 of file complexitem.h.

59  { return mChildItems; }

References mChildItems.

Referenced by NpcDialog::complexItemToStr().

Field Documentation

◆ mChildItems

std::vector<Item*> ComplexItem::mChildItems
protected

Definition at line 62 of file complexitem.h.

Referenced by addChild(), getChilds(), and ~ComplexItem().


The documentation for this class was generated from the following files:
Item
Definition: item.h:48
Item::getIdentified
Identified getIdentified() const
Definition: item.h:192
Equipm_false
const bool Equipm_false
Definition: equipm.h:29
Item::setTag
void setTag(const int tag)
Definition: item.h:227
Item::getColor
ItemColor getColor() const
Definition: item.h:180
ComplexItem::mChildItems
std::vector< Item * > mChildItems
Definition: complexitem.h:62
Item::setInvIndex
void setInvIndex(const int index)
Definition: item.h:158
Item::getId
int getId() const
Definition: item.h:80
ComplexItem::ComplexItem
ComplexItem(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: complexitem.cpp:28
Item::increaseQuantity
void increaseQuantity(const int amount)
Definition: item.h:98
Item::getFavorite
Favorite getFavorite() const
Definition: item.h:204
Item::getType
ItemTypeT getType() const
Definition: item.h:224
Item::getRefine
uint8_t getRefine() const
Definition: item.h:140
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)
Definition: item.cpp:45
Item::getTag
int getTag() const
Definition: item.h:230
Item::getDamaged
Damaged getDamaged() const
Definition: item.h:198
Item::getInvIndex
int getInvIndex() const
Definition: item.h:164
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
Equipped_false
const bool Equipped_false
Definition: equipped.h:29
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24