summaryrefslogtreecommitdiff
path: root/src/game-server/buysell.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_fr>2010-05-28 02:59:45 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_fr>2010-05-28 03:42:16 +0200
commit39b00578c249a3396bb03faa92bc9cccdcb1c68a (patch)
treefb9376dd3229f37c4b8d988c569493178ee130bd /src/game-server/buysell.cpp
parente6ce3d52648aec7139f1c3383a0ef0921411f0d4 (diff)
downloadmanaserv-39b00578c249a3396bb03faa92bc9cccdcb1c68a.tar.gz
manaserv-39b00578c249a3396bb03faa92bc9cccdcb1c68a.tar.bz2
manaserv-39b00578c249a3396bb03faa92bc9cccdcb1c68a.tar.xz
manaserv-39b00578c249a3396bb03faa92bc9cccdcb1c68a.zip
Modified the npc_trade() lua function to permit selling the whole player inventory.
It permits to open a sell box with every items in the player inventory as requested by Striker. Also added different return value support to both the buy selling functions, and made fixes where relevant. The test.lua script will be upgraded to show examples in a next commit. What's left to be done is to fix the inventory handling for both selling functions. (Sigh...) Concerns: Manasource mantis: #78, #101. Reviewed-by: Jaxad0127
Diffstat (limited to 'src/game-server/buysell.cpp')
-rw-r--r--src/game-server/buysell.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp
index 5622514b..2ae64618 100644
--- a/src/game-server/buysell.cpp
+++ b/src/game-server/buysell.cpp
@@ -23,6 +23,8 @@
#include "game-server/character.hpp"
#include "game-server/gamehandler.hpp"
#include "game-server/inventory.hpp"
+#include "game-server/itemmanager.hpp"
+#include "game-server/item.hpp"
#include "net/messageout.hpp"
#include <algorithm>
@@ -43,27 +45,54 @@ void BuySell::cancel()
delete this;
}
-void BuySell::registerItem(int id, int amount, int cost)
+bool BuySell::registerItem(int id, int amount, int cost)
{
if (mSell)
{
int nb = Inventory(mChar).count(id);
if (nb == 0)
- return;
+ return false;
if (!amount || nb < amount)
amount = nb;
}
TradedItem it = { id, amount, cost };
mItems.push_back(it);
+ return true;
}
-void BuySell::start(Actor *actor)
+int BuySell::registerPlayerItems()
+{
+ int nbItemsToSell = 0;
+ if (mSell)
+ {
+ for (int i = 0; i < EQUIPMENT_SLOTS; ++i)
+ {
+ int id = Inventory(mChar).getItem(i);
+ int nb = Inventory(mChar).count(id);
+ if (nb > 0)
+ {
+ int cost = -1;
+ if (ItemManager::getItem(id))
+ cost = ItemManager::getItem(id)->getCost();
+ if (cost > 0)
+ {
+ TradedItem it = { id, nb, cost };
+ mItems.push_back(it);
+ nbItemsToSell++;
+ }
+ }
+ }
+ }
+ return nbItemsToSell;
+}
+
+bool BuySell::start(Actor *actor)
{
if (mItems.empty())
{
cancel();
- return;
+ return false;
}
MessageOut msg(mSell ? GPMSG_NPC_SELL : GPMSG_NPC_BUY);
@@ -76,6 +105,7 @@ void BuySell::start(Actor *actor)
msg.writeShort(i->cost);
}
mChar->getClient()->send(msg);
+ return true;
}
void BuySell::perform(int id, int amount)