summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-31 02:02:43 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-31 02:02:43 +0100
commitb2209cbe93aa12dcd4e4e3b9a7cd8b13ed5713e9 (patch)
tree7375b0a214fa1e0c4523c49b0806417208b371c3
parent4bae401f089c39371bc1c89d45aafae24b9402fe (diff)
downloadmanaserv-b2209cbe93aa12dcd4e4e3b9a7cd8b13ed5713e9.tar.gz
manaserv-b2209cbe93aa12dcd4e4e3b9a7cd8b13ed5713e9.tar.xz
manaserv-b2209cbe93aa12dcd4e4e3b9a7cd8b13ed5713e9.zip
Fixed the money handling.
- At character's attributes recalculation when necessary. - In the lua scripting functions.
-rw-r--r--src/defines.h2
-rw-r--r--src/game-server/being.cpp5
-rw-r--r--src/game-server/buysell.cpp2
-rw-r--r--src/game-server/trade.cpp3
-rw-r--r--src/scripting/lua.cpp29
5 files changed, 34 insertions, 7 deletions
diff --git a/src/defines.h b/src/defines.h
index fc99fb6..89b9b38 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -159,7 +159,7 @@ enum Element
#define ATTR_MOVE_SPEED_RAW 17
// Money and inventory size attributes.
-#define ATTR_GP 18
+#define ATTR_MONEY 18
#define ATTR_INV_CAPACITY 19
/**
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index c2228dc..a01126f 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -528,6 +528,11 @@ bool Being::recalculateBaseAttribute(unsigned int attr)
// Provisional
newBase = 2000.0 + getModifiedAttribute(ATTR_STR) * 180.0;
break;
+ case ATTR_MONEY:
+ // Set the money to 0 if it was never set before.
+ if (getModifiedAttribute(ATTR_MONEY) < 0)
+ newBase = 0.0;
+ break;
}
if (newBase != getAttribute(attr))
{
diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp
index b3abb3e..4c083f5 100644
--- a/src/game-server/buysell.cpp
+++ b/src/game-server/buysell.cpp
@@ -32,7 +32,7 @@
#include <algorithm>
BuySell::BuySell(Character *c, bool sell):
- mCurrencyId(ATTR_GP), mChar(c), mSell(sell)
+ mCurrencyId(ATTR_MONEY), mChar(c), mSell(sell)
{
c->setBuySell(this);
}
diff --git a/src/game-server/trade.cpp b/src/game-server/trade.cpp
index 5150930..bcdc997 100644
--- a/src/game-server/trade.cpp
+++ b/src/game-server/trade.cpp
@@ -38,7 +38,8 @@
*/
Trade::Trade(Character *c1, Character *c2):
- mChar1(c1), mChar2(c2), mMoney1(0), mMoney2(0), mState(TRADE_INIT), mCurrencyId(ATTR_GP)
+ mChar1(c1), mChar2(c2), mMoney1(0), mMoney2(0), mState(TRADE_INIT),
+ mCurrencyId(ATTR_MONEY)
{
MessageOut msg(GPMSG_TRADE_REQUEST);
msg.writeInt16(c1->getPublicID());
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 3a61541..57146cb 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -370,8 +370,14 @@ static int chr_inv_change(lua_State *s)
int id = lua_tointeger(s, i * 2 + 2);
int nb = lua_tointeger(s, i * 2 + 3);
- if (id == 0)
- LOG_WARN("chr_inv_change: id 0! Currency is now handled through attributes!");
+ if (id == 0) // Id 0 = Change money amount.
+ {
+ double money = q->getModifiedAttribute(ATTR_MONEY);
+ money += nb;
+ q->setAttribute(ATTR_MONEY, money);
+ lua_pushboolean(s, 1);
+ return 1;
+ }
else if (nb < 0)
{
nb = inv.remove(id, -nb);
@@ -421,8 +427,23 @@ static int chr_inv_count(lua_State *s)
Inventory inv(q);
for (int i = 2; i <= nb_items + 1; ++i)
{
- int nb = inv.count(luaL_checkint(s, i));
- lua_pushinteger(s, nb);
+ int id = luaL_checkint(s, i);
+
+ // Id 0 = Money - get it through attributes
+ if (id == 0)
+ {
+ int money = (int) q->getAttribute(ATTR_MONEY);
+
+ if (money < 0)
+ money = 0;
+ lua_pushinteger(s, money);
+ }
+ else
+ {
+ // Otherwise, return the normal count result
+ int nb = inv.count(id);
+ lua_pushinteger(s, nb);
+ }
}
return nb_items;
}