Skip to content

Commit

Permalink
feat(Core/Spell): Add helper for TriggeredCastFlag (azerothcore#18227)
Browse files Browse the repository at this point in the history
* feat(Core/Spell): Add helper for TriggeredCastFlag

* Lol

* fix build
  • Loading branch information
Kitzunu authored Jan 26, 2024
1 parent c18bd64 commit 69dc880
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
66 changes: 33 additions & 33 deletions src/server/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,11 +2355,11 @@ void Spell::prepareDataForTriggerSystem(AuraEffect const* /*triggeredByAura*/)
// Ranged autorepeat attack is set as triggered spell - ignore it
if (!(m_procAttacker & PROC_FLAG_DONE_RANGED_AUTO_ATTACK))
{
if (_triggeredCastFlags & TRIGGERED_DISALLOW_PROC_EVENTS &&
if (HasTriggeredCastFlag(TRIGGERED_DISALLOW_PROC_EVENTS) &&
(m_spellInfo->HasAttribute(SPELL_ATTR2_ACTIVE_THREAT) ||
m_spellInfo->HasAttribute(SPELL_ATTR3_NOT_A_PROC)))
m_procEx |= PROC_EX_INTERNAL_CANT_PROC;
else if (_triggeredCastFlags & TRIGGERED_DISALLOW_PROC_EVENTS)
else if (HasTriggeredCastFlag(TRIGGERED_DISALLOW_PROC_EVENTS))
m_procEx |= PROC_EX_INTERNAL_TRIGGERED;
}
// Totem casts require spellfamilymask defined in spell_proc_event to proc
Expand Down Expand Up @@ -3147,7 +3147,7 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit* unit, uint32 effectMask, bool scaleA
if (m_originalCaster)
{
bool refresh = false;
bool refreshPeriodic = m_spellInfo->StackAmount < 2 && !(_triggeredCastFlags & TRIGGERED_NO_PERIODIC_RESET);
bool refreshPeriodic = m_spellInfo->StackAmount < 2 && !HasTriggeredCastFlag(TRIGGERED_NO_PERIODIC_RESET);
m_spellAura = Aura::TryRefreshStackOrCreate(aurSpellInfo, effectMask, unit, m_originalCaster,
(aurSpellInfo == m_spellInfo) ? &m_spellValue->EffectBasePoints[0] : &basePoints[0], m_CastItem, ObjectGuid::Empty, &refresh, refreshPeriodic);

Expand Down Expand Up @@ -3481,7 +3481,7 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
}

// Fill aura scaling information
if (sScriptMgr->CanScalingEverything(this) || m_caster->IsTotem() || (m_caster->IsControlledByPlayer() && !m_spellInfo->IsPassive() && m_spellInfo->SpellLevel && !m_spellInfo->IsChanneled() && !(_triggeredCastFlags & TRIGGERED_IGNORE_AURA_SCALING)))
if (sScriptMgr->CanScalingEverything(this) || m_caster->IsTotem() || (m_caster->IsControlledByPlayer() && !m_spellInfo->IsPassive() && m_spellInfo->SpellLevel && !m_spellInfo->IsChanneled() && !HasTriggeredCastFlag(TRIGGERED_IGNORE_AURA_SCALING)))
{
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
Expand Down Expand Up @@ -3522,7 +3522,7 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
}

//Prevent casting at cast another spell (ServerSide check)
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_CAST_IN_PROGRESS) && m_caster->IsNonMeleeSpellCast(false, true, true, m_spellInfo->Id == 75) && m_cast_count)
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_CAST_IN_PROGRESS) && m_caster->IsNonMeleeSpellCast(false, true, true, m_spellInfo->Id == 75) && m_cast_count)
{
SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS);
finish(false);
Expand All @@ -3536,7 +3536,7 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
m_powerCost = m_CastItem ? 0 : m_spellInfo->CalcPowerCost(m_caster, m_spellSchoolMask, this);

// Set combo point requirement
if ((_triggeredCastFlags & TRIGGERED_IGNORE_COMBO_POINTS) || m_CastItem)
if (HasTriggeredCastFlag(TRIGGERED_IGNORE_COMBO_POINTS) || m_CastItem)
m_needComboPoints = false;

SpellCastResult result = CheckCast(true);
Expand Down Expand Up @@ -3566,7 +3566,7 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
prepareDataForTriggerSystem(triggeredByAura);

// calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
m_casttime = (_triggeredCastFlags & TRIGGERED_CAST_DIRECTLY) ? 0 : m_spellInfo->CalcCastTime(m_caster, this);
m_casttime = HasTriggeredCastFlag(TRIGGERED_CAST_DIRECTLY) ? 0 : m_spellInfo->CalcCastTime(m_caster, this);

