mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 06:21:28 +00:00
More lua work - changed how i get return values off the stack and do calls
This commit is contained in:
parent
fa908040ca
commit
70998d25e3
@ -13,6 +13,10 @@ class Lua_Mob;
|
||||
//class Lua_Trap;
|
||||
//class Lua_Beacon;
|
||||
|
||||
#define Lua_Safe_Cast(type, m, other) \
|
||||
type *m = nullptr; \
|
||||
m = reinterpret_cast<type*>(other.d_);
|
||||
|
||||
class Lua_Entity
|
||||
{
|
||||
public:
|
||||
|
||||
@ -19,12 +19,12 @@ void Lua_Mob::Depop(bool start_spawn_timer) {
|
||||
|
||||
void Lua_Mob::RogueAssassinate(Lua_Mob other) {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
Mob *o = reinterpret_cast<Mob*>(other.d_);
|
||||
Lua_Safe_Cast(Mob, o, other);
|
||||
m->RogueAssassinate(o);
|
||||
}
|
||||
|
||||
bool Lua_Mob::BehindMob() {
|
||||
return BehindMob(Lua_Mob(nullptr), 0.0f, 0.0f);
|
||||
return BehindMob(nullptr, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
bool Lua_Mob::BehindMob(Lua_Mob other) {
|
||||
@ -37,7 +37,7 @@ bool Lua_Mob::BehindMob(Lua_Mob other, float x) {
|
||||
|
||||
bool Lua_Mob::BehindMob(Lua_Mob other, float x, float y) {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
Mob *o = reinterpret_cast<Mob*>(other.d_);
|
||||
Lua_Safe_Cast(Mob, o, other);
|
||||
return m->BehindMob(o, x, y);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ bool Lua_Mob::Attack(Lua_Mob other, int hand, bool from_riposte, bool is_striket
|
||||
|
||||
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_);
|
||||
Lua_Safe_Cast(Mob, o, other);
|
||||
return m->Attack(o, hand, from_riposte, is_strikethrough, is_from_spell);
|
||||
}
|
||||
|
||||
@ -126,19 +126,19 @@ void Lua_Mob::Damage(Lua_Mob from, int damage, int spell_id, int attack_skill, b
|
||||
|
||||
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_);
|
||||
Lua_Safe_Cast(Mob, f, from);
|
||||
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_);
|
||||
Lua_Safe_Cast(Mob, o, other);
|
||||
m->RangedAttack(o);
|
||||
}
|
||||
|
||||
void Lua_Mob::ThrowingAttack(Lua_Mob other) {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
Mob *o = reinterpret_cast<Mob*>(other.d_);
|
||||
Lua_Safe_Cast(Mob, o, other);
|
||||
m->ThrowingAttack(o);
|
||||
}
|
||||
|
||||
@ -149,12 +149,12 @@ void Lua_Mob::Heal() {
|
||||
|
||||
void Lua_Mob::HealDamage(uint32 amount) {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
HealDamage(amount, Lua_Mob(nullptr));
|
||||
HealDamage(amount, nullptr);
|
||||
}
|
||||
|
||||
void Lua_Mob::HealDamage(uint32 amount, Lua_Mob other) {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
Mob *o = reinterpret_cast<Mob*>(other.d_);
|
||||
Lua_Safe_Cast(Mob, o, other);
|
||||
m->HealDamage(amount, o);
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,96 @@ public:
|
||||
void Heal();
|
||||
void HealDamage(uint32 amount);
|
||||
void HealDamage(uint32 amount, Lua_Mob other);
|
||||
|
||||
//uint32 GetLevelCon(int other);
|
||||
//uint32 GetLevelCon(int my, int other);
|
||||
//void SetHP(int hp);
|
||||
//void DoAnim(int anim_num);
|
||||
//void DoAnim(int anim_num, int type);
|
||||
//void DoAnim(int anim_num, int type, bool ackreq);
|
||||
//void DoAnim(int anim_num, int type, bool ackreq, eqFilterType filter);
|
||||
//void ChangeSize(float in_size);
|
||||
//void ChangeSize(float in_size, bool no_restriction);
|
||||
//void GMMove(float x, float y, float z);
|
||||
//void GMMove(float x, float y, float z, float heading);
|
||||
//void GMMove(float x, float y, float z, float heading, bool SendUpdate);
|
||||
//void SendPosUpdate();
|
||||
//void SendPosUpdate(bool send_to_self);
|
||||
//void SendPosition();
|
||||
//bool HasProcs();
|
||||
//bool IsInvisible();
|
||||
//bool IsInvisible(Lua_Mob other);
|
||||
//void SetInvisible(int state);
|
||||
//bool FindBuff(uint16 spell_id);
|
||||
//bool FindType(uint16 type);
|
||||
//bool FindType(uint16 type, bool bOffensive);
|
||||
//bool FindType(uint16 type, bool bOffensive, uint16 threshold);
|
||||
//int GetBuffSlotFromType(int slot);
|
||||
//void MakePet(int spell_id, const char* pet_type);
|
||||
//void MakePet(int spell_id, const char* pet_type, const char *pet_name);
|
||||
//void MakePoweredPet(int spell_id, const char* pet_type);
|
||||
//void MakePoweredPet(int spell_id, const char* pet_type, int pet_power);
|
||||
//void MakePoweredPet(int spell_id, const char* pet_type, int pet_power, const char *pet_name);
|
||||
//int GetBaseRace();
|
||||
//int GetBaseGender();
|
||||
//int GetDeity();
|
||||
//int GetRace();
|
||||
//int GetGender();
|
||||
//int GetTexture();
|
||||
//int GetHelmTexture();
|
||||
//int GetHairColor();
|
||||
//int GetBeardColor();
|
||||
//int GetEyeColor1();
|
||||
//int GetEyeColor2();
|
||||
//int GetHairStyle();
|
||||
//int GetLuclinFace();
|
||||
//int GetBeard();
|
||||
//int GetDrakkinHeritage();
|
||||
//int GetDrakkinTattoo();
|
||||
//int GetDrakkinDetails();
|
||||
//int GetClass();
|
||||
//int GetLevel();
|
||||
//const char *GetCleanName();
|
||||
//Lua_Mob GetTarget();
|
||||
//void SetTarget(Lua_Mob t);
|
||||
/*
|
||||
|
||||
"GetHPRatio"), XS_Mob_GetHPRatio, file, "$");
|
||||
"IsWarriorClass"), XS_Mob_IsWarriorClass, file, "$");
|
||||
"GetHP"), XS_Mob_GetHP, file, "$");
|
||||
"GetMaxHP"), XS_Mob_GetMaxHP, file, "$");
|
||||
"GetItemHPBonuses"), XS_Mob_GetItemHPBonuses, file, "$");
|
||||
"GetSpellHPBonuses"), XS_Mob_GetSpellHPBonuses, file, "$");
|
||||
"GetWalkspeed"), XS_Mob_GetWalkspeed, file, "$");
|
||||
"GetRunspeed"), XS_Mob_GetRunspeed, file, "$");
|
||||
"GetCasterLevel"), XS_Mob_GetCasterLevel, file, "$$");
|
||||
"GetMaxMana"), XS_Mob_GetMaxMana, file, "$");
|
||||
"GetMana"), XS_Mob_GetMana, file, "$");
|
||||
"SetMana"), XS_Mob_SetMana, file, "$$");
|
||||
"GetManaRatio"), XS_Mob_GetManaRatio, file, "$");
|
||||
"GetAC"), XS_Mob_GetAC, file, "$");
|
||||
"GetATK"), XS_Mob_GetATK, file, "$");
|
||||
"GetSTR"), XS_Mob_GetSTR, file, "$");
|
||||
"GetSTA"), XS_Mob_GetSTA, file, "$");
|
||||
"GetDEX"), XS_Mob_GetDEX, file, "$");
|
||||
"GetAGI"), XS_Mob_GetAGI, file, "$");
|
||||
"GetINT"), XS_Mob_GetINT, file, "$");
|
||||
"GetWIS"), XS_Mob_GetWIS, file, "$");
|
||||
"GetCHA"), XS_Mob_GetCHA, file, "$");
|
||||
"GetMR"), XS_Mob_GetMR, file, "$");
|
||||
"GetFR"), XS_Mob_GetFR, file, "$");
|
||||
"GetDR"), XS_Mob_GetDR, file, "$");
|
||||
"GetPR"), XS_Mob_GetPR, file, "$");
|
||||
"GetCR"), XS_Mob_GetCR, file, "$");
|
||||
"GetCorruption"), XS_Mob_GetCR, file, "$");
|
||||
"GetMaxSTR"), XS_Mob_GetMaxSTR, file, "$");
|
||||
"GetMaxSTA"), XS_Mob_GetMaxSTA, file, "$");
|
||||
"GetMaxDEX"), XS_Mob_GetMaxDEX, file, "$");
|
||||
"GetMaxAGI"), XS_Mob_GetMaxAGI, file, "$");
|
||||
"GetMaxINT"), XS_Mob_GetMaxINT, file, "$");
|
||||
"GetMaxWIS"), XS_Mob_GetMaxWIS, file, "$");
|
||||
"GetMaxCHA"), XS_Mob_GetMaxCHA, file, "$");
|
||||
*/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -92,6 +92,11 @@ double LuaParser::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string da
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
const char *sub_name = LuaEvents[evt];
|
||||
if(!HasQuestSub(npc->GetNPCTypeID(), sub_name)) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
std::stringstream package_name;
|
||||
package_name << "npc_" << npc->GetNPCTypeID();
|
||||
|
||||
@ -101,17 +106,42 @@ double LuaParser::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string da
|
||||
return 100.0;
|
||||
}
|
||||
L = iter->second;
|
||||
|
||||
|
||||
Lua_NPC l_npc(npc);
|
||||
|
||||
try {
|
||||
double val = luabind::call_function<double>(L, LuaEvents[evt], l_npc);
|
||||
return val;
|
||||
luabind::object l_npc_o = luabind::object(L, l_npc);
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, sub_name);
|
||||
int arg_count = 1;
|
||||
int ret_count = 1;
|
||||
|
||||
l_npc_o.push(L);
|
||||
if(lua_pcall(L, arg_count, ret_count, 0)) {
|
||||
printf("Error: %s\n", lua_tostring(L, -1));
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
if(lua_isnumber(L, -1)) {
|
||||
double ret = lua_tonumber(L, -1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} catch(std::exception &ex) {
|
||||
printf("%s\n", ex.what());
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
|
||||
//try {
|
||||
// double val = luabind::call_function<double>(L, LuaEvents[evt], l_npc);
|
||||
// return val;
|
||||
//} catch(std::exception &ex) {
|
||||
// if(strcmp(ex.what(), "unable to make cast") != 0) {
|
||||
// printf("%s\n", ex.what());
|
||||
// }
|
||||
// return 100.0;
|
||||
//}
|
||||
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user