Skip to content

Commit

Permalink
feat(Unit/Misc): HasAnyAuras() HasAllAuras() HasAuras() (azerothcore#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitzunu authored Dec 26, 2024
1 parent aa24f50 commit bff594c
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate, bool isLFGReward)
// Favored experience increase START
uint32 zone = GetZoneId();
float favored_exp_mult = 0;
if ((zone == 3483 || zone == 3562 || zone == 3836 || zone == 3713 || zone == 3714) && (HasAura(32096) || HasAura(32098)))
if ((zone == 3483 || zone == 3562 || zone == 3836 || zone == 3713 || zone == 3714) && HasAnyAuras(32096 /*Thrallmar's Favor*/, 32098 /*Honor Hold's Favor*/))
favored_exp_mult = 0.05f; // Thrallmar's Favor and Honor Hold's Favor

xp = uint32(xp * (1 + favored_exp_mult));
Expand Down
23 changes: 23 additions & 0 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5695,6 +5695,29 @@ uint32 Unit::GetAuraCount(uint32 spellId) const
return count;
}

bool Unit::HasAuras(SearchMethod sm, std::vector<uint32>& spellIds) const
{
if (sm == SearchMethod::MatchAll)
{
for (auto const& spellId : spellIds)
if (!HasAura(spellId))
return false;
return true;
}
else if (sm == SearchMethod::MatchAny)
{
for (auto const& spellId : spellIds)
if (HasAura(spellId))
return true;
return false;
}
else
{
LOG_ERROR("entities.unit", "Unit::HasAuras using non-supported SearchMethod {}", sm);
return false;
}
}

bool Unit::HasAura(uint32 spellId, ObjectGuid casterGUID, ObjectGuid itemCasterGUID, uint8 reqEffMask) const
{
if (GetAuraApplication(spellId, casterGUID, itemCasterGUID, reqEffMask))
Expand Down
50 changes: 50 additions & 0 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ enum CommandStates : uint8
COMMAND_ABANDON = 3
};

enum class SearchMethod
{
MatchAll,
MatchAny
};

typedef std::list<Player*> SharedVisionList;