if (m_caster->GetTypeId() == TYPEID_PLAYER)
if (m_caster->ToPlayer()->GetCommandStatus(CHEAT_CASTTIME))
Expand Down Expand Up @@ -3656,13 +3656,13 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
//Containers for channeled spells have to be set
//TODO:Apply this to all casted spells if needed
// Why check duration? 29350: channelled triggers channelled
if ((_triggeredCastFlags & TRIGGERED_CAST_DIRECTLY) && (!m_spellInfo->IsChanneled() || !m_spellInfo->GetMaxDuration()))
if (HasTriggeredCastFlag(TRIGGERED_CAST_DIRECTLY) && (!m_spellInfo->IsChanneled() || !m_spellInfo->GetMaxDuration()))
cast(true);
else
{
// stealth must be removed at cast starting (at show channel bar)
// skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_AURA_INTERRUPT_FLAGS) && m_spellInfo->IsBreakingStealth())
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_AURA_INTERRUPT_FLAGS) && m_spellInfo->IsBreakingStealth())
{
// Farsight spells exception
uint32 exceptSpellId = 0;
Expand All @@ -3679,7 +3679,7 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
SendSpellStart();

// set target for proper facing
if ((m_casttime || m_spellInfo->IsChanneled()) && !(_triggeredCastFlags & TRIGGERED_IGNORE_SET_FACING))
if ((m_casttime || m_spellInfo->IsChanneled()) && !HasTriggeredCastFlag(TRIGGERED_IGNORE_SET_FACING))
{
if (m_caster->GetTypeId() == TYPEID_UNIT && !m_caster->ToCreature()->IsInEvadeMode() &&
((m_targets.GetObjectTarget() && m_caster != m_targets.GetObjectTarget()) || m_spellInfo->IsPositive()))
Expand All @@ -3697,7 +3697,7 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
if (!m_casttime && /*!m_castItemGUID &&*/ GetCurrentContainer() == CURRENT_GENERIC_SPELL)
cast(true);

if (!(_triggeredCastFlags & TRIGGERED_IGNORE_GCD))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_GCD))
TriggerGlobalCooldown();
}

Expand Down Expand Up @@ -3841,7 +3841,7 @@ void Spell::_cast(bool skipCheck)

SetExecutedCurrently(true);

if (!(_triggeredCastFlags & TRIGGERED_IGNORE_SET_FACING))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_SET_FACING))
if (m_caster->GetTypeId() == TYPEID_UNIT && m_targets.GetObjectTarget() && m_caster != m_targets.GetObjectTarget())
m_caster->SetInFront(m_targets.GetObjectTarget());

Expand Down Expand Up @@ -3920,7 +3920,7 @@ void Spell::_cast(bool skipCheck)

if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_CAST_ITEM) && m_CastItem)
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_CAST_ITEM) && m_CastItem)
{
m_caster->ToPlayer()->StartTimedAchievement(ACHIEVEMENT_TIMED_TYPE_ITEM, m_CastItem->GetEntry());
m_caster->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM, m_CastItem->GetEntry());
Expand All @@ -3929,7 +3929,7 @@ void Spell::_cast(bool skipCheck)
m_caster->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, m_spellInfo->Id, 0, (m_targets.GetUnitTarget() ? m_targets.GetUnitTarget() : m_caster));
}

if (!(_triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_POWER_AND_REAGENT_COST))
{
// Powers have to be taken before SendSpellGo
TakePower();
Expand Down Expand Up @@ -4342,7 +4342,7 @@ void Spell::SendSpellCooldown()
// xinef: properly add creature cooldowns
if (m_caster->GetTypeId() != TYPEID_PLAYER)
{
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD))
{
// xinef: this should be added here
//m_caster->AddSpellCooldown(m_spellInfo->Id, 0, 0);
Expand Down Expand Up @@ -4373,7 +4373,7 @@ void Spell::SendSpellCooldown()
}

// have infinity cooldown but set at aura apply // do not set cooldown for triggered spells (needed by reincarnation)
if (m_spellInfo->IsCooldownStartedOnEvent() || m_spellInfo->IsPassive() || ((_triggeredCastFlags & TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD) && !m_CastItem))
if (m_spellInfo->IsCooldownStartedOnEvent() || m_spellInfo->IsPassive() || (HasTriggeredCastFlag(TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD) && !m_CastItem))
return;

_player->AddSpellAndCategoryCooldowns(m_spellInfo, m_CastItem ? m_CastItem->GetEntry() : 0, this);
Expand Down Expand Up @@ -4665,7 +4665,7 @@ void Spell::SendCastResult(SpellCastResult result)
return;

