Core/Units: Refactor GetCastSpellInfo to return values via return value and hide internal lookup state tracker

This commit is contained in:
Shauren
2025-02-24 14:33:56 +01:00
parent 00223f3bee
commit e233079d2d
4 changed files with 27 additions and 14 deletions

View File

@@ -30904,8 +30904,9 @@ void Player::ExecutePendingSpellCastRequest()
}
// Check possible spell cast overrides
GetCastSpellInfoContext overrideContext;
spellInfo = castingUnit->GetCastSpellInfo(spellInfo, triggerFlag, &overrideContext);
auto [overrideSpellInfo, overrideTriggerFlag] = castingUnit->GetCastSpellInfo(spellInfo);
spellInfo = overrideSpellInfo;
triggerFlag |= overrideTriggerFlag;
if (spellInfo->IsPassive())
{
CancelPendingCastRequest();

View File

@@ -14085,16 +14085,19 @@ void Unit::ClearBossEmotes(Optional<uint32> zoneId, Player const* target) const
bool Unit::GetCastSpellInfoContext::AddSpell(uint32 spellId)
{
auto itr = std::ranges::find(VisitedSpells, spellId);
if (itr != VisitedSpells.end())
return false; // already exists
for (uint32& slot : VisitedSpells)
{
if (slot == spellId)
return false; // already exists
itr = std::ranges::find(VisitedSpells, 0u);
if (itr == VisitedSpells.end())
return false; // no free slots left
if (!slot)
{
slot = spellId;
return true;
}
}
*itr = spellId;
return true;
return false; // no free slots left
}
SpellInfo const* Unit::GetCastSpellInfo(SpellInfo const* spellInfo, TriggerCastFlags& triggerFlag, GetCastSpellInfoContext* context) const

View File

@@ -1462,6 +1462,18 @@ class TC_GAME_API Unit : public WorldObject
std::array<uint32, 5> VisitedSpells = { };
bool AddSpell(uint32 spellId);
};
struct GetCastSpellInfoResult
{
::SpellInfo const* SpellInfo = nullptr;
TriggerCastFlags TriggerFlag = TRIGGERED_NONE;
};
GetCastSpellInfoResult GetCastSpellInfo(SpellInfo const* spellInfo) const
{
GetCastSpellInfoContext context;
GetCastSpellInfoResult result;
result.SpellInfo = GetCastSpellInfo(spellInfo, result.TriggerFlag, &context);
return result;
}
virtual SpellInfo const* GetCastSpellInfo(SpellInfo const* spellInfo, TriggerCastFlags& triggerFlag, GetCastSpellInfoContext* context) const;
uint32 GetCastSpellXSpellVisualId(SpellInfo const* spellInfo) const override;

View File

@@ -1788,10 +1788,7 @@ class spell_sha_thorims_invocation_trigger : public SpellScript
if (!spellIdHolder)
return;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellIdHolder->SpellIdToTrigger, GetCastDifficulty());
TriggerCastFlags triggerFlags = TRIGGERED_NONE;
Unit::GetCastSpellInfoContext overrideContext;
spellInfo = caster->GetCastSpellInfo(spellInfo, triggerFlags, &overrideContext);
auto [spellInfo, triggerFlags] = caster->GetCastSpellInfo(sSpellMgr->GetSpellInfo(spellIdHolder->SpellIdToTrigger, GetCastDifficulty()));
// Remove Overflowing Maelstrom spellmod early to make next cast behave as if it consumed only 5 or less maelstrom stacks
// this works because consuming "up to 5 stacks" will always cause Maelstrom Weapon stacks to drop to 5 or lower