Core/Units: moved spell cast request includes out of unit class and use unique_ptr instead of optionals

This commit is contained in:
Ovahlord committed 2023-10-09 22:07:13 +02:00
1 parent b49f95e1e9
commit faa78b9e07
4 files changed
+54 -38

No files matched your search

+11 -11
View File
@@ -71,6 +71,7 @@
#include "Spell.h"
#include "SpellAuraEffects.h"
#include "SpellAuras.h"
#include "SpellCastRequest.h"
#include "SpellHistory.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
@@ -293,7 +294,6 @@ bool DispelableAura::RollDispel() const
return roll_chance_i(_chance);
}
Unit::Unit(bool isWorldObject) :
WorldObject(isWorldObject), m_lastSanctuaryTime(0),
LastCharmerGUID(), m_ControlledByPlayer(false), movespline(std::make_unique<Movement::MoveSpline>()),
@@ -14290,13 +14290,13 @@ bool Unit::CanExecutePendingSpellCastRequest(SpellInfo const* spellInfo) const
return true;
}
void Unit::RequestSpellCast(PendingSpellCastRequest castRequest, SpellInfo const* spellInfo)
void Unit::RequestSpellCast(std::unique_ptr<PendingSpellCastRequest> castRequest, SpellInfo const* spellInfo)
{
// We are overriding an already existing spell cast request so inform the client that the old cast is being replaced
if (_pendingSpellCastRequest.has_value())
if (_pendingSpellCastRequest)
CancelPendingCastRequest();
_pendingSpellCastRequest = castRequest;
_pendingSpellCastRequest = std::move(castRequest);
// If we can process the cast request right now, do it.
if (CanExecutePendingSpellCastRequest(spellInfo))
@@ -14305,7 +14305,7 @@ void Unit::RequestSpellCast(PendingSpellCastRequest castRequest, SpellInfo const
void Unit::CancelPendingCastRequest()
{
if (!_pendingSpellCastRequest.has_value())
if (!_pendingSpellCastRequest)
return;
// We have to inform the client that the cast has been canceled to avoid the cast button to stay highlightened
@@ -14319,7 +14319,7 @@ void Unit::CancelPendingCastRequest()
ToPlayer()->SendDirectMessage(&data);
}
_pendingSpellCastRequest.reset();
_pendingSpellCastRequest = nullptr;
}
// A spell can be queued up within 400 milliseconds before global cooldown expires or the cast finishes
@@ -14340,14 +14340,14 @@ bool Unit::CanRequestSpellCast(SpellInfo const* spellInfo) const
void Unit::ProcessPendingSpellCastRequest()
{
if (!_pendingSpellCastRequest.has_value())
if (!_pendingSpellCastRequest)
return;
// Sanity check. If the player requested an invalid spell cast, just skip the request.
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(_pendingSpellCastRequest->CastRequest.SpellID);
if (!spellInfo)
{
_pendingSpellCastRequest.reset();
_pendingSpellCastRequest = nullptr;
return;
}
@@ -14365,7 +14365,7 @@ void Unit::ProcessPendingSpellCastRequest()
if (_pendingSpellCastRequest->CastItemData.has_value())
{
ProcessItemCast(*_pendingSpellCastRequest, targets);
_pendingSpellCastRequest.reset();
_pendingSpellCastRequest = nullptr;
return;
}
@@ -14408,7 +14408,7 @@ void Unit::ProcessPendingSpellCastRequest()
if (!allow)
{
_pendingSpellCastRequest.reset();
_pendingSpellCastRequest = nullptr;
return;
}
}
@@ -14419,7 +14419,7 @@ void Unit::ProcessPendingSpellCastRequest()
// can't use our own spells when we're in possession of another unit,
if (caster->isPossessing())
{
_pendingSpellCastRequest.reset();
_pendingSpellCastRequest = nullptr;
return;
}