summaryrefslogtreecommitdiff
path: root/src/gui/windows/npcselldialog.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-04 02:03:03 +0300
committerAndrei Karas <akaras@inbox.ru>2015-11-04 02:40:04 +0300
commit5cfc73dc5c0093a96c45f604a028ecca21a01af8 (patch)
tree4916b602dfa9b5caee28252515a45215008b8d71 /src/gui/windows/npcselldialog.cpp
parent2288a403ad4377fbb552243e805aaf0b5a4f5a0d (diff)
downloadmanaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.gz
manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.bz2
manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.xz
manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.zip
Allow sell to npc many items at one time (hercules).halloween2015
Diffstat (limited to 'src/gui/windows/npcselldialog.cpp')
-rw-r--r--src/gui/windows/npcselldialog.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/gui/windows/npcselldialog.cpp b/src/gui/windows/npcselldialog.cpp
index 2645f4798..ab9ae47d0 100644
--- a/src/gui/windows/npcselldialog.cpp
+++ b/src/gui/windows/npcselldialog.cpp
@@ -28,12 +28,14 @@
#include "gui/models/shopitems.h"
+#include "gui/widgets/button.h"
#include "gui/widgets/createwidget.h"
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/slider.h"
#include "net/buysellhandler.h"
#include "net/npchandler.h"
+#include "net/serverfeatures.h"
#include "resources/iteminfo.h"
@@ -43,23 +45,25 @@
#include "debug.h"
NpcSellDialog::NpcSellDialog(const BeingId npcId) :
- SellDialog(true),
+ SellDialog(true,
+ serverFeatures ? serverFeatures->haveAdvancedBuySell() : false),
mNpcId(npcId)
{
}
void NpcSellDialog::sellAction(const ActionEvent &event)
{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
const std::string &eventId = event.getId();
const int selectedItem = mShopItemList->getSelected();
ShopItem *const item = mShopItems->at(selectedItem);
if (!item || PlayerInfo::isItemProtected(item->getId()))
return;
+
if (eventId == "presell")
{
+ if (mAmountItems <= 0 || mAmountItems > mMaxItems)
+ return;
+
const ItemInfo &info = ItemDB::get(item->getId());
if (info.isProtected())
{
@@ -76,6 +80,38 @@ void NpcSellDialog::sellAction(const ActionEvent &event)
return;
}
}
+
+ if (mAdvanced)
+ sellManyItems(event.getId());
+ else
+ sellOneItem();
+}
+
+void NpcSellDialog::sellManyItems(const std::string &eventId)
+{
+ if (eventId == "confirm")
+ {
+ npcHandler->sellItems(mShopItems->allItems());
+ close();
+ }
+ else
+ {
+ const int selectedItem = mShopItemList->getSelected();
+ ShopItem *const item = mShopItems->at(selectedItem);
+ item->increaseUsedQuantity(mAmountItems);
+ item->update();
+ if (mConfirmButton)
+ mConfirmButton->setEnabled(true);
+ }
+}
+
+void NpcSellDialog::sellOneItem()
+{
+ if (mAmountItems <= 0 || mAmountItems > mMaxItems)
+ return;
+
+ const int selectedItem = mShopItemList->getSelected();
+ ShopItem *const item = mShopItems->at(selectedItem);
// Attempt sell
mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice();
mMaxItems -= mAmountItems;