Mana
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Attributes | List of all members
ShopItem Class Reference

Represents an item in a shop inventory. More...

#include <shopitem.h>

Inheritance diagram for ShopItem:
Item

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.
 
- Public Member Functions inherited from Item
 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.
 
ImagegetImage () 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 ItemInfogetInfo () const
 Returns information about this item type.
 

Protected Attributes

int mPrice
 
std::string mDisplayName
 
std::stack< DuplicateItemmDuplicates
 
- Protected Attributes inherited from Item
int mId
 Item type id.
 
ResourceRef< ImagemImage
 Item image.
 
int mQuantity
 Number of items.
 
bool mEquipped
 Item is equipped.
 
int mInvIndex
 Inventory index.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ShopItem()

ShopItem::ShopItem ( int  inventoryIndex,
int  id,
int  quantity,
int  price 
)

Constructor.

Creates a new ShopItem.

Parameters
inventoryIndexthe inventory index of the item
idthe id of the item
quantitynumber of available copies of the item
priceprice of the item

Definition at line 28 of file shopitem.cpp.

◆ ~ShopItem()

ShopItem::~ShopItem ( )
overridedefault

Member Function Documentation

◆ addDuplicate()

void ShopItem::addDuplicate ( int  inventoryIndex,
int  quantity 
)

Add a duplicate.

Id and price will be taken from this item.

Parameters
inventoryIndexthe inventory index of the item
quantitynumber of available copies of the item

Definition at line 41 of file shopitem.cpp.

◆ getCurrentInvIndex()

int ShopItem::getCurrentInvIndex ( ) const
inline

Gets the inventory index of the currently topmost duplicate.

Returns
the inventory index of the currently topmost duplicate

Definition at line 70 of file shopitem.h.

◆ getCurrentQuantity()

int ShopItem::getCurrentQuantity ( ) const
inline

Gets the quantity of the currently topmost duplicate.

Returns
the quantity of the currently topmost duplicate

Definition at line 60 of file shopitem.h.

◆ getDisplayName()

const std::string & ShopItem::getDisplayName ( ) const
inline

Gets the display name for the item in the shop list.

Returns
the display name for the item in the shop list

Definition at line 102 of file shopitem.h.

◆ getPrice()

int ShopItem::getPrice ( ) const
inline

Gets the price of the item.

Returns
the price of the item

Definition at line 94 of file shopitem.h.

◆ sellCurrentDuplicate()

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!)

Returns
the amount, that actually was sold.

Definition at line 49 of file shopitem.cpp.

Member Data Documentation

◆ mDisplayName

std::string ShopItem::mDisplayName
protected

Definition at line 107 of file shopitem.h.

◆ mDuplicates

std::stack<DuplicateItem> ShopItem::mDuplicates
protected

Definition at line 117 of file shopitem.h.

◆ mPrice

int ShopItem::mPrice
protected

Definition at line 106 of file shopitem.h.


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