From 0e582eda82c7ebd16002dca7ac19288073a021b6 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sat, 29 Apr 2023 21:09:00 -0400 Subject: [PATCH] [Quest API] Add HasSpellEffect() to Perl/Lua (#3319) * [Quest API] Add HasSpellEffect() to Perl/Lua # Perl - Add `$mob->HasSpellEffect(effect_id)`. # Lua - Add `mob:HasSpellEffect(effect_id)`. # Notes - Allows operators to see if a Mob has an effect ID from any of their buffs. * Update mob.cpp --- zone/lua_mob.cpp | 6 ++++++ zone/lua_mob.h | 1 + zone/mob.cpp | 16 ++++++++-------- zone/perl_mob.cpp | 6 ++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index ab8b67a089..32c85c272f 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -3010,6 +3010,11 @@ luabind::object Lua_Mob::GetBuffSpellIDs(lua_State* L) { return t; } +bool Lua_Mob::HasSpellEffect(int effect_id) { + Lua_Safe_Call_Bool(); + return self->HasSpellEffect(effect_id); +} + luabind::scope lua_register_mob() { return luabind::class_("Mob") .def(luabind::constructor<>()) @@ -3350,6 +3355,7 @@ luabind::scope lua_register_mob() { .def("HasPet", (bool(Lua_Mob::*)(void))&Lua_Mob::HasPet) .def("HasProcs", &Lua_Mob::HasProcs) .def("HasShieldEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasShieldEquipped) + .def("HasSpellEffect", &Lua_Mob::HasSpellEffect) .def("HasTimer", &Lua_Mob::HasTimer) .def("HasTwoHandBluntEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasTwoHandBluntEquipped) .def("HasTwoHanderEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasTwoHanderEquipped) diff --git a/zone/lua_mob.h b/zone/lua_mob.h index e4fff10908..00532a8492 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -541,6 +541,7 @@ class Lua_Mob : public Lua_Entity void StopAllTimers(); void StopTimer(const char* timer_name); luabind::object GetBuffSpellIDs(lua_State* L); + bool HasSpellEffect(int effect_id); }; #endif diff --git a/zone/mob.cpp b/zone/mob.cpp index 69178d5814..b9dd4b2c37 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -6227,20 +6227,20 @@ FACTION_VALUE Mob::GetSpecialFactionCon(Mob* iOther) { bool Mob::HasSpellEffect(int effect_id) { - int i; + const auto buff_count = GetMaxTotalSlots(); + for (int i = 0; i < buff_count; i++) { + const auto spell_id = buffs[i].spellid; - int buff_count = GetMaxTotalSlots(); - for(i = 0; i < buff_count; i++) - { - if (!IsValidSpell(buffs[i].spellid)) { + if (!IsValidSpell(spell_id)) { continue; } - if (IsEffectInSpell(buffs[i].spellid, effect_id)) { - return(1); + if (IsEffectInSpell(spell_id, effect_id)) { + return true; } } - return(0); + + return false; } int Mob::GetSpecialAbility(int ability) diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index fc4cb634e3..9410c49055 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -2960,6 +2960,11 @@ perl::array Perl_Mob_GetBuffSpellIDs(Mob* self) return l; } +bool Perl_Mob_HasSpellEffect(Mob* self, int effect_id) +{ + return self->HasSpellEffect(effect_id); +} + void perl_register_mob() { perl::interpreter perl(PERL_GET_THX); @@ -3284,6 +3289,7 @@ void perl_register_mob() package.add("HasPet", &Perl_Mob_HasPet); package.add("HasProcs", &Perl_Mob_HasProcs); package.add("HasShieldEquipped", &Perl_Mob_HasShieldEquipped); + package.add("HasSpellEffect", &Perl_Mob_HasSpellEffect); package.add("HasTimer", &Perl_Mob_HasTimer); package.add("HasTwoHandBluntEquipped", &Perl_Mob_HasTwoHandBluntEquipped); package.add("HasTwoHanderEquipped", &Perl_Mob_HasTwoHanderEquipped);