summaryrefslogtreecommitdiff
path: root/src/game-server/trade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server/trade.cpp')
-rw-r--r--src/game-server/trade.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/game-server/trade.cpp b/src/game-server/trade.cpp
index c044ece6..e2f1cd0c 100644
--- a/src/game-server/trade.cpp
+++ b/src/game-server/trade.cpp
@@ -38,7 +38,7 @@
*/
Trade::Trade(Character *c1, Character *c2):
- mChar1(c1), mChar2(c2), mMoney1(0), mMoney2(0), mState(TRADE_INIT)
+ mChar1(c1), mChar2(c2), mMoney1(0), mMoney2(0), mState(TRADE_INIT), mCurrencyId(ATTR_GP)
{
MessageOut msg(GPMSG_TRADE_REQUEST);
msg.writeShort(c1->getPublicID());
@@ -131,10 +131,17 @@ void Trade::agree(Character *c)
// Check if both player has the objects in their inventories
// and enouth money, then swap them.
Inventory v1(mChar1, true), v2(mChar2, true);
- if (!perform(mItems1, v1, v2) ||
- !perform(mItems2, v2, v1) ||
- !v1.changeMoney(mMoney2 - mMoney1) ||
- !v2.changeMoney(mMoney1 - mMoney2))
+ if (mChar1->getAttribute(mCurrencyId) >= mMoney1 - mMoney2 &&
+ mChar2->getAttribute(mCurrencyId) >= mMoney2 - mMoney1 &&
+ perform(mItems1, v1, v2) &&
+ perform(mItems2, v2, v1))
+ {
+ mChar1->setAttribute(mCurrencyId, mChar1->getAttribute(mCurrencyId)
+ - mMoney1 + mMoney2);
+ mChar2->setAttribute(mCurrencyId, mChar2->getAttribute(mCurrencyId)
+ - mMoney2 + mMoney1);
+ }
+ else
{
v1.cancel();
v2.cancel();