From cf27f2bc883ea87824b1528b67ffc056b16e493b Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 29 Sep 2023 19:38:36 -0400 Subject: [PATCH] [Quest API] Add Caster ID Parameter to FindBuff in Perl/Lua (#3590) * [Quest API] Add Caster ID Parameter to FindBuff in Perl/Lua # Perl - Add `$mob->FindBuff(spell_id, caster_id)`. # Lua - Add `mob:FindBuff(spell_id, caster_id)`. # Notes - Allows operators to check if the spell ID is cast by a specific entity ID. - We don't use `Mob*` reference here since the mob may have died, left zone, etc. * Formatting. --- zone/lua_mob.cpp | 10 ++++++++-- zone/lua_mob.h | 3 ++- zone/mob.h | 2 +- zone/perl_mob.cpp | 8 +++++++- zone/spells.cpp | 12 ++++++++---- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 6c5b24c28..49dd21eee 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -315,11 +315,16 @@ void Lua_Mob::SetInvisible(int state) { self->SetInvisible(state); } -bool Lua_Mob::FindBuff(int spell_id) { +bool Lua_Mob::FindBuff(uint16 spell_id) { Lua_Safe_Call_Bool(); return self->FindBuff(spell_id); } +bool Lua_Mob::FindBuff(uint16 spell_id, uint16 caster_id) { + Lua_Safe_Call_Bool(); + return self->FindBuff(spell_id, caster_id); +} + uint16 Lua_Mob::FindBuffBySlot(int slot) { Lua_Safe_Call_Int(); return self->FindBuffBySlot(slot); @@ -3324,7 +3329,8 @@ luabind::scope lua_register_mob() { .def("Emote", &Lua_Mob::Emote) .def("EntityVariableExists", &Lua_Mob::EntityVariableExists) .def("FaceTarget", (void(Lua_Mob::*)(Lua_Mob))&Lua_Mob::FaceTarget) - .def("FindBuff", &Lua_Mob::FindBuff) + .def("FindBuff", (bool(Lua_Mob::*)(uint16))&Lua_Mob::FindBuff) + .def("FindBuff", (bool(Lua_Mob::*)(uint16,uint16))&Lua_Mob::FindBuff) .def("FindBuffBySlot", (uint16(Lua_Mob::*)(int))&Lua_Mob::FindBuffBySlot) .def("FindGroundZ", (double(Lua_Mob::*)(double,double))&Lua_Mob::FindGroundZ) .def("FindGroundZ", (double(Lua_Mob::*)(double,double,double))&Lua_Mob::FindGroundZ) diff --git a/zone/lua_mob.h b/zone/lua_mob.h index 36b0d7180..01293fd24 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -90,7 +90,8 @@ public: uint8 GetInvisibleUndeadLevel(); void SetSeeInvisibleLevel(uint8 invisible_level); void SetSeeInvisibleUndeadLevel(uint8 invisible_level); - bool FindBuff(int spell_id); + bool FindBuff(uint16 spell_id); + bool FindBuff(uint16 spell_id, uint16 caster_id); uint16 FindBuffBySlot(int slot); uint32 BuffCount(); uint32 BuffCount(bool is_beneficial); diff --git a/zone/mob.h b/zone/mob.h index bcd989049..68779cc53 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -466,7 +466,7 @@ public: void DamageShield(Mob* other, bool spell_ds = false); int32 RuneAbsorb(int64 damage, uint16 type); std::vector GetBuffSpellIDs(); - bool FindBuff(uint16 spell_id); + bool FindBuff(uint16 spell_id, uint16 caster_id = 0); uint16 FindBuffBySlot(int slot); uint32 BuffCount(bool is_beneficial = true, bool is_detrimental = true); bool FindType(uint16 type, bool bOffensive = false, uint16 threshold = 100); diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index b556a06fc..bc3dbbc78 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -362,6 +362,11 @@ bool Perl_Mob_FindBuff(Mob* self, uint16 spell_id) // @categories Spells and Dis return self->FindBuff(spell_id); } +bool Perl_Mob_FindBuff(Mob* self, uint16 spell_id, uint16 caster_id) // @categories Spells and Disciplines, Script Utility +{ + return self->FindBuff(spell_id, caster_id); +} + int Perl_Mob_FindBuffBySlot(Mob* self, int slot) // @categories Spells and Disciplines, Script Utility { return self->FindBuffBySlot(slot); @@ -3570,7 +3575,8 @@ void perl_register_mob() package.add("EntityVariableExists", &Perl_Mob_EntityVariableExists); package.add("FaceTarget", (void(*)(Mob*))&Perl_Mob_FaceTarget); package.add("FaceTarget", (void(*)(Mob*, Mob*))&Perl_Mob_FaceTarget); - package.add("FindBuff", &Perl_Mob_FindBuff); + package.add("FindBuff", (bool(*)(Mob*, uint16))&Perl_Mob_FindBuff); + package.add("FindBuff", (bool(*)(Mob*, uint16, uint16))&Perl_Mob_FindBuff); package.add("FindBuffBySlot", &Perl_Mob_FindBuffBySlot); package.add("FindGroundZ", (float(*)(Mob*, float, float))&Perl_Mob_FindGroundZ); package.add("FindGroundZ", (float(*)(Mob*, float, float, float))&Perl_Mob_FindGroundZ); diff --git a/zone/spells.cpp b/zone/spells.cpp index 1c335add1..faecbf48b 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -4411,14 +4411,18 @@ std::vector Mob::GetBuffSpellIDs() return l; } -bool Mob::FindBuff(uint16 spell_id) +bool Mob::FindBuff(uint16 spell_id, uint16 caster_id) { - uint32 buff_count = GetMaxTotalSlots(); + const int buff_count = GetMaxTotalSlots(); for (int buff_slot = 0; buff_slot < buff_count; buff_slot++) { - auto current_spell_id = buffs[buff_slot].spellid; + const uint16 current_spell_id = buffs[buff_slot].spellid; if ( IsValidSpell(current_spell_id) && - current_spell_id == spell_id + current_spell_id == spell_id && + ( + !caster_id || + buffs[buff_slot].casterid == caster_id + ) ) { return true; }