00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "shopitem.h"
00023
00024 #include "units.h"
00025
00026 #include "resources/iteminfo.h"
00027
00028 ShopItem::ShopItem(int inventoryIndex, int id,
00029 int quantity, int price) :
00030 Item(id, 0),
00031 mPrice(price)
00032 {
00033 mDisplayName = getInfo().getName() +
00034 " (" + Units::formatCurrency(mPrice).c_str() + ")";
00035 setInvIndex(inventoryIndex);
00036 addDuplicate(inventoryIndex, quantity);
00037 }
00038
00039 ShopItem::ShopItem (int id, int price) : Item (id, 0), mPrice(price)
00040 {
00041 mDisplayName = getInfo().getName() +
00042 " (" + Units::formatCurrency(mPrice).c_str() + ")";
00043 setInvIndex(-1);
00044 addDuplicate(-1, 0);
00045 }
00046
00047 ShopItem::~ShopItem()
00048 {
00050 while (!mDuplicates.empty())
00051 {
00052 delete mDuplicates.top();
00053 mDuplicates.pop();
00054 }
00055 }
00056
00057 void ShopItem::addDuplicate(int inventoryIndex, int quantity)
00058 {
00059 DuplicateItem* di = new DuplicateItem;
00060 di->inventoryIndex = inventoryIndex;
00061 di->quantity = quantity;
00062 mDuplicates.push(di);
00063 mQuantity += quantity;
00064 }
00065
00066 void ShopItem::addDuplicate()
00067 {
00068 DuplicateItem* di = new DuplicateItem;
00069 di->inventoryIndex = -1;
00070 di->quantity = 0;
00071 mDuplicates.push(di);
00072 }
00073
00074 int ShopItem::sellCurrentDuplicate(int quantity)
00075 {
00076 DuplicateItem* dupl = mDuplicates.top();
00077 int sellCount = quantity <= dupl->quantity ? quantity : dupl->quantity;
00078 dupl->quantity -= sellCount;
00079 mQuantity -= sellCount;
00080 if (dupl->quantity == 0)
00081 {
00082 delete dupl;
00083 mDuplicates.pop();
00084 }
00085 return sellCount;
00086 }