From 2288a403ad4377fbb552243e805aaf0b5a4f5a0d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 3 Nov 2015 21:54:44 +0300 Subject: Allow buy from npc shop or from market more than one of item at one transaction. --- src/shopitem.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/shopitem.cpp') diff --git a/src/shopitem.cpp b/src/shopitem.cpp index faf635fbd..0430e4d0f 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -22,6 +22,7 @@ #include "shopitem.h" +#include "logger.h" #include "units.h" #include "resources/iteminfo.h" @@ -47,6 +48,7 @@ ShopItem::ShopItem(const int inventoryIndex, mDisplayName(), mDuplicates(), mPrice(price), + mUsedQuantity(0), mShowQuantity(true), mVisible(true) { @@ -68,6 +70,7 @@ ShopItem::ShopItem(const int id, mDisplayName(), mDuplicates(), mPrice(price), + mUsedQuantity(0), mShowQuantity(false), mVisible(true) { @@ -97,14 +100,15 @@ void ShopItem::updateDisplayName(const int quantity) mDisplayName.append(" (").append( Units::formatCurrency(mPrice)).append(") "); } - if (quantity > 1) + if (mShowQuantity && quantity > 1) mDisplayName.append("[").append(toString(quantity)).append("]"); + if (mUsedQuantity > 0) + mDisplayName.append(" +").append(toString(mUsedQuantity)); } void ShopItem::update() { - if (mShowQuantity) - updateDisplayName(mQuantity); + updateDisplayName(mQuantity); } void ShopItem::addDuplicate(const int inventoryIndex, const int quantity) @@ -141,3 +145,21 @@ int ShopItem::sellCurrentDuplicate(const int quantity) } return sellCount; } + +void ShopItem::increaseUsedQuantity(const int amount) +{ + if (mShowQuantity && mQuantity) + { + if (mQuantity < mUsedQuantity + amount || + mUsedQuantity + amount < 0) + { + return; + } + } + else if (mUsedQuantity + amount < 0) + { + return; + } + + mUsedQuantity += amount; +} -- cgit v1.2.3-60-g2f50