diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/scripting/lua.cpp | 153 | ||||
-rw-r--r-- | src/scripting/luautil.h | 10 |
2 files changed, 155 insertions, 8 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 00a108c5..97e557a3 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -991,7 +991,7 @@ static int being_damage(lua_State *s) dmg.delta = luaL_checkint(s, 3); dmg.cth = luaL_checkint(s, 4); dmg.type = (DamageType)luaL_checkint(s, 5); - dmg.element = luaL_checkint(s, 6); + dmg.element = (Element)luaL_checkint(s, 6); Being *source = 0; if (lua_gettop(s) >= 7) { @@ -1260,13 +1260,11 @@ static int monster_class_on_damage(lua_State *s) return 0; } -static int monster_class_on(lua_State *s) +static int monster_class_attacks(lua_State *s) { MonsterClass *monsterClass = LuaMonsterClass::check(s, 1); - const char *event = luaL_checkstring(s, 2); - luaL_checktype(s, 3, LUA_TFUNCTION); - monsterClass->setEventCallback(event, getScript(s)); - return 0; + pushSTLContainer(s, monsterClass->getAttackInfos()); + return 1; } /** @@ -2054,6 +2052,14 @@ static int item_class_on(lua_State *s) return 0; } +static int item_class_attacks(lua_State *s) +{ + ItemClass *itemClass = LuaItemClass::check(s, 1); + std::vector<AttackInfo *> attacks = itemClass->getAttackInfos(); + pushSTLContainer<AttackInfo *>(s, attacks); + return 1; +} + /** * drop_item(int x, int y, int id || string name[, int number]): bool * Creates an item stack on the floor. @@ -2320,6 +2326,113 @@ static int specialinfo_on_use(lua_State *s) return 0; } +static int attack_get_priority(lua_State *s) +{ + AttackInfo *attack = LuaAttackInfo::check(s, 1); + lua_pushinteger(s, attack->getPriority()); + return 1; +} + +static int attack_get_cooldowntime(lua_State *s) +{ + AttackInfo *attack = LuaAttackInfo::check(s, 1); + lua_pushinteger(s, attack->getCooldownTime()); + return 1; +} + +static int attack_get_warmuptime(lua_State *s) +{ + AttackInfo *attack = LuaAttackInfo::check(s, 1); + lua_pushinteger(s, attack->getWarmupTime()); + return 1; +} + +static int attack_get_reusetime(lua_State *s) +{ + AttackInfo *attack = LuaAttackInfo::check(s, 1); + lua_pushinteger(s, attack->getReuseTime()); + return 1; +} + +static int attack_get_damage(lua_State *s) +{ + AttackInfo *attack = LuaAttackInfo::check(s, 1); + LuaDamage::push(s, &attack->getDamage()); + return 1; +} + +static int attack_on_attack(lua_State *s) +{ + AttackInfo *attack = LuaAttackInfo::check(s, 1); + luaL_checktype(s, 2, LUA_TFUNCTION); + attack->setCallback(getScript(s)); + return 0; +} + +static int damage_get_id(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->id); + return 1; +} + + +static int damage_get_skill(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->skill); + return 1; +} + +static int damage_get_base(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->base); + return 1; +} + +static int damage_get_delta(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->delta); + return 1; +} + +static int damage_get_cth(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->cth); + return 1; +} + +static int damage_get_element(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->element); + return 1; +} + +static int damage_get_type(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->type); + return 1; +} + +static int damage_is_truestrike(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushboolean(s, damage->trueStrike); + return 1; +} + +static int damage_get_range(lua_State *s) +{ + Damage *damage = LuaDamage::check(s, 1); + lua_pushinteger(s, damage->range); + return 1; +} + static int require_loader(lua_State *s) { // Add .lua extension (maybe only do this when it doesn't have it already) @@ -2468,8 +2581,32 @@ LuaScript::LuaScript(): luaL_register(mRootState, NULL, callbacks); lua_pop(mRootState, 1); // pop the globals table + static luaL_Reg const members_AttackInfo[] = { + { "priority", &attack_get_priority }, + { "cooldowntime", &attack_get_cooldowntime }, + { "warmuptime", &attack_get_warmuptime }, + { "reusetime", &attack_get_reusetime }, + { "damage", &attack_get_damage }, + { "on_attack", &attack_on_attack }, + { NULL, NULL } + }; + + static luaL_Reg const members_Damage[] = { + { "id", &damage_get_id }, + { "skill", &damage_get_skill }, + { "base", &damage_get_base }, + { "delta", &damage_get_delta }, + { "cth", &damage_get_cth }, + { "element", &damage_get_element }, + { "type", &damage_get_type }, + { "is_truestrike", &damage_is_truestrike }, + { "range", &damage_get_range }, + { NULL, NULL } + }; + static luaL_Reg const members_ItemClass[] = { { "on", &item_class_on }, + { "attacks", &item_class_attacks }, { NULL, NULL } }; @@ -2484,7 +2621,7 @@ LuaScript::LuaScript(): static luaL_Reg const members_MonsterClass[] = { { "on_update", &monster_class_on_update }, { "on_damage", &monster_class_on_damage }, - { "on", &monster_class_on }, + { "attacks", &monster_class_attacks }, { NULL, NULL } }; @@ -2503,6 +2640,8 @@ LuaScript::LuaScript(): { NULL, NULL} }; + LuaAttackInfo::registerType(mRootState, "Attack", members_AttackInfo); + LuaDamage::registerType(mRootState, "Damage", members_Damage); LuaItemClass::registerType(mRootState, "ItemClass", members_ItemClass); LuaMapObject::registerType(mRootState, "MapObject", members_MapObject); LuaMonsterClass::registerType(mRootState, "MonsterClass", members_MonsterClass); diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h index 2395f211..e2ee5737 100644 --- a/src/scripting/luautil.h +++ b/src/scripting/luautil.h @@ -34,10 +34,12 @@ extern "C" { #include <set> #include <vector> +#include "game-server/attack.h" #include "game-server/specialmanager.h" class Being; class Character; +class Entity; class ItemClass; class MapComposite; class MapObject; @@ -45,7 +47,6 @@ class Monster; class MonsterClass; class NPC; class StatusEffect; -class Entity; // Report script errors and interrupt the script. void raiseScriptError(lua_State *s, const char *format, ...); @@ -150,6 +151,8 @@ private: template <typename T> const char * LuaUserData<T>::mTypeName; +typedef LuaUserData<AttackInfo> LuaAttackInfo; +typedef LuaUserData<Damage> LuaDamage; typedef LuaUserData<ItemClass> LuaItemClass; typedef LuaUserData<MapObject> LuaMapObject; typedef LuaUserData<MonsterClass> LuaMonsterClass; @@ -185,6 +188,11 @@ void push(lua_State *s, const std::string &val); void push(lua_State *s, Entity *val); void push(lua_State *s, double val); +inline void push(lua_State *s, AttackInfo *val) +{ + LuaAttackInfo::push(s, val); +} + inline void push(lua_State *s, MapObject *val) { LuaMapObject::push(s, val); |