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;
}
+3 -25
View File
@@ -68,6 +68,7 @@ struct FactionTemplateEntry;
struct LiquidData;
struct LiquidTypeEntry;
struct MountCapabilityEntry;
struct PendingSpellCastRequest;
struct SpellValue;
class Aura;
@@ -772,29 +773,6 @@ struct PositionUpdateInfo
bool Turned = false;
};
struct SpellCastRequestItemData
{
SpellCastRequestItemData(uint8 bagSlot, uint8 slot, ObjectGuid castItem) :
BagSlot(bagSlot), Slot(slot), CastItem(castItem)
{
}
uint8 BagSlot = 0;
uint8 Slot = 0;
ObjectGuid CastItem;
};
struct PendingSpellCastRequest
{
PendingSpellCastRequest(WorldPackets::Spells::SpellCastRequest&& castRequest, Optional<SpellCastRequestItemData> castItemData = {}) :
CastRequest(castRequest), CastItemData(castItemData)
{
}
WorldPackets::Spells::SpellCastRequest CastRequest;
Optional<SpellCastRequestItemData> CastItemData;
};
// delay time next attack to prevent client attack animation problems
#define ATTACK_DISPLAY_DELAY 200
#define MAX_PLAYER_STEALTH_DETECT_RANGE 30.0f // max distance for detection targets by player
@@ -1804,7 +1782,7 @@ class TC_GAME_API Unit : public WorldObject
void SetIgnoringCombat(bool apply) { _isIgnoringCombat = apply; }
// Queues up a spell cast request that has been received via packet and processes it whenever possible.
void RequestSpellCast(PendingSpellCastRequest castRequest, SpellInfo const* spellInfo);
void RequestSpellCast(std::unique_ptr<PendingSpellCastRequest> castRequest, SpellInfo const* spellInfo);
void CancelPendingCastRequest();
bool CanRequestSpellCast(SpellInfo const* spell) const;
@@ -1957,7 +1935,7 @@ class TC_GAME_API Unit : public WorldObject
bool _isIgnoringCombat;
Optional<PendingSpellCastRequest> _pendingSpellCastRequest;
std::unique_ptr<PendingSpellCastRequest> _pendingSpellCastRequest;
void ProcessPendingSpellCastRequest();
void ProcessItemCast(PendingSpellCastRequest const& castRequest, SpellCastTargets const& targets);
bool CanExecutePendingSpellCastRequest(SpellInfo const* spellInfo) const;
+3 -2
View File
@@ -36,6 +36,7 @@
#include "ScriptMgr.h"
#include "Spell.h"
#include "SpellAuraEffects.h"
#include "SpellCastRequest.h"
#include "SpellMgr.h"
#include "SpellPackets.h"
#include "Totem.h"
@@ -103,7 +104,7 @@ void WorldSession::HandleUseItemOpcode(WorldPackets::Spells::UseItem& packet)
return;
if (user->CanRequestSpellCast(spellInfo))
user->RequestSpellCast(PendingSpellCastRequest(std::move(packet.Cast), SpellCastRequestItemData(packet.PackSlot, packet.Slot, packet.CastItem)), spellInfo);
user->RequestSpellCast(std::make_unique<PendingSpellCastRequest>(std::move(packet.Cast), SpellCastRequestItemData(packet.PackSlot, packet.Slot, packet.CastItem)), spellInfo);
}
void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
@@ -274,7 +275,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPackets::Spells::CastSpell& cast)
return;
if (mover->CanRequestSpellCast(spellInfo))
mover->RequestSpellCast(PendingSpellCastRequest(std::move(cast.Cast)), spellInfo);
mover->RequestSpellCast(std::make_unique<PendingSpellCastRequest>(std::move(cast.Cast)), spellInfo);
else if (mover->IsPlayer())
Spell::SendCastResult(mover->ToPlayer(), spellInfo, cast.Cast.CastID, SPELL_FAILED_SPELL_IN_PROGRESS);
}
+37
View File
@@ -0,0 +1,37 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpellPacketsCommon.h"
struct SpellCastRequestItemData
{
SpellCastRequestItemData(uint8 bagSlot, uint8 slot, ObjectGuid castItem) :
BagSlot(bagSlot), Slot(slot), CastItem(castItem) { }
uint8 BagSlot = 0;
uint8 Slot = 0;
ObjectGuid CastItem;
};
struct PendingSpellCastRequest
{
PendingSpellCastRequest(WorldPackets::Spells::SpellCastRequest&& castRequest, Optional<SpellCastRequestItemData> castItemData = { }) :
CastRequest(castRequest), CastItemData(castItemData) { }
WorldPackets::Spells::SpellCastRequest CastRequest;
Optional<SpellCastRequestItemData> CastItemData;
};