aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Unit
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-02-24 14:33:56 +0100
committerShauren <shauren.trinity@gmail.com>2025-02-24 14:33:56 +0100
commite233079d2d8dbdc1bcd7beb593f047b26a6c4cc9 (patch)
tree7d95c9ae4d0f37f1dc39397863aca43ac08c5e94 /src/server/game/Entities/Unit
parent00223f3bee137f3b3f3a8e0ec33b634b4511cc0b (diff)
Core/Units: Refactor GetCastSpellInfo to return values via return value and hide internal lookup state tracker
Diffstat (limited to 'src/server/game/Entities/Unit')
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp19
-rw-r--r--src/server/game/Entities/Unit/Unit.h12
2 files changed, 23 insertions, 8 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 4b3e7921046..f928a40fe7b 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -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
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index 8feedd56904..6fbd86f0f31 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -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;