Core/Movement: MotionMaster reimplementation
Port From (https://github.com/TrinityCore/TrinityCore/commit/426f9f2f92b26fbb68e7cda9290ccbd586c6af4e)
This commit is contained in:
@@ -110,7 +110,7 @@ namespace Game.Entities
|
||||
|
||||
public bool IsReturningHome()
|
||||
{
|
||||
if (GetMotionMaster().GetMotionSlotType(MovementSlot.Active) == MovementGeneratorType.Home)
|
||||
if (GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Home)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -551,8 +551,7 @@ namespace Game.Entities
|
||||
{
|
||||
Unit charmer = Global.ObjAccessor.GetUnit(this, LastCharmerGUID);
|
||||
if (charmer)
|
||||
if (CanStartAttack(charmer, true))
|
||||
i_AI.AttackStart(charmer);
|
||||
EngageWithTarget(charmer);
|
||||
}
|
||||
|
||||
LastCharmerGUID.Clear();
|
||||
@@ -1917,7 +1916,8 @@ namespace Game.Entities
|
||||
SetNativeDisplayId(display.CreatureDisplayID, display.DisplayScale);
|
||||
}
|
||||
|
||||
GetMotionMaster().InitDefault();
|
||||
GetMotionMaster().InitializeDefault();
|
||||
|
||||
//Re-initialize reactstate that could be altered by movementgenerators
|
||||
InitializeReactState();
|
||||
|
||||
|
||||
@@ -266,7 +266,8 @@ namespace Game.Entities
|
||||
creature.GetMotionMaster().Initialize();
|
||||
else
|
||||
creature.GetMotionMaster().MoveIdle();
|
||||
Log.outDebug(LogFilter.Unit, "Set {0} movement for member GUID: {1}", dismiss ? "default" : "idle", creature.GetGUID().ToString());
|
||||
|
||||
Log.outDebug(LogFilter.Unit, $"CreatureGroup::FormationReset: Set {(dismiss ? "default" : "idle")} movement for member {creature.GetGUID()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,20 +315,20 @@ namespace Game.Entities
|
||||
if (!member.IsFlying())
|
||||
member.UpdateGroundPositionZ(dx, dy, ref dz);
|
||||
|
||||
Position point = new(dx, dy, dz, destination.GetOrientation());
|
||||
|
||||
member.GetMotionMaster().MoveFormation(id, point, moveType, !member.IsWithinDist(_leader, dist + 5.0f), orientation);
|
||||
member.SetHomePosition(dx, dy, dz, pathangle);
|
||||
|
||||
Position point = new(dx, dy, dz, destination.GetOrientation());
|
||||
member.GetMotionMaster().MoveFormation(id, point, moveType, !member.IsWithinDist(_leader, dist + 5.0f), orientation);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanLeaderStartMoving()
|
||||
{
|
||||
foreach (var itr in _members)
|
||||
foreach (var pair in _members)
|
||||
{
|
||||
if (itr.Key != _leader && itr.Key.IsAlive())
|
||||
if (pair.Key != _leader && pair.Key.IsAlive())
|
||||
{
|
||||
if (itr.Key.IsEngaged() || itr.Key.IsReturningHome())
|
||||
if (pair.Key.IsEngaged() || pair.Key.IsReturningHome())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2120,11 +2120,7 @@ namespace Game.Entities
|
||||
return;
|
||||
|
||||
// stop taxi flight at summon
|
||||
if (IsInFlight())
|
||||
{
|
||||
GetMotionMaster().MovementExpired();
|
||||
CleanupAfterTaxiFlight();
|
||||
}
|
||||
FinishTaxiFlight();
|
||||
|
||||
// drop flag at summon
|
||||
// this code can be reached only when GM is summoning player who carries flag, because player should be immune to summoning spells when he carries flag
|
||||
@@ -6880,9 +6876,18 @@ namespace Game.Entities
|
||||
return ActivateTaxiPathTo(nodes, null, spellid);
|
||||
}
|
||||
|
||||
public void FinishTaxiFlight()
|
||||
{
|
||||
if (!IsInFlight())
|
||||
return;
|
||||
|
||||
GetMotionMaster().Remove(MovementGeneratorType.Flight);
|
||||
m_taxi.ClearTaxiDestinations(); // not destinations, clear source node
|
||||
}
|
||||
|
||||
public void CleanupAfterTaxiFlight()
|
||||
{
|
||||
m_taxi.ClearTaxiDestinations(); // not destinations, clear source node
|
||||
m_taxi.ClearTaxiDestinations(); // not destinations, clear source node
|
||||
Dismount();
|
||||
RemoveUnitFlag(UnitFlags.RemoveClientControl | UnitFlags.TaxiFlight);
|
||||
}
|
||||
@@ -7206,13 +7211,8 @@ namespace Game.Entities
|
||||
public void SetMover(Unit target)
|
||||
{
|
||||
m_unitMovedByMe.m_playerMovingMe = null;
|
||||
if (m_unitMovedByMe.IsCreature())
|
||||
m_unitMovedByMe.GetMotionMaster().Initialize();
|
||||
|
||||
m_unitMovedByMe = target;
|
||||
m_unitMovedByMe.m_playerMovingMe = this;
|
||||
if (m_unitMovedByMe.IsCreature())
|
||||
m_unitMovedByMe.GetMotionMaster().Initialize();
|
||||
|
||||
MoveSetActiveMover packet = new();
|
||||
packet.MoverGUID = target.GetGUID();
|
||||
|
||||
@@ -172,11 +172,11 @@ namespace Game.Entities
|
||||
if (MotionMaster.IsInvalidMovementSlot(slot))
|
||||
return;
|
||||
|
||||
IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(slot);
|
||||
MovementGenerator movementGenerator = GetMotionMaster().GetCurrentMovementGenerator(slot);
|
||||
if (movementGenerator != null)
|
||||
movementGenerator.Pause(timer);
|
||||
|
||||
if (forced)
|
||||
if (forced && GetMotionMaster().GetCurrentSlot() == slot)
|
||||
StopMoving();
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace Game.Entities
|
||||
if (MotionMaster.IsInvalidMovementSlot(slot))
|
||||
return;
|
||||
|
||||
IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(slot);
|
||||
MovementGenerator movementGenerator = GetMotionMaster().GetCurrentMovementGenerator(slot);
|
||||
if (movementGenerator != null)
|
||||
movementGenerator.Resume(timer);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ namespace Game.Entities
|
||||
init.DisableTransportPathTransformations(); // It makes no sense to target global orientation
|
||||
init.SetFacing(ori);
|
||||
|
||||
//GetMotionMaster().LaunchMoveSpline(init, EventId.Face, MovementSlot.Controlled);
|
||||
//GetMotionMaster().LaunchMoveSpline(init, EventId.Face, MovementGeneratorPriority.Highest);
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace Game.Entities
|
||||
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZ(), false);
|
||||
init.SetFacing(GetAbsoluteAngle(obj)); // when on transport, GetAbsoluteAngle will still return global coordinates (and angle) that needs transforming
|
||||
|
||||
//GetMotionMaster().LaunchMoveSpline(init, EventId.Face, MovementSlot.Controlled);
|
||||
//GetMotionMaster().LaunchMoveSpline(init, EventId.Face, MovementGeneratorPriority.Highest);
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ namespace Game.Entities
|
||||
MoveSplineInit init = new(this);
|
||||
init.MoveTo(x, y, z, generatePath, forceDestination);
|
||||
init.SetVelocity(speed);
|
||||
GetMotionMaster().LaunchMoveSpline(init, 0, MovementSlot.Active, MovementGeneratorType.Point);
|
||||
GetMotionMaster().LaunchMoveSpline(init, 0, MovementGeneratorPriority.Normal, MovementGeneratorType.Point);
|
||||
}
|
||||
|
||||
public void KnockbackFrom(float x, float y, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null)
|
||||
@@ -539,7 +539,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Follow)
|
||||
{
|
||||
Unit followed = ((AbstractFollower)GetMotionMaster().Top()).GetTarget();
|
||||
Unit followed = (GetMotionMaster().GetCurrentMovementGenerator() as FollowMovementGenerator).GetTarget();
|
||||
if (followed != null && followed.GetGUID() == GetOwnerGUID() && !followed.IsInCombat())
|
||||
{
|
||||
float ownerSpeed = followed.GetSpeedRate(mtype);
|
||||
@@ -1254,8 +1254,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (IsAlive())
|
||||
{
|
||||
if (GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Fleeing)
|
||||
GetMotionMaster().MovementExpired();
|
||||
GetMotionMaster().Remove(MovementGeneratorType.Fleeing);
|
||||
if (GetVictim() != null)
|
||||
SetTarget(GetVictim().GetGUID());
|
||||
}
|
||||
@@ -1280,8 +1279,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (IsAlive())
|
||||
{
|
||||
if (GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Confused)
|
||||
GetMotionMaster().MovementExpired();
|
||||
GetMotionMaster().Remove(MovementGeneratorType.Confused);
|
||||
if (GetVictim() != null)
|
||||
SetTarget(GetVictim().GetGUID());
|
||||
}
|
||||
|
||||
@@ -353,11 +353,8 @@ namespace Game.Entities
|
||||
|
||||
if (IsTypeId(TypeId.Unit))
|
||||
{
|
||||
IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(MovementSlot.Idle);
|
||||
if (movementGenerator != null)
|
||||
movementGenerator.Pause(0);
|
||||
|
||||
GetMotionMaster().Clear(MovementSlot.Active);
|
||||
PauseMovement(0, 0, false);
|
||||
GetMotionMaster().Clear(MovementGeneratorPriority.Normal);
|
||||
|
||||
StopMoving();
|
||||
|
||||
@@ -476,7 +473,7 @@ namespace Game.Entities
|
||||
RestoreFaction();
|
||||
|
||||
///@todo Handle SLOT_IDLE motion resume
|
||||
GetMotionMaster().InitDefault();
|
||||
GetMotionMaster().InitializeDefault();
|
||||
|
||||
Creature creature = ToCreature();
|
||||
if (creature)
|
||||
@@ -547,8 +544,6 @@ namespace Game.Entities
|
||||
player.SetClientControl(this, true);
|
||||
}
|
||||
|
||||
EngageWithTarget(charmer);
|
||||
|
||||
// a guardian should always have charminfo
|
||||
if (playerCharmer && this != charmer.GetFirstControlled())
|
||||
playerCharmer.SendRemoveControlBar();
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
UpdateSplineMovement(diff);
|
||||
GetMotionMaster().UpdateMotion(diff);
|
||||
GetMotionMaster().Update(diff);
|
||||
}
|
||||
|
||||
void _UpdateSpells(uint diff)
|
||||
@@ -999,7 +999,7 @@ namespace Game.Entities
|
||||
init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), height, false);
|
||||
init.SetFacing(GetOrientation());
|
||||
init.SetTransportExit();
|
||||
GetMotionMaster().LaunchMoveSpline(init, EventId.VehicleExit, MovementSlot.Controlled);
|
||||
GetMotionMaster().LaunchMoveSpline(init, EventId.VehicleExit, MovementGeneratorPriority.Highest);
|
||||
|
||||
if (player != null)
|
||||
player.ResummonPetTemporaryUnSummonedIfAny();
|
||||
@@ -1353,7 +1353,7 @@ namespace Game.Entities
|
||||
// * Using 'call pet' on dead pets
|
||||
// * Using 'call stabled pet'
|
||||
// * Logging in with dead pets
|
||||
GetMotionMaster().Clear(false);
|
||||
GetMotionMaster().Clear();
|
||||
GetMotionMaster().MoveIdle();
|
||||
}
|
||||
StopMoving();
|
||||
|
||||
@@ -641,7 +641,7 @@ namespace Game.Entities
|
||||
init.MoveTo(veSeat.AttachmentOffset.X, veSeat.AttachmentOffset.Y, veSeat.AttachmentOffset.Z, false, true);
|
||||
init.SetFacing(0.0f);
|
||||
init.SetTransportEnter();
|
||||
Passenger.GetMotionMaster().LaunchMoveSpline(init, EventId.VehicleBoard, MovementSlot.Controlled);
|
||||
Passenger.GetMotionMaster().LaunchMoveSpline(init, EventId.VehicleBoard, MovementGeneratorPriority.Highest);
|
||||
|
||||
Creature creature = Target.GetBase().ToCreature();
|
||||
if (creature != null)
|
||||
|
||||
Reference in New Issue
Block a user