// Xinef: override every possible result, except for gm fail result... breaks many things and goes unnoticed because of this and makes me rage when i find this out
if ((_triggeredCastFlags & TRIGGERED_DONT_REPORT_CAST_ERROR) && result != SPELL_FAILED_BM_OR_INVISGOD)
if (HasTriggeredCastFlag(TRIGGERED_DONT_REPORT_CAST_ERROR) && result != SPELL_FAILED_BM_OR_INVISGOD)
result = SPELL_FAILED_DONT_REPORT;

SendCastResult(m_caster->ToPlayer(), m_spellInfo, m_cast_count, result, m_customError);
Expand Down Expand Up @@ -5231,7 +5231,7 @@ void Spell::TakeCastItem()
return;

// not remove cast item at triggered spell (equipping, weapon damage, etc)
if (_triggeredCastFlags & TRIGGERED_IGNORE_CAST_ITEM)
if (HasTriggeredCastFlag(TRIGGERED_IGNORE_CAST_ITEM))
return;

ItemTemplate const* proto = m_CastItem->GetTemplate();
Expand Down Expand Up @@ -5647,10 +5647,10 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
//can cast triggered (by aura only?) spells while have this flag
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURASTATE) && m_caster->ToPlayer()->HasPlayerFlag(PLAYER_ALLOW_ONLY_ABILITY))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_CASTER_AURASTATE) && m_caster->ToPlayer()->HasPlayerFlag(PLAYER_ALLOW_ONLY_ABILITY))
return SPELL_FAILED_SPELL_IN_PROGRESS;

if (!(_triggeredCastFlags & TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD) && m_caster->ToPlayer()->HasSpellCooldown(m_spellInfo->Id))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD) && m_caster->ToPlayer()->HasSpellCooldown(m_spellInfo->Id))
{
if (m_triggeredByAuraSpell)
return SPELL_FAILED_DONT_REPORT;
Expand All @@ -5673,7 +5673,7 @@ SpellCastResult Spell::CheckCast(bool strict)
}

// Check global cooldown
if (strict && !(_triggeredCastFlags & TRIGGERED_IGNORE_GCD) && HasGlobalCooldown())
if (strict && !HasTriggeredCastFlag(TRIGGERED_IGNORE_GCD) && HasGlobalCooldown())
return SPELL_FAILED_NOT_READY;

// only triggered spells can be processed an ended battleground
Expand All @@ -5695,7 +5695,7 @@ SpellCastResult Spell::CheckCast(bool strict)

// only check at first call, Stealth auras are already removed at second call
// for now, ignore triggered spells
if (strict && !(_triggeredCastFlags & TRIGGERED_IGNORE_SHAPESHIFT))
if (strict && !HasTriggeredCastFlag(TRIGGERED_IGNORE_SHAPESHIFT))
{
bool checkForm = true;
// Ignore form req aura
Expand Down Expand Up @@ -5741,7 +5741,7 @@ SpellCastResult Spell::CheckCast(bool strict)

// caster state requirements
// not for triggered spells (needed by execute)
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURASTATE))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_CASTER_AURASTATE))
{
if (m_spellInfo->CasterAuraState && !m_caster->HasAuraState(AuraStateType(m_spellInfo->CasterAuraState), m_spellInfo, m_caster))
return SPELL_FAILED_CASTER_AURASTATE;
Expand Down Expand Up @@ -5791,7 +5791,7 @@ SpellCastResult Spell::CheckCast(bool strict)
}

Vehicle* vehicle = m_caster->GetVehicle();
if (vehicle && !(_triggeredCastFlags & TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE))
if (vehicle && !HasTriggeredCastFlag(TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE))
{
uint16 checkMask = 0;
for (uint8 effIndex = EFFECT_0; effIndex < MAX_SPELL_EFFECTS; ++effIndex)
Expand Down Expand Up @@ -5981,7 +5981,7 @@ SpellCastResult Spell::CheckCast(bool strict)
}

