Skip to content

Commit

Permalink
[Quest API] Add HasSpellEffect() to Perl/Lua (#3319)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
Kinglykrab authored Apr 30, 2023
1 parent 7eff6ad commit 0e582ed
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions zone/lua_mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<Lua_Mob, Lua_Entity>("Mob")
.def(luabind::constructor<>())
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions zone/lua_mob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions zone/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions zone/perl_mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0e582ed

Please sign in to comment.