summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
authorFreeyorp <Freeyorp101@hotmail.com>2010-05-17 20:55:06 +1200
committerFreeyorp <Freeyorp101@hotmail.com>2010-07-10 21:51:07 +1200
commit98cdcb1de4f422255aa5ef924042ae7d00a5b968 (patch)
tree1746776580502fb007581f171fa89638ab6bc64f /src/scripting/lua.cpp
parent26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (diff)
downloadmanaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.gz
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.bz2
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.xz
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.zip
New attribute system and major changes to many low-level areas.
Attribute system: Structure is no longer completely hardcoded. Attributes and structure is defined by new xml file (defaulting to stats.xml) Structure defines non-base modifications to an attribute, to be used by modifiers from items, effects, etc. Calculating the base value for core attributes is still done in C++ (and for such fundamental elements the only reason I can think of to do it any other way is perhaps being able to quickly change scripts without a compile could be useful for testing, but such things are a low priority anyway) Item structure: Modifiers are now through triggers rather than single events. This also removes hardcoded types - an item could be both able to be equipped and be able to be activated. Item activation no longer consumes by default, this must be specified by the property <consumes /> inside the trigger. Currently only attribute modifications, autoattacks, and consumes are defined as effects, but stubs for others do exist. Autoattacks are currently non-functional, and this should be rectified with some urgency. Auto Attacks: AutoAttacks are now separate entities, though not fully complete, nor fully integrated with all beings yet. Integration with the Character class is urgent, integration with other Being children less so. When fully integrated this will allow for multiple autoattacks, through equipping multiple items with this as an equip effect or even through other means if needed. Equipment structure: As ItemClass types are no longer hardcoded, so too are equip types. An item have multiple ways to be equipped across multiple equipment slots with any number in each slot. Character maximums are global but configurable. Miscellaneous: Speed, money, and weight are now attributes. Some managers have been changed into classes such that their associated classes can have them as friends, to avoid (ab)use of public accessors. The serialise procedure should also be set as a friend of Character (both in the account- and game- server) as well; having public accessors returning iterators is simply ridiculous. Some start for such cleanups have been made, but this is not the primary focus here. Significant work will need to be done before this is resolved completely, but the start is there. BuySell::registerPlayerItems() has been completely disabled temporarily. The previous function iterated through equipment, yet in the context I think it is intended to fill items? I have been unable to update this function to fit the modifications made to the Inventory/Equipment/Possessions, as I am unsure what exactly what it should be doing. ItemClass::mSpriteId was previously unused, so had been removed, but I notice that it was used when transmitting equipment to nearby clients. Experimentation showed that this value was never set to anything other than 0, and so has been left out of the ItemManager rewrite. I am not entirely sure what is happening here, but it should be worth looking into at a later time, as I am not sure how equipment appearences would be sent otherwise.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp79
1 files changed, 21 insertions, 58 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 2d9562ed..72456789 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -49,6 +49,7 @@ extern "C" {
#include "scripting/luautil.hpp"
#include "scripting/luascript.hpp"
#include "utils/logger.h"
+#include "utils/speedconv.hpp"
#include <string.h>
@@ -342,8 +343,10 @@ static int chr_warp(lua_State *s)
* (negative amount) should be passed first, then insertions (positive amount).
* If a removal fails, all the previous operations are canceled (except for
* items dropped on the floor, hence why removals should be passed first), and
- * the function returns false. Otherwise the function will return true. When
- * the item identifier is zero, money is modified.
+ * the function returns false. Otherwise the function will return true.
+ * Note that previously when the item identifier was zero, money was modified;
+ * however currency is now handled through attributes. This breaks backwards
+ * compatibility with old scripts, and so logs a warning.
* Note: If an insertion fails, extra items are dropped on the floor.
* mana.chr_inv_change(character, (int id, int nb)...): bool success
*/
@@ -368,14 +371,7 @@ static int chr_inv_change(lua_State *s)
int nb = lua_tointeger(s, i * 2 + 3);
if (id == 0)
- {
- if (!inv.changeMoney(nb))
- {
- inv.cancel();
- lua_pushboolean(s, 0);
- return 1;
- }
- }
+ LOG_WARN("chr_inv_change: id 0! Currency is now handled through attributes!");
else if (nb < 0)
{
nb = inv.remove(id, -nb);
@@ -388,7 +384,7 @@ static int chr_inv_change(lua_State *s)
}
else
{
- ItemClass *ic = ItemManager::getItem(id);
+ ItemClass *ic = itemManager->getItem(id);
if (!ic)
{
raiseScriptError(s, "chr_inv_change called with an unknown item.");
@@ -410,7 +406,6 @@ static int chr_inv_change(lua_State *s)
/**
* Callback for counting items in inventory.
- * When an item identifier is zero, money is queried.
* mana.chr_inv_count(character, int id...): int count...
*/
static int chr_inv_count(lua_State *s)
@@ -432,7 +427,7 @@ static int chr_inv_count(lua_State *s)
return 0;
}
int id = lua_tointeger(s, i);
- int nb = id ? inv.count(id) : q->getPossessions().money;
+ int nb = id ? inv.count(id) : 0;
lua_pushinteger(s, nb);
}
return nb_items;
@@ -626,38 +621,6 @@ static int being_set_status_time(lua_State *s)
return 1;
}
-/**
-* Returns the current speed of the being
-* mana.being_get_speed(Being *being)
-*/
-static int being_get_speed(lua_State *s)
-{
- if (!lua_isuserdata(s, 1))
- {
- raiseScriptError(s, "being_get_speed called with incorrect parameters.");
- return 0;
- }
- Being *being = getBeing(s, 1);
- lua_pushnumber(s, being->getSpeed());
- return 1;
-}
-
-/**
-* Sets the speed of the being
-* mana.being_set_speed(Being *being, float speed)
-*/
-static int being_set_speed(lua_State *s)
-{
- if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2))
- {
- raiseScriptError(s, "being_set_speed called with incorrect parameters.");
- return 0;
- }
- Being *being = getBeing(s, 1);
- being->setSpeed(lua_tonumber(s, 2));
- return 1;
-}
-
/**
* Returns the Thing type of the given Being
@@ -698,7 +661,11 @@ static int being_walk(lua_State *s)
being->setDestination(destination);
if (lua_isnumber(s, 4))
- being->setSpeed((float) lua_tonumber(s, 4));
+ {
+ being->setAttribute(ATTR_MOVE_SPEED_TPS, lua_tonumber(s, 4));
+ being->setAttribute(ATTR_MOVE_SPEED_RAW, utils::tpsToSpeed(
+ being->getModifiedAttribute(ATTR_MOVE_SPEED_TPS)));
+ }
return 0;
}
@@ -741,14 +708,12 @@ static int being_damage(lua_State *s)
if (!being->canFight())
return 0;
- Damage damage;
- damage.base = lua_tointeger(s, 2);
- damage.delta = lua_tointeger(s, 3);
- damage.cth = lua_tointeger(s, 4);
- damage.type = lua_tointeger(s, 5);
- damage.element = lua_tointeger(s, 6);
-
- being->damage(NULL, damage);
+ Damage dmg((unsigned short) lua_tointeger(s, 2), /* base */
+ (unsigned short) lua_tointeger(s, 3), /* delta */
+ (unsigned short) lua_tointeger(s, 4), /* cth */
+ (unsigned char) lua_tointeger(s, 6), /* element */
+ DAMAGE_PHYSICAL); /* type */
+ being->damage(NULL, dmg);
return 0;
}
@@ -965,7 +930,7 @@ static int monster_create(lua_State *s)
}
int monsterId = lua_tointeger(s, 1);
- MonsterClass *spec = MonsterManager::getMonster(monsterId);
+ MonsterClass *spec = monsterManager->getMonster(monsterId);
if (!spec)
{
raiseScriptError(s, "monster_create called with invalid monster ID: %d", monsterId);
@@ -1649,7 +1614,7 @@ static int item_drop(lua_State *s)
number = lua_tointeger(s, 4);
}
- ItemClass *ic = ItemManager::getItem(type);
+ ItemClass *ic = itemManager->getItem(type);
if (!ic)
{
raiseScriptError(s, "item_drop called with unknown item ID");
@@ -1734,8 +1699,6 @@ LuaScript::LuaScript():
{ "being_has_status", &being_has_status },
{ "being_set_status_time", &being_set_status_time},
{ "being_get_status_time", &being_get_status_time},
- { "being_set_speed", &being_set_speed },
- { "being_get_speed", &being_get_speed },
{ "being_type", &being_type },
{ "being_walk", &being_walk },
{ "being_say", &being_say },