mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Units: Refactor GetCastSpellInfo to return values via return value and hide internal lookup state tracker
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user