From 5cfc73dc5c0093a96c45f604a028ecca21a01af8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 4 Nov 2015 02:03:03 +0300 Subject: Allow sell to npc many items at one time (hercules). --- src/gui/windows/npcselldialog.cpp | 44 +++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'src/gui/windows/npcselldialog.cpp') 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; -- cgit v1.2.3-60-g2f50