Mana
|
Represents an item in a shop inventory. More...
#include <shopitem.h>
Classes | |
struct | DuplicateItem |
Struct to keep track of duplicates. More... | |
Public Member Functions | |
ShopItem (int inventoryIndex, int id, int quantity, int price) | |
Constructor. | |
~ShopItem () override | |
void | addDuplicate (int inventoryIndex, int quantity) |
Add a duplicate. | |
int | getCurrentQuantity () const |
Gets the quantity of the currently topmost duplicate. | |
int | getCurrentInvIndex () const |
Gets the inventory index of the currently topmost duplicate. | |
int | sellCurrentDuplicate (int quantity) |
Reduces the quantity of the topmost duplicate by the specified amount. | |
int | getPrice () const |
Gets the price of the item. | |
const std::string & | getDisplayName () const |
Gets the display name for the item in the shop list. | |
![]() | |
Item (int id=-1, int quantity=0, bool equipped=false) | |
virtual | ~Item ()=default |
void | setId (int id) |
Sets the item id, identifying the item type. | |
int | getId () const |
Returns the item id. | |
Image * | getImage () const |
Returns the item image. | |
void | setQuantity (int quantity) |
Sets the number of items. | |
void | increaseQuantity (int amount) |
Increases the number of items by the given amount. | |
int | getQuantity () const |
Returns the number of items. | |
void | setEquipped (bool equipped) |
Sets whether this item is equipped. | |
bool | isEquipped () const |
Returns whether this item is equipped. | |
bool | isEquippable () const |
Returns whether this item is equippable. | |
void | setInvIndex (int index) |
Sets the inventory index of this item. | |
int | getInvIndex () const |
Returns the inventory index of this item. | |
void | doEvent (Event::Type eventType) |
void | doEvent (Event::Type eventType, int amount) |
const ItemInfo & | getInfo () const |
Returns information about this item type. | |
Protected Attributes | |
int | mPrice |
std::string | mDisplayName |
std::stack< DuplicateItem > | mDuplicates |
![]() | |
int | mId |
Item type id. | |
ResourceRef< Image > | mImage |
Item image. | |
int | mQuantity |
Number of items. | |
bool | mEquipped |
Item is equipped. | |
int | mInvIndex |
Inventory index. | |
Represents an item in a shop inventory.
It can store quantity and inventory indices of duplicate entries in the shop as well.
Definition at line 32 of file shopitem.h.
ShopItem::ShopItem | ( | int | inventoryIndex, |
int | id, | ||
int | quantity, | ||
int | price | ||
) |
Constructor.
Creates a new ShopItem.
inventoryIndex | the inventory index of the item |
id | the id of the item |
quantity | number of available copies of the item |
price | price of the item |
Definition at line 28 of file shopitem.cpp.
|
overridedefault |
void ShopItem::addDuplicate | ( | int | inventoryIndex, |
int | quantity | ||
) |
Add a duplicate.
Id and price will be taken from this item.
inventoryIndex | the inventory index of the item |
quantity | number of available copies of the item |
Definition at line 41 of file shopitem.cpp.
|
inline |
Gets the inventory index of the currently topmost duplicate.
Definition at line 70 of file shopitem.h.
|
inline |
Gets the quantity of the currently topmost duplicate.
Definition at line 60 of file shopitem.h.
|
inline |
Gets the display name for the item in the shop list.
Definition at line 102 of file shopitem.h.
|
inline |
int ShopItem::sellCurrentDuplicate | ( | int | quantity | ) |
Reduces the quantity of the topmost duplicate by the specified amount.
Also reduces the total quantity of this DuplicateItem. Empty duplicates are automatically removed.
If the amount is bigger than the quantity of the current topmost, only sell as much as possible. Returns the amount actually sold (do not ignore the return value!)
Definition at line 49 of file shopitem.cpp.
|
protected |
Definition at line 107 of file shopitem.h.
|
protected |
Definition at line 117 of file shopitem.h.
|
protected |
Definition at line 106 of file shopitem.h.