From bddde92a0f26e5f88023ea4c0286ba4485d91c7f Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 26 Dec 2021 19:54:55 -0500 Subject: [PATCH] Entities/Player: Clean up client control handling behavior around possession. Mind Control should no longer cause various weirdness. Port From (https://github.com/TrinityCore/TrinityCore/commit/bba4696de715b79b31e154d1a8e1597507812ece) --- Source/Game/Entities/Player/Player.cs | 28 ++++++++++++++++++++------- Source/Game/Entities/Unit/Unit.cs | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 5aa7fcabb..fc8af57c0 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -7214,24 +7214,38 @@ namespace Game.Entities public void SetClientControl(Unit target, bool allowMove) { - // still affected by some aura that shouldn't allow control, only allow on last such aura to be removed - if (allowMove && target.HasUnitState(UnitState.CantClientControl)) + // a player can never client control nothing + Cypher.Assert(target); + + // don't allow possession to be overridden + if (target.HasUnitState(UnitState.Charmed) && (GetGUID() != target.GetCharmerGUID())) { // this should never happen, otherwise m_unitBeingMoved might be left dangling! - Cypher.Assert(GetUnitBeingMoved() == target); + Log.outError(LogFilter.Player, $"Player '{GetName()}' attempt to client control '{target.GetName()}', which is charmed by GUID {target.GetCharmerGUID()}"); return; } + // still affected by some aura that shouldn't allow control, only allow on last such aura to be removed + if (target.HasUnitState(UnitState.Controlled)) + allowMove = false; + ControlUpdate packet = new(); packet.Guid = target.GetGUID(); packet.On = allowMove; SendPacket(packet); - if (this != target) - SetViewpoint(target, allowMove); + WorldObject viewpoint = GetViewpoint(); + if (viewpoint == null) + viewpoint = this; + if (target != viewpoint) + { + if (viewpoint != this) + SetViewpoint(viewpoint, false); + if (target != this) + SetViewpoint(target, true); + } - if (allowMove) - SetMovedUnit(target); + SetMovedUnit(target); } public Item GetWeaponForAttack(WeaponAttackType attackType, bool useable = false) diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 7e158cccb..c4fc10b0f 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -172,7 +172,7 @@ namespace Game.Entities UpdateSplineMovement(diff); GetMotionMaster().Update(diff); - if (GetAI() == null && (!IsPlayer() || IsCharmed())) + if (GetAI() == null && (!IsPlayer() || (IsCharmed() && GetCharmerGUID().IsCreature()))) UpdateCharmAI(); RefreshAI();