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

Port From (https://github.com/TrinityCore/TrinityCore/commit/edc75831194bc2419e3abada47121fadf4b2aa8d)
This commit is contained in:
hondacrx
2021-12-23 20:17:08 -05:00
parent 4584543d45
commit 1f58dc2b53
5 changed files with 41 additions and 48 deletions
@@ -209,8 +209,6 @@ namespace Game.Entities
public List<ObjectGuid> m_clientGUIDs = new();
public List<ObjectGuid> m_visibleTransports = new();
public WorldObject seerView;
// only changed for direct client control (possess, vehicle etc.), not stuff you control using pet commands
public Unit m_unitMovedByMe;
Team m_team;
ReputationMgr reputationMgr;
QuestObjectiveCriteriaManager m_questObjectiveCriteriaMgr;
+3 -14
View File
@@ -4013,7 +4013,7 @@ namespace Game.Entities
public override bool CanAlwaysSee(WorldObject obj)
{
// Always can see self
if (m_unitMovedByMe == obj)
if (GetUnitBeingMoved() == obj)
return true;
ObjectGuid guid = m_activePlayerData.FarsightObject;
@@ -5544,7 +5544,7 @@ namespace Game.Entities
initialSetup.ServerExpansionLevel = (byte)WorldConfig.GetIntValue(WorldCfg.Expansion);
SendPacket(initialSetup);
SetMover(this);
SetMovedUnit(this);
}
public void SendInitialPacketsAfterAddToMap()
@@ -7228,18 +7228,7 @@ namespace Game.Entities
SetViewpoint(target, allowMove);
if (allowMove)
SetMover(target);
}
public void SetMover(Unit target)
{
m_unitMovedByMe.m_playerMovingMe = null;
m_unitMovedByMe = target;
m_unitMovedByMe.m_playerMovingMe = this;
MoveSetActiveMover packet = new();
packet.MoverGUID = target.GetGUID();
SendPacket(packet);
SetMovedUnit(target);
}
public Item GetWeaponForAttack(WeaponAttackType attackType, bool useable = false)