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 32 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 29 of file complexitem.cpp.

38  :
39  Item(id,
40  type,
41  quantity,
42  refine,
43  color,
44  identified,
45  damaged,
46  favorite,
47  equipment,
48  equipped),
49  mChildItems()
50 {
51 }
std::vector< Item * > mChildItems
Definition: complexitem.h:63
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:46

Referenced by addChild().

◆ ~ComplexItem()

ComplexItem::~ComplexItem ( )
virtual

Destructor.

Definition at line 53 of file complexitem.cpp.

54 {
56  mChildItems.clear();
57 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), and mChildItems.

Member Function Documentation

◆ addChild()

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

Definition at line 59 of file complexitem.cpp.

61 {
62  if (item == nullptr)
63  return;
64  increaseQuantity(amount);
65  Item *child = nullptr;
66  FOR_EACH (STD_VECTOR<Item*>::iterator, it, mChildItems)
67  {
68  Item *const item1 = *it;
69  if (item1->getId() == item->getId() &&
70  item1->getInvIndex() == item->getInvIndex() &&
71  item1->getTag() == item->getTag())
72  {
73  child = item1;
74  break;
75  }
76  }
77  if (child != nullptr)
78  {
79  child->increaseQuantity(amount);
80  }
81  else
82  {
83  child = new ComplexItem(item->getId(),
84  item->getType(),
85  amount,
86  item->getRefine(),
87  item->getColor(),
88  item->getIdentified(),
89  item->getDamaged(),
90  item->getFavorite(),
93  child->setTag(item->getTag());
94  child->setInvIndex(item->getInvIndex());
95  mChildItems.push_back(child);
96  }
97 }
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:29
Definition: item.h:50
uint8_t getRefine() const
Definition: item.h:141
int getTag() const
Definition: item.h:231
void setInvIndex(const int index)
Definition: item.h:159
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
void increaseQuantity(const int amount)
Definition: item.h:99
const bool Equipm_false
Definition: equipm.h:30
const bool Equipped_false
Definition: equipped.h:30
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

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 59 of file complexitem.h.

60  { return mChildItems; }

References mChildItems.

Referenced by NpcDialog::complexItemToStr().

Field Documentation

◆ mChildItems

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

Definition at line 63 of file complexitem.h.

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


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