Entities/Unit: Cleanup all the direct accesses to m_unitMovedByMe. Refactor the field to be protected. Add assertions to catch dangling pointers.

(cherry picked from commit 396f87c30d)
This commit is contained in:
Treeston
2019-06-23 16:44:37 +02:00
committed by Shauren
parent 06823f19cd
commit edc7583119
6 changed files with 48 additions and 63 deletions

View File

@@ -43,7 +43,7 @@ void WorldSession::HandleUseItemOpcode(WorldPackets::Spells::UseItem& packet)
Player* user = _player;
// ignore for remote control state
if (user->m_unitMovedByMe != user)
if (user->GetUnitBeingMoved() != user)
return;
Item* item = user->GetUseableItemByPos(packet.PackSlot, packet.Slot);
@@ -137,7 +137,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPackets::Spells::OpenItem& packet)
Player* player = GetPlayer();
// ignore for remote control state
if (player->m_unitMovedByMe != player)
if (player->GetUnitBeingMoved() != player)
return;
TC_LOG_INFO("network", "bagIndex: %u, slot: %u", packet.Slot, packet.PackSlot);
@@ -248,8 +248,8 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPackets::GameObject::GameObjUs
if (GameObject* obj = GetPlayer()->GetGameObjectIfCanInteractWith(packet.Guid))
{
// ignore for remote control state
if (GetPlayer()->m_unitMovedByMe != GetPlayer())
if (!(GetPlayer()->IsOnVehicle(GetPlayer()->m_unitMovedByMe) || GetPlayer()->IsMounted()) && !obj->GetGOInfo()->IsUsableMounted())
if (GetPlayer()->GetUnitBeingMoved() != GetPlayer())
if (!(GetPlayer()->IsOnVehicle(GetPlayer()->GetUnitBeingMoved()) || GetPlayer()->IsMounted()) && !obj->GetGOInfo()->IsUsableMounted())
return;
obj->Use(GetPlayer());
@@ -259,7 +259,7 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPackets::GameObject::GameObjUs
void WorldSession::HandleGameobjectReportUse(WorldPackets::GameObject::GameObjReportUse& packet)
{
// ignore for remote control state
if (_player->m_unitMovedByMe != _player)
if (_player->GetUnitBeingMoved() != _player)
return;
if (GameObject* go = GetPlayer()->GetGameObjectIfCanInteractWith(packet.Guid))
@@ -274,7 +274,7 @@ void WorldSession::HandleGameobjectReportUse(WorldPackets::GameObject::GameObjRe
void WorldSession::HandleCastSpellOpcode(WorldPackets::Spells::CastSpell& cast)
{
// ignore for remote control state (for player case)
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
return;
@@ -482,7 +482,7 @@ void WorldSession::HandleCancelAutoRepeatSpellOpcode(WorldPackets::Spells::Cance
void WorldSession::HandleCancelChanneling(WorldPackets::Spells::CancelChannelling& /*cancelChanneling*/)
{
// ignore for remote control state (for player case)
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
return;
@@ -492,7 +492,7 @@ void WorldSession::HandleCancelChanneling(WorldPackets::Spells::CancelChannellin
void WorldSession::HandleTotemDestroyed(WorldPackets::Totem::TotemDestroyed& totemDestroyed)
{
// ignore for remote control state
if (_player->m_unitMovedByMe != _player)
if (_player->GetUnitBeingMoved() != _player)
return;
uint8 slotId = totemDestroyed.Slot;