[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
This commit is contained in:
Alex King 2023-04-29 21:09:00 -04:00 committed by GitHub
parent 7eff6ada87
commit 0e582eda82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 8 deletions

View File

@ -3010,6 +3010,11 @@ luabind::object Lua_Mob::GetBuffSpellIDs(lua_State* L) {
return t; return t;
} }
bool Lua_Mob::HasSpellEffect(int effect_id) {
Lua_Safe_Call_Bool();
return self->HasSpellEffect(effect_id);
}
luabind::scope lua_register_mob() { luabind::scope lua_register_mob() {
return luabind::class_<Lua_Mob, Lua_Entity>("Mob") return luabind::class_<Lua_Mob, Lua_Entity>("Mob")
.def(luabind::constructor<>()) .def(luabind::constructor<>())
@ -3350,6 +3355,7 @@ luabind::scope lua_register_mob() {
.def("HasPet", (bool(Lua_Mob::*)(void))&Lua_Mob::HasPet) .def("HasPet", (bool(Lua_Mob::*)(void))&Lua_Mob::HasPet)
.def("HasProcs", &Lua_Mob::HasProcs) .def("HasProcs", &Lua_Mob::HasProcs)
.def("HasShieldEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasShieldEquipped) .def("HasShieldEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasShieldEquipped)
.def("HasSpellEffect", &Lua_Mob::HasSpellEffect)
.def("HasTimer", &Lua_Mob::HasTimer) .def("HasTimer", &Lua_Mob::HasTimer)
.def("HasTwoHandBluntEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasTwoHandBluntEquipped) .def("HasTwoHandBluntEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasTwoHandBluntEquipped)
.def("HasTwoHanderEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasTwoHanderEquipped) .def("HasTwoHanderEquipped", (bool(Lua_Mob::*)(void))&Lua_Mob::HasTwoHanderEquipped)

View File

@ -541,6 +541,7 @@ public:
void StopAllTimers(); void StopAllTimers();
void StopTimer(const char* timer_name); void StopTimer(const char* timer_name);
luabind::object GetBuffSpellIDs(lua_State* L); luabind::object GetBuffSpellIDs(lua_State* L);
bool HasSpellEffect(int effect_id);
}; };
#endif #endif

View File

@ -6227,20 +6227,20 @@ FACTION_VALUE Mob::GetSpecialFactionCon(Mob* iOther) {
bool Mob::HasSpellEffect(int effect_id) 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(); if (!IsValidSpell(spell_id)) {
for(i = 0; i < buff_count; i++)
{
if (!IsValidSpell(buffs[i].spellid)) {
continue; continue;
} }
if (IsEffectInSpell(buffs[i].spellid, effect_id)) { if (IsEffectInSpell(spell_id, effect_id)) {
return(1); return true;
} }
} }
return(0);
return false;
} }
int Mob::GetSpecialAbility(int ability) int Mob::GetSpecialAbility(int ability)

View File

@ -2960,6 +2960,11 @@ perl::array Perl_Mob_GetBuffSpellIDs(Mob* self)
return l; return l;
} }
bool Perl_Mob_HasSpellEffect(Mob* self, int effect_id)
{
return self->HasSpellEffect(effect_id);
}
void perl_register_mob() void perl_register_mob()
{ {
perl::interpreter perl(PERL_GET_THX); perl::interpreter perl(PERL_GET_THX);
@ -3284,6 +3289,7 @@ void perl_register_mob()
package.add("HasPet", &Perl_Mob_HasPet); package.add("HasPet", &Perl_Mob_HasPet);
package.add("HasProcs", &Perl_Mob_HasProcs); package.add("HasProcs", &Perl_Mob_HasProcs);
package.add("HasShieldEquipped", &Perl_Mob_HasShieldEquipped); package.add("HasShieldEquipped", &Perl_Mob_HasShieldEquipped);
package.add("HasSpellEffect", &Perl_Mob_HasSpellEffect);
package.add("HasTimer", &Perl_Mob_HasTimer); package.add("HasTimer", &Perl_Mob_HasTimer);
package.add("HasTwoHandBluntEquipped", &Perl_Mob_HasTwoHandBluntEquipped); package.add("HasTwoHandBluntEquipped", &Perl_Mob_HasTwoHandBluntEquipped);
package.add("HasTwoHanderEquipped", &Perl_Mob_HasTwoHanderEquipped); package.add("HasTwoHanderEquipped", &Perl_Mob_HasTwoHanderEquipped);