#include <shopitem.h>
It can store quantity and inventory indices of duplicate entries in the shop as well.
Definition at line 33 of file shopitem.h.
Public Member Functions | |
ShopItem (int inventoryIndex, int id, int quantity, int price) | |
Constructor. | |
ShopItem (int id, int price) | |
Constructor. | |
~ShopItem () | |
Destructor. | |
void | addDuplicate (int inventoryIndex, int quantity) |
Add a duplicate. | |
void | addDuplicate () |
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. | |
Protected Attributes | |
int | mPrice |
std::string | mDisplayName |
std::stack< DuplicateItem * > | mDuplicates |
Classes | |
struct | DuplicateItem |
Struct to keep track of duplicates. More... |
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.
ShopItem::ShopItem | ( | int | id, | |
int | price | |||
) |
Constructor.
Creates a new ShopItem. Inventory index will be set to -1 and quantity to 0.
id | the id of the item | |
price | price of the item |
Definition at line 39 of file shopitem.cpp.
ShopItem::~ShopItem | ( | ) |
Destructor.
Clear all remaining duplicates on Object destruction.
Definition at line 47 of file shopitem.cpp.
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 57 of file shopitem.cpp.
void ShopItem::addDuplicate | ( | ) |
Add a duplicate.
Id and price will be taken from this item. Needed for compatibility with ShopDuplicateItems (see) class documentation).
Definition at line 66 of file shopitem.cpp.
int ShopItem::getCurrentQuantity | ( | ) | const [inline] |
Gets the quantity of the currently topmost duplicate.
Definition at line 80 of file shopitem.h.
int ShopItem::getCurrentInvIndex | ( | ) | const [inline] |
Gets the inventory index of the currently topmost duplicate.
Definition at line 90 of file shopitem.h.
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 74 of file shopitem.cpp.
int ShopItem::getPrice | ( | ) | const [inline] |
Gets the price of the item.
Definition at line 114 of file shopitem.h.
const std::string& ShopItem::getDisplayName | ( | ) | const [inline] |
Gets the display name for the item in the shop list.
Definition at line 122 of file shopitem.h.
int ShopItem::mPrice [protected] |
Definition at line 126 of file shopitem.h.
std::string ShopItem::mDisplayName [protected] |
Definition at line 127 of file shopitem.h.
std::stack<DuplicateItem*> ShopItem::mDuplicates [protected] |
Definition at line 136 of file shopitem.h.