From ada1a2756824d80ee004d1c1dcbcaba3ce34d2af Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 15 Feb 2015 18:09:18 +0300 Subject: eathena: impliment selling item to buying store. --- src/gui/windows/buyingstoreselldialog.cpp | 21 +++++++++++++++++++++ src/net/buyingstorehandler.h | 4 ++-- src/net/eathena/buyingstorehandler.cpp | 11 ++++++----- src/net/eathena/buyingstorehandler.h | 3 +-- src/net/tmwa/buyingstorehandler.cpp | 3 +-- src/net/tmwa/buyingstorehandler.h | 3 +-- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/gui/windows/buyingstoreselldialog.cpp b/src/gui/windows/buyingstoreselldialog.cpp index e3d6cbf88..29b24f638 100644 --- a/src/gui/windows/buyingstoreselldialog.cpp +++ b/src/gui/windows/buyingstoreselldialog.cpp @@ -22,6 +22,8 @@ #include "gui/windows/buyingstoreselldialog.h" +#include "actormanager.h" +#include "inventory.h" #include "shopitem.h" #include "being/being.h" @@ -45,4 +47,23 @@ BuyingStoreSellDialog::BuyingStoreSellDialog(const int accountId, void BuyingStoreSellDialog::sellAction(const ActionEvent &event A_UNUSED) { + if (mAmountItems <= 0 || mAmountItems > mMaxItems) + return; + + const int selectedItem = mShopItemList->getSelected(); + ShopItem *const item1 = mShopItems->at(selectedItem); + if (!item1 || PlayerInfo::isItemProtected(item1->getId())) + return; + Being *const being = actorManager->findBeing(mAccountId); + if (!being) + return; + // +++ need add colors + Item *const item2 = PlayerInfo::getInventory()->findItem( + item1->getId(), 1); + if (!item2) + return; + + mPlayerMoney += mAmountItems * item1->getPrice(); + mMaxItems -= mAmountItems; + buyingStoreHandler->sell(being, mStoreId, item2, mAmountItems); } diff --git a/src/net/buyingstorehandler.h b/src/net/buyingstorehandler.h index 856f2ad3d..321cd9ec1 100644 --- a/src/net/buyingstorehandler.h +++ b/src/net/buyingstorehandler.h @@ -27,6 +27,7 @@ #include "localconsts.h" class Being; +class Item; class ShopItem; namespace Net @@ -49,8 +50,7 @@ class BuyingStoreHandler notfinal virtual void sell(const Being *const being, const int storeId, - const int index, - const int itemId, + const Item *const item, const int amount) const = 0; }; diff --git a/src/net/eathena/buyingstorehandler.cpp b/src/net/eathena/buyingstorehandler.cpp index 7f2627a29..cca75ce78 100644 --- a/src/net/eathena/buyingstorehandler.cpp +++ b/src/net/eathena/buyingstorehandler.cpp @@ -310,19 +310,20 @@ void BuyingStoreHandler::open(const Being *const being) const void BuyingStoreHandler::sell(const Being *const being, const int storeId, - const int index, - const int itemId, + const Item *const item, const int amount) const { if (!being) return; createOutPacket(CMSG_BUYINGSTORE_SELL); - outMsg.writeInt16(16, "len"); + outMsg.writeInt16(18, "len"); outMsg.writeInt32(being->getId(), "account id"); outMsg.writeInt32(storeId, "store id"); - outMsg.writeInt16(static_cast(index), "index"); - outMsg.writeInt16(static_cast(itemId), "item id"); + outMsg.writeInt16(static_cast( + item->getInvIndex() + INVENTORY_OFFSET), + "index"); + outMsg.writeInt16(static_cast(item->getId()), "item id"); outMsg.writeInt16(static_cast(amount), "amount"); } diff --git a/src/net/eathena/buyingstorehandler.h b/src/net/eathena/buyingstorehandler.h index f48373f03..123ae135e 100644 --- a/src/net/eathena/buyingstorehandler.h +++ b/src/net/eathena/buyingstorehandler.h @@ -48,8 +48,7 @@ class BuyingStoreHandler final : public MessageHandler, void sell(const Being *const being, const int storeId, - const int index, - const int itemId, + const Item *const item, const int amount) const override final; protected: diff --git a/src/net/tmwa/buyingstorehandler.cpp b/src/net/tmwa/buyingstorehandler.cpp index b2385eacb..245775c24 100644 --- a/src/net/tmwa/buyingstorehandler.cpp +++ b/src/net/tmwa/buyingstorehandler.cpp @@ -59,8 +59,7 @@ void BuyingStoreHandler::open(const Being *const being A_UNUSED) const void BuyingStoreHandler::sell(const Being *const being A_UNUSED, const int storeId A_UNUSED, - const int index A_UNUSED, - const int itemId A_UNUSED, + const Item *const item A_UNUSED, const int amount A_UNUSED) const { } diff --git a/src/net/tmwa/buyingstorehandler.h b/src/net/tmwa/buyingstorehandler.h index 2eb965783..b98325acc 100644 --- a/src/net/tmwa/buyingstorehandler.h +++ b/src/net/tmwa/buyingstorehandler.h @@ -49,8 +49,7 @@ class BuyingStoreHandler final : public MessageHandler, void sell(const Being *const being, const int storeId, - const int index, - const int itemId, + const Item *const item, const int amount) const override final; }; -- cgit v1.2.3-70-g09d2