Lua work on api - entity and mob, lots more to go

This commit is contained in:
KimLS 2013-05-11 13:51:57 -07:00
parent d1f7935ee2
commit fa908040ca
10 changed files with 292 additions and 13 deletions

View File

@ -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

8
zone/lua_client.cpp Normal file
View File

@ -0,0 +1,8 @@
#ifdef LUA_EQEMU
#include "masterentity.h"
#include "lua_client.h"
#endif

18
zone/lua_client.h Normal file
View File

@ -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

View File

@ -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<Entity*>(d_);
@ -64,6 +66,16 @@ int Lua_Entity::GetID() {
return ent->GetID();
}
Lua_Client Lua_Entity::CastToClient() {
Client *m = reinterpret_cast<Client*>(d_);
return Lua_Client(m);
}
Lua_NPC Lua_Entity::CastToNPC() {
NPC *m = reinterpret_cast<NPC*>(d_);
return Lua_NPC(m);
}
Lua_Mob Lua_Entity::CastToMob() {
Mob *m = reinterpret_cast<Mob*>(d_);
return Lua_Mob(m);

View File

@ -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();

View File

@ -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<Mob*>(d_);
Mob *o = reinterpret_cast<Mob*>(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<Mob*>(d_);
Mob *o = reinterpret_cast<Mob*>(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<Mob*>(d_);
m->SetLevel(level, command);
}
void Lua_Mob::SendWearChange(int material_slot) {
Mob *m = reinterpret_cast<Mob*>(d_);
m->SendWearChange(material_slot);
}
uint32 Lua_Mob::GetEquipment(int material_slot) {
Mob *m = reinterpret_cast<Mob*>(d_);
return m->GetEquipment(material_slot);
}
int32 Lua_Mob::GetEquipmentMaterial(int material_slot) {
Mob *m = reinterpret_cast<Mob*>(d_);
return m->GetEquipmentMaterial(material_slot);
}
uint32 Lua_Mob::GetEquipmentColor(int material_slot) {
Mob *m = reinterpret_cast<Mob*>(d_);
return m->GetEquipmentColor(material_slot);
}
uint32 Lua_Mob::GetArmorTint(int i) {
Mob *m = reinterpret_cast<Mob*>(d_);
return m->GetArmorTint(i);
}
bool Lua_Mob::IsMoving() {
Mob *m = reinterpret_cast<Mob*>(d_);
return m->IsMoving();
}
void Lua_Mob::GotoBind() {
Mob *m = reinterpret_cast<Mob*>(d_);
m->GoToBind();
}
void Lua_Mob::Gate() {
Mob *m = reinterpret_cast<Mob*>(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<Mob*>(d_);
Mob *o = reinterpret_cast<Mob*>(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<Mob*>(d_);
Mob *f = reinterpret_cast<Mob*>(from.d_);
m->Damage(f, damage, spell_id, static_cast<SkillType>(attack_skill), avoidable, buffslot, buff_tic);
}
void Lua_Mob::RangedAttack(Lua_Mob other) {
Mob *m = reinterpret_cast<Mob*>(d_);
Mob *o = reinterpret_cast<Mob*>(other.d_);
m->RangedAttack(o);
}
void Lua_Mob::ThrowingAttack(Lua_Mob other) {
Mob *m = reinterpret_cast<Mob*>(d_);
Mob *o = reinterpret_cast<Mob*>(other.d_);
m->ThrowingAttack(o);
}
void Lua_Mob::Heal() {
Mob *m = reinterpret_cast<Mob*>(d_);
m->Heal();
}
void Lua_Mob::HealDamage(uint32 amount) {
Mob *m = reinterpret_cast<Mob*>(d_);
HealDamage(amount, Lua_Mob(nullptr));
}
void Lua_Mob::HealDamage(uint32 amount, Lua_Mob other) {
Mob *m = reinterpret_cast<Mob*>(d_);
Mob *o = reinterpret_cast<Mob*>(other.d_);
m->HealDamage(amount, o);
}
#endif

View File

@ -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

8
zone/lua_npc.cpp Normal file
View File

@ -0,0 +1,8 @@
#ifdef LUA_EQEMU
#include "masterentity.h"
#include "lua_npc.h"
#endif

18
zone/lua_npc.h Normal file
View File

@ -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

View File

@ -4,14 +4,15 @@
#include <ctype.h>
#include <sstream>
#include <lua.hpp>
#include "lua.hpp"
#include <luabind/luabind.hpp>
#include <boost/any.hpp>
//#include <LuaBridge.h>
#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<double>(L, LuaEvents[evt], ent);
double val = luabind::call_function<double>(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_<Lua_Entity>("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_<Lua_Mob>("Mob")
luabind::class_<Lua_Mob, Lua_Entity>("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_<Lua_Client, Lua_Mob>("Client")
.def(luabind::constructor<>()),
luabind::class_<Lua_NPC, Lua_Mob>("NPC")
.def(luabind::constructor<>())
];
} catch(std::exception &ex) {