struct AttackPosition {
Expand Down Expand Up @@ -1367,6 +1373,50 @@ class Unit : public WorldObject

[[nodiscard]] bool HasAuraEffect(uint32 spellId, uint8 effIndex, ObjectGuid caster = ObjectGuid::Empty) const;
[[nodiscard]] uint32 GetAuraCount(uint32 spellId) const;

/**
* @brief Check if unit has ANY or ALL specified auras.
*
* @param sm The search method to use
* - SearchMethod::MatchAll : The function checks for all of the spell id's on the unit.
* - SearchMethod::MatchAny : The function checks for any of the spell id's on the unit.
*
* @param spellIds List of spell id's to check for on the unit.
*
* @return Returns true if the search method condition is met. Otherwise false.
*/
bool HasAuras(SearchMethod sm, std::vector<uint32>& spellIds) const;

/**
* @brief Checks if the unit has ANY specified auras.
*
* @tparam Auras Can be any type convertible to uint32.
* @param spellIds List of spell id's to check for on the unit.
*
* @return Returns true if the unit has ANY of the specified auras. Otherwise false.
*/
template <typename... Auras>
bool HasAnyAuras(Auras... spellIds) const
{
std::vector<uint32> spellList = { static_cast<uint32>(spellIds)... };
return HasAuras(SearchMethod::MatchAny, spellList);
}

/**
* @brief Checks if the unit has ALL specified auras.
*
* @tparam Auras Can be any type convertible to uint32.
* @param spellIds List of spell id's to check for on the unit.
*
* @return Returns true if the unit has ALL of the specified auras. Otherwise false.
*/
template <typename... Auras>
bool HasAllAuras(Auras... spellIds) const
{
std::vector<uint32> spellList = { static_cast<uint32>(spellIds)... };
return HasAuras(SearchMethod::MatchAll, spellList);
}

[[nodiscard]] bool HasAura(uint32 spellId, ObjectGuid casterGUID = ObjectGuid::Empty, ObjectGuid itemCasterGUID = ObjectGuid::Empty, uint8 reqEffMask = 0) const;
[[nodiscard]] bool HasAuraType(AuraType auraType) const;
[[nodiscard]] bool HasAuraTypeWithCaster(AuraType auratype, ObjectGuid caster) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,8 @@ class boss_chromaggus : public CreatureScript
{
DoCast(player, afflictionSpellID, true);

if (player->HasAura(SPELL_BROODAF_BLUE) && player->HasAura(SPELL_BROODAF_BLACK) && player->HasAura(SPELL_BROODAF_RED) &&
player->HasAura(SPELL_BROODAF_BRONZE) && player->HasAura(SPELL_BROODAF_GREEN))
{
if (player->HasAllAuras(SPELL_BROODAF_BLUE, SPELL_BROODAF_BLACK, SPELL_BROODAF_RED, SPELL_BROODAF_BRONZE, SPELL_BROODAF_GREEN))
DoCast(player, SPELL_CHROMATIC_MUT_1);
}
}
}
events.ScheduleEvent(EVENT_AFFLICTION, 10s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class spell_mutate_explode_bug : public SpellScript
if (target->GetEntry() != NPC_QIRAJI_SCARAB && target->GetEntry() != NPC_QIRAJI_SCORPION)
return true;
if (Creature const* creature = target->ToCreature())
if (creature->HasAura(SPELL_EXPLODE_BUG) || creature->HasAura(SPELL_MUTATE_BUG))
if (creature->HasAnyAuras(SPELL_EXPLODE_BUG, SPELL_MUTATE_BUG))
return true;

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/Kalimdor/zone_desolace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class npc_aged_dying_ancient_kodo : public CreatureScript
{
if (spell->Id == SPELL_KODO_KOMBO_ITEM)
{
if (!(caster->HasAura(SPELL_KODO_KOMBO_PLAYER_BUFF) || me->HasAura(SPELL_KODO_KOMBO_DESPAWN_BUFF))
if (!caster->HasAnyAuras(SPELL_KODO_KOMBO_PLAYER_BUFF, SPELL_KODO_KOMBO_DESPAWN_BUFF)
&& (me->GetEntry() == NPC_AGED_KODO || me->GetEntry() == NPC_DYING_KODO || me->GetEntry() == NPC_ANCIENT_KODO))
{
me->UpdateEntry(NPC_TAMED_KODO, nullptr, false);
Expand All @@ -494,7 +494,7 @@ class npc_aged_dying_ancient_kodo : public CreatureScript

bool OnGossipHello(Player* player, Creature* creature) override
{
if (player->HasAura(SPELL_KODO_KOMBO_PLAYER_BUFF) && creature->HasAura(SPELL_KODO_KOMBO_DESPAWN_BUFF))
if (player->HasAllAuras(SPELL_KODO_KOMBO_PLAYER_BUFF, SPELL_KODO_KOMBO_DESPAWN_BUFF))
{
player->TalkedToCreature(creature->GetEntry(), ObjectGuid::Empty);
player->RemoveAurasDueToSpell(SPELL_KODO_KOMBO_PLAYER_BUFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct LastPhaseIceTombTargetSelector
if (target->HasAura(SPELL_FROST_IMBUED_BLADE))
return false;

if (target->IsImmunedToDamageOrSchool(SPELL_SCHOOL_MASK_ALL) || target->HasAura(SPELL_ICE_TOMB_UNTARGETABLE) || target->HasAura(SPELL_ICE_TOMB_DAMAGE) || target->HasAura(SPELL_TANK_MARKER_AURA) || target->HasSpiritOfRedemptionAura())
if (target->IsImmunedToDamageOrSchool(SPELL_SCHOOL_MASK_ALL) || target->HasAnyAuras(SPELL_ICE_TOMB_UNTARGETABLE, SPELL_ICE_TOMB_DAMAGE, SPELL_TANK_MARKER_AURA) || target->HasSpiritOfRedemptionAura())
return false;

return target != _source->GetVictim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ struct DefileTargetSelector
return false;
if (_source->GetExactDist(target) > 100.0f)
return false;
if (target->HasAura(SPELL_HARVEST_SOUL_VALKYR) || target->HasAura(SPELL_VALKYR_TARGET_SEARCH))
if (target->HasAnyAuras(SPELL_HARVEST_SOUL_VALKYR, SPELL_VALKYR_TARGET_SEARCH))
return false;
if (!_source->IsWithinLOSInMap(target))
return false;
Expand Down Expand Up @@ -603,7 +603,7 @@ class NecroticPlagueTargetCheck
{
if (!unit || !unit->IsPlayer() || unit == _sourceObj || _sourceObj->GetVictim() == unit || !unit->isTargetableForAttack())
return false;
if (unit->HasAura(SPELL_PLAGUE_AVOIDANCE) || unit->HasAura(SPELL_BOSS_HITTIN_YA_AURA) || unit->HasAura(_notAura1) || unit->HasAura(_notAura2))
if (unit->HasAnyAuras(SPELL_PLAGUE_AVOIDANCE, SPELL_BOSS_HITTIN_YA_AURA, _notAura1, _notAura2))
return false;
if (!_sourceObj->IsWithinLOSInMap(unit))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ class npc_alchemist_adrianna : public CreatureScript
{
if (InstanceScript* instance = creature->GetInstanceScript())
if (instance->GetBossState(DATA_ROTFACE) == DONE && instance->GetBossState(DATA_FESTERGUT) == DONE && !creature->FindCurrentSpellBySpellId(SPELL_HARVEST_BLIGHT_SPECIMEN) && !creature->FindCurrentSpellBySpellId(SPELL_HARVEST_BLIGHT_SPECIMEN25))
if (player->HasAura(SPELL_ORANGE_BLIGHT_RESIDUE) && player->HasAura(SPELL_GREEN_BLIGHT_RESIDUE))
if (player->HasAllAuras(SPELL_ORANGE_BLIGHT_RESIDUE, SPELL_GREEN_BLIGHT_RESIDUE))
creature->CastSpell(creature, SPELL_HARVEST_BLIGHT_SPECIMEN, false);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Northrend/Nexus/Oculus/boss_eregos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class boss_eregos : public CreatureScript
if (!UpdateVictim())
return;

if (me->HasAura(SPELL_PLANAR_SHIFT) || me->HasAura(SPELL_DRAKE_STOP_TIME))
if (me->HasAnyAuras(SPELL_PLANAR_SHIFT, SPELL_DRAKE_STOP_TIME))
return;

events.Update(diff);
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/Northrend/Ulduar/Ulduar/boss_hodir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ class achievement_staying_buffed_all_winter_10 : public AchievementCriteriaScrip

bool OnCheck(Player* player, Unit* /*target*/, uint32 /*criteria_id*/) override
{
return player && player->HasAura(SPELL_MAGE_TOASTY_FIRE_AURA) && player->HasAura(SPELL_DRUID_STARLIGHT_AREA_AURA) && player->HasAura(SPELL_SHAMAN_STORM_POWER_10);
return player && player->HasAllAuras(SPELL_MAGE_TOASTY_FIRE_AURA, SPELL_DRUID_STARLIGHT_AREA_AURA, SPELL_SHAMAN_STORM_POWER_10);
}
};

Expand All @@ -1538,7 +1538,7 @@ class achievement_staying_buffed_all_winter_25 : public AchievementCriteriaScrip

bool OnCheck(Player* player, Unit* /*target*/, uint32 /*criteria_id*/) override
{
return player && player->HasAura(SPELL_MAGE_TOASTY_FIRE_AURA) && player->HasAura(SPELL_DRUID_STARLIGHT_AREA_AURA) && player->HasAura(SPELL_SHAMAN_STORM_POWER_25);
return player && player->HasAllAuras(SPELL_MAGE_TOASTY_FIRE_AURA, SPELL_DRUID_STARLIGHT_AREA_AURA, SPELL_SHAMAN_STORM_POWER_25);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/server/scripts/Northrend/zone_dalaran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,7 @@ class npc_mageguard_dalaran : public CreatureScript

if (!player || player->IsGameMaster() || player->IsBeingTeleported() || (player->GetPositionZ() > 670 && player->GetVehicle()) ||
// If player has Disguise aura for quest A Meeting With The Magister or An Audience With The Arcanist, do not teleport it away but let it pass
player->HasAura(SPELL_SUNREAVER_DISGUISE_FEMALE) || player->HasAura(SPELL_SUNREAVER_DISGUISE_MALE) ||
player->HasAura(SPELL_SILVER_COVENANT_DISGUISE_FEMALE) || player->HasAura(SPELL_SILVER_COVENANT_DISGUISE_MALE))
player->HasAnyAuras(SPELL_SUNREAVER_DISGUISE_FEMALE, SPELL_SUNREAVER_DISGUISE_MALE, SPELL_SILVER_COVENANT_DISGUISE_FEMALE, SPELL_SILVER_COVENANT_DISGUISE_MALE))
return;

switch (me->GetEntry())
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Northrend/zone_icecrown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ class npc_guardian_pavilion : public CreatureScript
if (!who || !who->IsPlayer() || !me->IsHostileTo(who) || !me->isInBackInMap(who, 5.0f))
return;

if (who->HasAura(SPELL_TRESPASSER_H) || who->HasAura(SPELL_TRESPASSER_A))
if (who->HasAnyAuras(SPELL_TRESPASSER_H, SPELL_TRESPASSER_A))
return;

if (who->ToPlayer()->GetTeamId() == TEAM_ALLIANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class go_manticron_cube : public GameObjectScript

bool OnGossipHello(Player* player, GameObject* /*go*/) override
{
if (player->HasAura(SPELL_MIND_EXHAUSTION) || player->HasAura(SPELL_SHADOW_GRASP))
if (player->HasAnyAuras(SPELL_MIND_EXHAUSTION, SPELL_SHADOW_GRASP))
return true;

if (Creature* trigger = player->FindNearestCreature(NPC_HELLFIRE_RAID_TRIGGER, 10.0f))
Expand Down
6 changes: 3 additions & 3 deletions src/server/scripts/Spells/spell_dk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ class spell_dk_improved_blood_presence : public AuraScript
void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
Unit* target = GetTarget();
if ((target->HasAura(SPELL_DK_FROST_PRESENCE) || target->HasAura(SPELL_DK_UNHOLY_PRESENCE)) && !target->HasAura(SPELL_DK_IMPROVED_BLOOD_PRESENCE_TRIGGERED))
if (target->HasAnyAuras(SPELL_DK_FROST_PRESENCE, SPELL_DK_UNHOLY_PRESENCE) && !target->HasAura(SPELL_DK_IMPROVED_BLOOD_PRESENCE_TRIGGERED))
target->CastCustomSpell(SPELL_DK_IMPROVED_BLOOD_PRESENCE_TRIGGERED, SPELLVALUE_BASE_POINT1, aurEff->GetAmount(), target, true, nullptr, aurEff);
}

Expand Down Expand Up @@ -1655,7 +1655,7 @@ class spell_dk_improved_frost_presence : public AuraScript
void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
Unit* target = GetTarget();
if ((target->HasAura(SPELL_DK_BLOOD_PRESENCE) || target->HasAura(SPELL_DK_UNHOLY_PRESENCE)) && !target->HasAura(SPELL_DK_FROST_PRESENCE_TRIGGERED))
if (target->HasAnyAuras(SPELL_DK_BLOOD_PRESENCE, SPELL_DK_UNHOLY_PRESENCE) && !target->HasAura(SPELL_DK_FROST_PRESENCE_TRIGGERED))
target->CastCustomSpell(SPELL_DK_FROST_PRESENCE_TRIGGERED, SPELLVALUE_BASE_POINT0, aurEff->GetAmount(), target, true, nullptr, aurEff);
}

Expand Down Expand Up @@ -1700,7 +1700,7 @@ class spell_dk_improved_unholy_presence : public AuraScript
target->CastCustomSpell(target, SPELL_DK_IMPROVED_UNHOLY_PRESENCE_TRIGGERED, &basePoints, &basePoints, &basePoints, true, nullptr, aurEff);
}

if ((target->HasAura(SPELL_DK_BLOOD_PRESENCE) || target->HasAura(SPELL_DK_FROST_PRESENCE)) && !target->HasAura(SPELL_DK_UNHOLY_PRESENCE_TRIGGERED))
if (target->HasAnyAuras(SPELL_DK_BLOOD_PRESENCE, SPELL_DK_FROST_PRESENCE) && !target->HasAura(SPELL_DK_UNHOLY_PRESENCE_TRIGGERED))
target->CastCustomSpell(SPELL_DK_UNHOLY_PRESENCE_TRIGGERED, SPELLVALUE_BASE_POINT0, aurEff->GetAmount(), target, true, nullptr, aurEff);
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Spells/spell_paladin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ class spell_pal_lay_on_hands : public SpellScript
Unit* caster = GetCaster();
if (Unit* target = GetExplTargetUnit())
if (caster == target)
if (target->HasAura(SPELL_PALADIN_FORBEARANCE) || target->HasAura(SPELL_PALADIN_AVENGING_WRATH_MARKER) || target->HasAura(SPELL_PALADIN_IMMUNE_SHIELD_MARKER))
if (target->HasAnyAuras(SPELL_PALADIN_FORBEARANCE, SPELL_PALADIN_AVENGING_WRATH_MARKER, SPELL_PALADIN_IMMUNE_SHIELD_MARKER))
return SPELL_FAILED_TARGET_AURASTATE;

// Xinef: Glyph of Divinity
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/World/achievement_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class achievement_flirt_with_disaster_perf_check : public AchievementCriteriaScr
if (!player)
return false;

if (player->HasAura(AURA_PERFUME_FOREVER) || player->HasAura(AURA_PERFUME_ENCHANTRESS) || player->HasAura(AURA_PERFUME_VICTORY))
if (player->HasAnyAuras(AURA_PERFUME_FOREVER, AURA_PERFUME_ENCHANTRESS, AURA_PERFUME_VICTORY))
return true;

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/World/boss_emerald_dragons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ class MarkOfNatureTargetSelector
{
// return those not tagged or already under the influence of Aura of Nature
if (Unit* unit = object->ToUnit())
return !(unit->HasAura(SPELL_MARK_OF_NATURE) && !unit->HasAura(SPELL_AURA_OF_NATURE));
return !unit->HasAllAuras(SPELL_MARK_OF_NATURE, SPELL_AURA_OF_NATURE);
return true;
}
};
Expand Down
6 changes: 1 addition & 5 deletions src/server/scripts/World/npc_stave_of_ancients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,10 @@ class npc_nelson : public CreatureScript
void SpellHit(Unit* /*Caster*/, SpellInfo const* Spell) override
{
if (InNormalForm())
{
return;
}

if (me->HasAura(NELSON_SPELL_SOUL_FLAME) && me->HasAura(NELSON_WEAKNESS_FROST_TRAP))
{
if (me->HasAllAuras(NELSON_SPELL_SOUL_FLAME, NELSON_WEAKNESS_FROST_TRAP))
me->RemoveAura(NELSON_SPELL_SOUL_FLAME);
}

if (!me->HasAura(NELSON_SPELL_CRIPPLING_CLIP) && Spell->Id == NELSON_WEAKNESS_WING_CLIP)
{
Expand Down

0 comments on commit bff594c

Please sign in to comment.