// not let players cast spells at mount (and let do it to creatures)
if (m_caster->IsMounted() && m_caster->GetTypeId() == TYPEID_PLAYER && !(_triggeredCastFlags & TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE) &&
if (m_caster->IsMounted() && m_caster->GetTypeId() == TYPEID_PLAYER && !HasTriggeredCastFlag(TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE) &&
!m_spellInfo->IsPassive() && !m_spellInfo->HasAttribute(SPELL_ATTR0_ALLOW_WHILE_MOUNTED))
{
if (m_caster->IsInFlight())
Expand Down Expand Up @@ -6011,17 +6011,17 @@ SpellCastResult Spell::CheckCast(bool strict)
if (castResult != SPELL_CAST_OK)
return castResult;

if (!(_triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_POWER_AND_REAGENT_COST))
{
castResult = CheckPower();
if (castResult != SPELL_CAST_OK)
return castResult;
}

// xinef: do not skip triggered spells if they posses prevention type (eg. Bladestorm vs Hand of Protection)
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURAS) || (m_spellInfo->PreventionType > SPELL_PREVENTION_TYPE_NONE && m_triggeredByAuraSpell && m_triggeredByAuraSpell.spellInfo->IsPositive()))
if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_CASTER_AURAS) || (m_spellInfo->PreventionType > SPELL_PREVENTION_TYPE_NONE && m_triggeredByAuraSpell && m_triggeredByAuraSpell.spellInfo->IsPositive()))
{
castResult = CheckCasterAuras(_triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURAS);
castResult = CheckCasterAuras(HasTriggeredCastFlag(TRIGGERED_IGNORE_CASTER_AURAS));
if (castResult != SPELL_CAST_OK)
return castResult;

Expand Down Expand Up @@ -6781,7 +6781,7 @@ SpellCastResult Spell::CheckCast(bool strict)

SpellCastResult Spell::CheckPetCast(Unit* target)
{
if (m_caster->HasUnitState(UNIT_STATE_CASTING) && !(_triggeredCastFlags & TRIGGERED_IGNORE_CAST_IN_PROGRESS)) //prevent spellcast interruption by another spellcast
if (m_caster->HasUnitState(UNIT_STATE_CASTING) && !HasTriggeredCastFlag(TRIGGERED_IGNORE_CAST_IN_PROGRESS)) //prevent spellcast interruption by another spellcast
return SPELL_FAILED_SPELL_IN_PROGRESS;

// dead owner (pets still alive when owners ressed?)
Expand Down Expand Up @@ -7245,15 +7245,15 @@ SpellCastResult Spell::CheckItems()
else
{
// Xinef: this is not true in my opinion, in eg bladestorm will not be canceled after disarm
//if (!(_triggeredCastFlags & TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT))
//if (!HasTriggeredCastFlag(TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT))
if (m_caster->GetTypeId() == TYPEID_PLAYER && !m_caster->ToPlayer()->HasItemFitToSpellRequirements(m_spellInfo))
return SPELL_FAILED_EQUIPPED_ITEM_CLASS;
}

// do not take reagents for these item casts
if (!(m_CastItem && m_CastItem->GetTemplate()->Flags & ITEM_FLAG_NO_REAGENT_COST))
{
bool checkReagents = !(_triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST) && !player->CanNoReagentCast(m_spellInfo);
bool checkReagents = !HasTriggeredCastFlag(TRIGGERED_IGNORE_POWER_AND_REAGENT_COST) && !player->CanNoReagentCast(m_spellInfo);
// Not own traded item (in trader trade slot) requires reagents even if triggered spell
if (!checkReagents)
if (Item* targetItem = m_targets.GetItemTarget())
Expand Down Expand Up @@ -7675,7 +7675,7 @@ SpellCastResult Spell::CheckItems()
}

// check weapon presence in slots for main/offhand weapons
if (/*never skip those checks !(_triggeredCastFlags & TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT) &&*/ m_spellInfo->EquippedItemClass >= 0)
if (/*never skip those checks !HasTriggeredCastFlag(TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT) &&*/ m_spellInfo->EquippedItemClass >= 0)
{
// main hand weapon required
if (m_spellInfo->HasAttribute(SPELL_ATTR3_REQUIRES_MAIN_HAND_WEAPON))
Expand Down Expand Up @@ -8031,7 +8031,7 @@ bool Spell::IsNextMeleeSwingSpell() const

bool Spell::IsIgnoringCooldowns() const
{
return (_triggeredCastFlags & TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD) != 0;
return HasTriggeredCastFlag(TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD) != 0;
}

bool Spell::IsAutoActionResetSpell() const
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Spells/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ class Spell
void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
bool IsNextMeleeSwingSpell() const;
bool IsTriggered() const { return _triggeredCastFlags & TRIGGERED_FULL_MASK; };
bool IsTriggered() const { return HasTriggeredCastFlag(TRIGGERED_FULL_MASK); };
bool HasTriggeredCastFlag(TriggerCastFlags flag) const { return _triggeredCastFlags & flag; };
bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
bool IsAutoActionResetSpell() const;
bool IsIgnoringCooldowns() const;
Expand Down

0 comments on commit 69dc880

Please sign in to comment.