mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
Spell Fizzle for < LDON expansions via lua_mod (#1118)
* [expansions] Create a Lua mod hook into Client::CheckFizzle() * Added expansions_combat.lua mod stub * Spell Fizzle as per TAKP formula
This commit is contained in:
@@ -485,6 +485,11 @@ int Lua_Client::GetRawSkill(int skill_id) {
|
||||
return self->GetRawSkill(static_cast<EQ::skills::SkillType>(skill_id));
|
||||
}
|
||||
|
||||
int Lua_Client::GetSkill(int skill_id) {
|
||||
Lua_Safe_Call_Int();
|
||||
return self->GetSkill(static_cast<EQ::skills::SkillType>(skill_id));
|
||||
}
|
||||
|
||||
bool Lua_Client::HasSkill(int skill_id) {
|
||||
Lua_Safe_Call_Bool();
|
||||
return self->HasSkill(static_cast<EQ::skills::SkillType>(skill_id));
|
||||
@@ -1730,6 +1735,7 @@ luabind::scope lua_register_client() {
|
||||
.def("IncreaseLanguageSkill", (void(Lua_Client::*)(int))&Lua_Client::IncreaseLanguageSkill)
|
||||
.def("IncreaseLanguageSkill", (void(Lua_Client::*)(int,int))&Lua_Client::IncreaseLanguageSkill)
|
||||
.def("GetRawSkill", (int(Lua_Client::*)(int))&Lua_Client::GetRawSkill)
|
||||
.def("GetSkill", (int(Lua_Client::*)(int))&Lua_Client::GetSkill)
|
||||
.def("HasSkill", (bool(Lua_Client::*)(int))&Lua_Client::HasSkill)
|
||||
.def("CanHaveSkill", (bool(Lua_Client::*)(int))&Lua_Client::CanHaveSkill)
|
||||
.def("SetSkill", (void(Lua_Client::*)(int,int))&Lua_Client::SetSkill)
|
||||
|
||||
@@ -122,6 +122,7 @@ public:
|
||||
void IncreaseLanguageSkill(int skill_id);
|
||||
void IncreaseLanguageSkill(int skill_id, int value);
|
||||
int GetRawSkill(int skill_id);
|
||||
int GetSkill(int skill_id);
|
||||
bool HasSkill(int skill_id);
|
||||
bool CanHaveSkill(int skill_id);
|
||||
void SetSkill(int skill_id, int value);
|
||||
|
||||
@@ -632,4 +632,59 @@ void LuaMod::GetExperienceForKill(Client *self, Mob *against, uint32 &returnValu
|
||||
}
|
||||
}
|
||||
|
||||
void LuaMod::CheckFizzle(Client *self, uint16 &spell_id, SPDat_Spell_Struct spell_struct, bool &returnValue, bool &ignoreDefault) {
|
||||
int start = lua_gettop(L);
|
||||
|
||||
try {
|
||||
if (!m_has_check_fizzle) {
|
||||
return;
|
||||
}
|
||||
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str());
|
||||
lua_getfield(L, -1, "CheckFizzle");
|
||||
|
||||
Lua_Client l_self(self);
|
||||
luabind::adl::object e = luabind::newtable(L);
|
||||
e["self"] = l_self;
|
||||
e["spell_id"] = spell_id;
|
||||
|
||||
e.push(L);
|
||||
|
||||
Lua_Spell l_spell(&spell_struct);
|
||||
auto l_spell_o = luabind::adl::object(L, l_spell);
|
||||
|
||||
l_spell_o.push(L);
|
||||
lua_setfield(L, -2, "spell");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0)) {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
parser_->AddError(error);
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lua_type(L, -1) == LUA_TTABLE) {
|
||||
luabind::adl::object ret(luabind::from_stack(L, -1));
|
||||
auto IgnoreDefaultObj = ret["IgnoreDefault"];
|
||||
if (luabind::type(IgnoreDefaultObj) == LUA_TBOOLEAN) {
|
||||
ignoreDefault = ignoreDefault || luabind::object_cast<bool>(IgnoreDefaultObj);
|
||||
}
|
||||
|
||||
auto returnValueObj = ret["ReturnValue"];
|
||||
if (luabind::type(returnValueObj) == LUA_TBOOLEAN) {
|
||||
returnValue = returnValue || luabind::object_cast<bool>(returnValueObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex) {
|
||||
parser_->AddError(ex.what());
|
||||
}
|
||||
|
||||
int end = lua_gettop(L);
|
||||
int n = end - start;
|
||||
if (n > 0) {
|
||||
lua_pop(L, n);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
void GetRequiredAAExperience(Client *self, uint32 &returnValue, bool &ignoreDefault);
|
||||
void GetEXPForLevel(Client *self, uint16 level, uint32 &returnValue, bool &ignoreDefault);
|
||||
void GetExperienceForKill(Client *self, Mob *against, uint32 &returnValue, bool &ignoreDefault);
|
||||
void CheckFizzle(Client *self, uint16 &spell_id, SPDat_Spell_Struct spell_struct, bool &returnValue, bool &ignoreDefault);
|
||||
private:
|
||||
LuaParser *parser_;
|
||||
lua_State *L;
|
||||
@@ -40,4 +41,5 @@ private:
|
||||
bool m_has_get_required_aa_experience;
|
||||
bool m_has_get_exp_for_level;
|
||||
bool m_has_get_experience_for_kill;
|
||||
bool m_has_check_fizzle;
|
||||
};
|
||||
|
||||
@@ -1377,4 +1377,13 @@ uint32 LuaParser::GetExperienceForKill(Client *self, Mob *against, bool &ignoreD
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool LuaParser::CheckFizzle(Client *self, uint16 &spell_id, SPDat_Spell_Struct spell_struct, bool &ignoreDefault)
|
||||
{
|
||||
bool retValue = false;
|
||||
for (auto &mod : mods_) {
|
||||
mod.CheckFizzle(self, spell_id, spell_struct, retValue, ignoreDefault);
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -99,6 +99,8 @@ public:
|
||||
uint32 GetRequiredAAExperience(Client *self, bool &ignoreDefault);
|
||||
uint32 GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault);
|
||||
uint32 GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault);
|
||||
bool CheckFizzle(Client *self, uint16 &spell_id, SPDat_Spell_Struct spell_struct, bool &ignoreDefault);
|
||||
|
||||
|
||||
private:
|
||||
LuaParser();
|
||||
|
||||
@@ -82,6 +82,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
||||
#include "string_ids.h"
|
||||
#include "worldserver.h"
|
||||
#include "fastmath.h"
|
||||
#include "lua_parser.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -734,6 +735,16 @@ bool Mob::CheckFizzle(uint16 spell_id)
|
||||
|
||||
bool Client::CheckFizzle(uint16 spell_id)
|
||||
{
|
||||
#ifdef LUA_EQEMU
|
||||
bool ignoreDefault = false;
|
||||
bool fizzle = LuaParser::Instance()->CheckFizzle(this, spell_id, spells[spell_id], ignoreDefault);
|
||||
|
||||
if (!fizzle) {
|
||||
return false;
|
||||
} else if (ignoreDefault) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
// GMs don't fizzle
|
||||
if (GetGM()) return(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user