From fa908040ca48ce2ce17caeccce42077e7e5713d9 Mon Sep 17 00:00:00 2001 From: KimLS Date: Sat, 11 May 2013 13:51:57 -0700 Subject: [PATCH] Lua work on api - entity and mob, lots more to go --- zone/CMakeLists.txt | 4 ++ zone/lua_client.cpp | 8 +++ zone/lua_client.h | 18 ++++++ zone/lua_entity.cpp | 12 ++++ zone/lua_entity.h | 10 ++-- zone/lua_mob.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++++ zone/lua_mob.h | 33 +++++++++- zone/lua_npc.cpp | 8 +++ zone/lua_npc.h | 18 ++++++ zone/lua_parser.cpp | 52 ++++++++++++++-- 10 files changed, 292 insertions(+), 13 deletions(-) create mode 100644 zone/lua_client.cpp create mode 100644 zone/lua_client.h create mode 100644 zone/lua_npc.cpp create mode 100644 zone/lua_npc.h diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 54e0321c9..d2a757e14 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -31,8 +31,10 @@ SET(zone_sources horse.cpp inventory.cpp loottables.cpp + lua_client.cpp lua_entity.cpp lua_mob.cpp + lua_npc.cpp lua_parser.cpp Map.cpp merc.cpp @@ -112,8 +114,10 @@ SET(zone_headers guild_mgr.h hate_list.h horse.h + lua_client.h lua_entity.h lua_mob.h + lua_npc.h lua_parser.h map.h masterentity.h diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp new file mode 100644 index 000000000..f3b9369b3 --- /dev/null +++ b/zone/lua_client.cpp @@ -0,0 +1,8 @@ +#ifdef LUA_EQEMU + +#include "masterentity.h" +#include "lua_client.h" + + + +#endif diff --git a/zone/lua_client.h b/zone/lua_client.h new file mode 100644 index 000000000..8a094be9b --- /dev/null +++ b/zone/lua_client.h @@ -0,0 +1,18 @@ +#ifndef EQEMU_LUA_CLIENT_H +#define EQEMU_LUA_CLIENT_H +#ifdef LUA_EQEMU + +#include "lua_mob.h" + +class Client; + +class Lua_Client : public Lua_Mob +{ +public: + Lua_Client() { d_ = nullptr; } + Lua_Client(Client *d) { d_ = d; } + virtual ~Lua_Client() { } +}; + +#endif +#endif \ No newline at end of file diff --git a/zone/lua_entity.cpp b/zone/lua_entity.cpp index f6227b7d5..1daf94b8d 100644 --- a/zone/lua_entity.cpp +++ b/zone/lua_entity.cpp @@ -3,6 +3,8 @@ #include "masterentity.h" #include "lua_entity.h" #include "lua_mob.h" +#include "lua_client.h" +#include "lua_npc.h" bool Lua_Entity::IsClient() { Entity *ent = reinterpret_cast(d_); @@ -64,6 +66,16 @@ int Lua_Entity::GetID() { return ent->GetID(); } +Lua_Client Lua_Entity::CastToClient() { + Client *m = reinterpret_cast(d_); + return Lua_Client(m); +} + +Lua_NPC Lua_Entity::CastToNPC() { + NPC *m = reinterpret_cast(d_); + return Lua_NPC(m); +} + Lua_Mob Lua_Entity::CastToMob() { Mob *m = reinterpret_cast(d_); return Lua_Mob(m); diff --git a/zone/lua_entity.h b/zone/lua_entity.h index 292c1ef6e..accec2328 100644 --- a/zone/lua_entity.h +++ b/zone/lua_entity.h @@ -3,8 +3,8 @@ #ifdef LUA_EQEMU class Entity; -//class Lua_Client; -//class Lua_NPC; +class Lua_Client; +class Lua_NPC; class Lua_Mob; //class Lua_Merc; //class Lua_Corpse; @@ -16,7 +16,7 @@ class Lua_Mob; class Lua_Entity { public: - Lua_Entity() { } + Lua_Entity() { d_ = nullptr; } Lua_Entity(Entity *d) : d_(d) { } virtual ~Lua_Entity() { } @@ -33,8 +33,8 @@ public: bool IsBeacon(); int GetID(); - //Lua_Client CastToClient(); - //Lua_NPC CastToNPC(); + Lua_Client CastToClient(); + Lua_NPC CastToNPC(); Lua_Mob CastToMob(); //Lua_Merc CastToMerc(); //Lua_Corpse CastToCorpse(); diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 86edfcc0a..45314ac81 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -17,4 +17,146 @@ void Lua_Mob::Depop(bool start_spawn_timer) { return m->Depop(start_spawn_timer); } +void Lua_Mob::RogueAssassinate(Lua_Mob other) { + Mob *m = reinterpret_cast(d_); + Mob *o = reinterpret_cast(other.d_); + m->RogueAssassinate(o); +} + +bool Lua_Mob::BehindMob() { + return BehindMob(Lua_Mob(nullptr), 0.0f, 0.0f); +} + +bool Lua_Mob::BehindMob(Lua_Mob other) { + return BehindMob(other, 0.0f, 0.0f); +} + +bool Lua_Mob::BehindMob(Lua_Mob other, float x) { + return BehindMob(other, x, 0.0f); +} + +bool Lua_Mob::BehindMob(Lua_Mob other, float x, float y) { + Mob *m = reinterpret_cast(d_); + Mob *o = reinterpret_cast(other.d_); + return m->BehindMob(o, x, y); +} + +void Lua_Mob::SetLevel(int level) { + SetLevel(level, false); +} + +void Lua_Mob::SetLevel(int level, bool command) { + Mob *m = reinterpret_cast(d_); + m->SetLevel(level, command); +} + +void Lua_Mob::SendWearChange(int material_slot) { + Mob *m = reinterpret_cast(d_); + m->SendWearChange(material_slot); +} + +uint32 Lua_Mob::GetEquipment(int material_slot) { + Mob *m = reinterpret_cast(d_); + return m->GetEquipment(material_slot); +} + +int32 Lua_Mob::GetEquipmentMaterial(int material_slot) { + Mob *m = reinterpret_cast(d_); + return m->GetEquipmentMaterial(material_slot); +} + +uint32 Lua_Mob::GetEquipmentColor(int material_slot) { + Mob *m = reinterpret_cast(d_); + return m->GetEquipmentColor(material_slot); +} + +uint32 Lua_Mob::GetArmorTint(int i) { + Mob *m = reinterpret_cast(d_); + return m->GetArmorTint(i); +} + +bool Lua_Mob::IsMoving() { + Mob *m = reinterpret_cast(d_); + return m->IsMoving(); +} + +void Lua_Mob::GotoBind() { + Mob *m = reinterpret_cast(d_); + m->GoToBind(); +} + +void Lua_Mob::Gate() { + Mob *m = reinterpret_cast(d_); + m->Gate(); +} + +bool Lua_Mob::Attack(Lua_Mob other) { + return Attack(other, 13, false, false, false); +} + +bool Lua_Mob::Attack(Lua_Mob other, int hand) { + return Attack(other, hand, false, false, false); +} + +bool Lua_Mob::Attack(Lua_Mob other, int hand, bool from_riposte) { + return Attack(other, hand, from_riposte, false, false); +} + +bool Lua_Mob::Attack(Lua_Mob other, int hand, bool from_riposte, bool is_strikethrough) { + return Attack(other, hand, from_riposte, is_strikethrough, false); +} + +bool Lua_Mob::Attack(Lua_Mob other, int hand, bool from_riposte, bool is_strikethrough, bool is_from_spell) { + Mob *m = reinterpret_cast(d_); + Mob *o = reinterpret_cast(other.d_); + return m->Attack(o, hand, from_riposte, is_strikethrough, is_from_spell); +} + +void Lua_Mob::Damage(Lua_Mob from, int damage, int spell_id, int attack_skill) { + Damage(from, damage, spell_id, attack_skill, true, -1, false); +} + +void Lua_Mob::Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, bool avoidable) { + Damage(from, damage, spell_id, attack_skill, avoidable, -1, false); +} + +void Lua_Mob::Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, bool avoidable, int buffslot) { + Damage(from, damage, spell_id, attack_skill, avoidable, buffslot, false); +} + +void Lua_Mob::Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, bool avoidable, int buffslot, bool buff_tic) { + Mob *m = reinterpret_cast(d_); + Mob *f = reinterpret_cast(from.d_); + m->Damage(f, damage, spell_id, static_cast(attack_skill), avoidable, buffslot, buff_tic); +} + +void Lua_Mob::RangedAttack(Lua_Mob other) { + Mob *m = reinterpret_cast(d_); + Mob *o = reinterpret_cast(other.d_); + m->RangedAttack(o); +} + +void Lua_Mob::ThrowingAttack(Lua_Mob other) { + Mob *m = reinterpret_cast(d_); + Mob *o = reinterpret_cast(other.d_); + m->ThrowingAttack(o); +} + +void Lua_Mob::Heal() { + Mob *m = reinterpret_cast(d_); + m->Heal(); +} + +void Lua_Mob::HealDamage(uint32 amount) { + Mob *m = reinterpret_cast(d_); + HealDamage(amount, Lua_Mob(nullptr)); +} + +void Lua_Mob::HealDamage(uint32 amount, Lua_Mob other) { + Mob *m = reinterpret_cast(d_); + Mob *o = reinterpret_cast(other.d_); + m->HealDamage(amount, o); +} + + #endif diff --git a/zone/lua_mob.h b/zone/lua_mob.h index 8c71a67ba..277688ee5 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -9,14 +9,43 @@ class Mob; class Lua_Mob : public Lua_Entity { public: - Lua_Mob() { } - Lua_Mob(Mob *d) { this->d_ = d; } + Lua_Mob() { d_ = nullptr; } + Lua_Mob(Mob *d) { d_ = d; } virtual ~Lua_Mob() { } const char *GetName(); void Depop(); void Depop(bool start_spawn_timer); + void RogueAssassinate(Lua_Mob other); + bool BehindMob(); + bool BehindMob(Lua_Mob other); + bool BehindMob(Lua_Mob other, float x); + bool BehindMob(Lua_Mob other, float x, float y); + void SetLevel(int level); + void SetLevel(int level, bool command); + void SendWearChange(int material_slot); + uint32 GetEquipment(int material_slot); + int32 GetEquipmentMaterial(int material_slot); + uint32 GetEquipmentColor(int material_slot); + uint32 GetArmorTint(int i); + bool IsMoving(); + void GotoBind(); + void Gate(); + bool Attack(Lua_Mob other); + bool Attack(Lua_Mob other, int hand); + bool Attack(Lua_Mob other, int hand, bool from_riposte); + bool Attack(Lua_Mob other, int hand, bool from_riposte, bool is_strikethrough); + bool Attack(Lua_Mob other, int hand, bool from_riposte, bool is_strikethrough, bool is_from_spell); + void Damage(Lua_Mob from, int damage, int spell_id, int attack_skill); + void Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, bool avoidable); + void Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, bool avoidable, int buffslot); + void Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, bool avoidable, int buffslot, bool buff_tic); + void RangedAttack(Lua_Mob other); + void ThrowingAttack(Lua_Mob other); + void Heal(); + void HealDamage(uint32 amount); + void HealDamage(uint32 amount, Lua_Mob other); }; #endif diff --git a/zone/lua_npc.cpp b/zone/lua_npc.cpp new file mode 100644 index 000000000..d95f79967 --- /dev/null +++ b/zone/lua_npc.cpp @@ -0,0 +1,8 @@ +#ifdef LUA_EQEMU + +#include "masterentity.h" +#include "lua_npc.h" + + + +#endif diff --git a/zone/lua_npc.h b/zone/lua_npc.h new file mode 100644 index 000000000..673c1af8f --- /dev/null +++ b/zone/lua_npc.h @@ -0,0 +1,18 @@ +#ifndef EQEMU_LUA_NPC_H +#define EQEMU_LUA_NPC_H +#ifdef LUA_EQEMU + +#include "lua_mob.h" + +class NPC; + +class Lua_NPC : public Lua_Mob +{ +public: + Lua_NPC() { d_ = nullptr; } + Lua_NPC(NPC *d) { d_ = d; } + virtual ~Lua_NPC() { } +}; + +#endif +#endif \ No newline at end of file diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 3c359f283..5e1a17ee8 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -4,14 +4,15 @@ #include #include -#include +#include "lua.hpp" #include #include -//#include #include "masterentity.h" #include "lua_entity.h" #include "lua_mob.h" +#include "lua_client.h" +#include "lua_npc.h" const char *LuaEvents[_LargestEventID] = { "event_say", @@ -101,12 +102,13 @@ double LuaParser::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string da } L = iter->second; - Lua_Entity ent(npc); + Lua_NPC l_npc(npc); try { - double val = luabind::call_function(L, LuaEvents[evt], ent); + double val = luabind::call_function(L, LuaEvents[evt], l_npc); return val; - } catch(std::exception) { + } catch(std::exception &ex) { + printf("%s\n", ex.what()); return 100.0; } @@ -303,6 +305,7 @@ void LuaParser::MapFunctions(lua_State *L) { luabind::module(L) [ luabind::class_("Entity") + .def(luabind::constructor<>()) .def("IsClient", &Lua_Entity::IsClient) .def("IsNPC", &Lua_Entity::IsNPC) .def("IsMob", &Lua_Entity::IsMob) @@ -315,11 +318,48 @@ void LuaParser::MapFunctions(lua_State *L) { .def("IsTrap", &Lua_Entity::IsTrap) .def("IsBeacon", &Lua_Entity::IsBeacon) .def("GetID", &Lua_Entity::GetID) + .def("CastToClient", &Lua_Entity::CastToClient) + .def("CastToNPC", &Lua_Entity::CastToNPC) .def("CastToMob", &Lua_Entity::CastToMob), - luabind::class_("Mob") + + luabind::class_("Mob") + .def(luabind::constructor<>()) .def("GetName", &Lua_Mob::GetName) .def("Depop", (void(Lua_Mob::*)(void))&Lua_Mob::Depop) .def("Depop", (void(Lua_Mob::*)(bool))&Lua_Mob::Depop) + .def("RogueAssassinate", &Lua_Mob::RogueAssassinate) + .def("BehindMob", (bool(Lua_Mob::*)(void))&Lua_Mob::BehindMob) + .def("BehindMob", (bool(Lua_Mob::*)(Lua_Mob))&Lua_Mob::BehindMob) + .def("BehindMob", (bool(Lua_Mob::*)(Lua_Mob,float))&Lua_Mob::BehindMob) + .def("BehindMob", (bool(Lua_Mob::*)(Lua_Mob,float,float))&Lua_Mob::BehindMob) + .def("SetLevel", (void(Lua_Mob::*)(int))&Lua_Mob::SetLevel) + .def("SetLevel", (void(Lua_Mob::*)(int,bool))&Lua_Mob::SetLevel) + .def("GetEquipment", &Lua_Mob::GetEquipment) + .def("GetEquipmentMaterial", &Lua_Mob::GetEquipmentMaterial) + .def("GetEquipmentColor", &Lua_Mob::GetEquipmentColor) + .def("GetArmorTint", &Lua_Mob::GetArmorTint) + .def("IsMoving", &Lua_Mob::IsMoving) + .def("GotoBind", &Lua_Mob::GotoBind) + .def("Attack", (bool(Lua_Mob::*)(Lua_Mob))&Lua_Mob::Attack) + .def("Attack", (bool(Lua_Mob::*)(Lua_Mob,int))&Lua_Mob::Attack) + .def("Attack", (bool(Lua_Mob::*)(Lua_Mob,int,bool))&Lua_Mob::Attack) + .def("Attack", (bool(Lua_Mob::*)(Lua_Mob,int,bool,bool))&Lua_Mob::Attack) + .def("Attack", (bool(Lua_Mob::*)(Lua_Mob,int,bool,bool,bool))&Lua_Mob::Attack) + .def("Damage", (void(Lua_Mob::*)(Lua_Mob,int,int,int))&Lua_Mob::Damage) + .def("Damage", (void(Lua_Mob::*)(Lua_Mob,int,int,int,bool))&Lua_Mob::Damage) + .def("Damage", (void(Lua_Mob::*)(Lua_Mob,int,int,int,bool,int))&Lua_Mob::Damage) + .def("Damage", (void(Lua_Mob::*)(Lua_Mob,int,int,int,bool,int,bool))&Lua_Mob::Damage) + .def("RangedAttack", &Lua_Mob::RangedAttack) + .def("ThrowingAttack", &Lua_Mob::ThrowingAttack) + .def("Heal", &Lua_Mob::Heal) + .def("HealDamage", (void(Lua_Mob::*)(uint32))&Lua_Mob::HealDamage) + .def("HealDamage", (void(Lua_Mob::*)(uint32,Lua_Mob))&Lua_Mob::HealDamage), + + luabind::class_("Client") + .def(luabind::constructor<>()), + + luabind::class_("NPC") + .def(luabind::constructor<>()) ]; } catch(std::exception &ex) {