summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-06-10 15:11:11 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-01-08 16:58:57 +0100
commitcf69b4b007e602576208d1beff9852c8bf1acbe9 (patch)
treec864c21097b0e462ece0b570bf38f5a0660d5739
parent6f287f239e9d94707735b183d6c6b89eea9fef20 (diff)
downloadmanaserv-cf69b4b007e602576208d1beff9852c8bf1acbe9.tar.gz
manaserv-cf69b4b007e602576208d1beff9852c8bf1acbe9.tar.bz2
manaserv-cf69b4b007e602576208d1beff9852c8bf1acbe9.tar.xz
manaserv-cf69b4b007e602576208d1beff9852c8bf1acbe9.zip
Added script binds for getting attack information
New binds: - Damage: - id - skill - base - delta - cth - element - type - truestrike - range - Attack: - priority - cooldown - warmup - global_cooldown - damage - on_attack - MonsterClass: - attacks - ItemClass: - attacks
-rw-r--r--example/scripts/monster/testmonster.lua5
-rw-r--r--src/scripting/lua.cpp153
-rw-r--r--src/scripting/luautil.h10
3 files changed, 159 insertions, 9 deletions
diff --git a/example/scripts/monster/testmonster.lua b/example/scripts/monster/testmonster.lua
index 6ef11faa..86d1592f 100644
--- a/example/scripts/monster/testmonster.lua
+++ b/example/scripts/monster/testmonster.lua
@@ -26,4 +26,7 @@ end
local maggot = get_monster_class("maggot")
maggot:on_update(update)
-maggot:on("strike", strike)
+local attacks = maggot:attacks();
+for i, attack in ipairs(attacks) do
+ attack:on_attack(strike)
+end
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 5e0f93c9..6285f382 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1001,7 +1001,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)
{
@@ -1269,13 +1269,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;
}
/**
@@ -2170,6 +2168,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.
@@ -2435,6 +2441,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)
@@ -2590,8 +2703,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 }
};
@@ -2606,7 +2743,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 }
};
@@ -2625,6 +2762,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 36ed80f4..1ff2ab8d 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;
void raiseWarning(lua_State *s, const char *format, ...);
@@ -147,6 +148,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;
@@ -198,6 +201,11 @@ inline void push(lua_State *s, double val)
lua_pushnumber(s, 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);