Core/Movement: waypoint movement

Port From (https://github.com/TrinityCore/TrinityCore/commit/97585597f0b1aff93873fe4d757556731bc0c1b2)
This commit is contained in:
hondacrx
2020-08-24 17:02:02 -04:00
parent c9e535bb3a
commit 3d3fd0f55f
31 changed files with 960 additions and 950 deletions
+42
View File
@@ -105,6 +105,21 @@ namespace Game.Entities
ForcedDespawn(0);
}
public override void PauseMovement(uint timer = 0, MovementSlot slot = 0)
{
base.PauseMovement(timer, slot);
SetHomePosition(GetPosition());
}
public bool IsReturningHome()
{
if (GetMotionMaster().GetMotionSlotType(MovementSlot.Active) == MovementGeneratorType.Home)
return true;
return false;
}
public void SearchFormation()
{
if (IsSummon())
@@ -119,6 +134,33 @@ namespace Game.Entities
FormationMgr.AddCreatureToGroup(frmdata.leaderGUID, this);
}
public bool IsFormationLeader()
{
if (m_formation == null)
return false;
return m_formation.IsLeader(this);
}
public void SignalFormationMovement(Position destination, uint id = 0, WaypointMoveType moveType = 0, bool orientation = false)
{
if (m_formation == null)
return;
if (!m_formation.IsLeader(this))
return;
m_formation.LeaderMoveTo(destination, id, moveType, orientation);
}
public bool IsFormationLeaderMoveAllowed()
{
if (m_formation == null)
return false;
return m_formation.CanLeaderStartMoving();
}
public void RemoveCorpse(bool setSpawnTime = true, bool destroyForNearbyPlayers = true)
{
if (GetDeathState() != DeathState.Corpse)
@@ -216,7 +216,7 @@ namespace Game.Entities
m_Formed = !dismiss;
}
public void LeaderMoveTo(Position destination, uint id = 0, uint moveType = 0, bool orientation = false)
public void LeaderMoveTo(Position destination, uint id = 0, WaypointMoveType moveType = 0, bool orientation = false)
{
//! To do: This should probably get its own movement generator or use WaypointMovementGenerator.
//! If the leader's path is known, member's path can be plotted as well using formation offsets.
@@ -258,11 +258,26 @@ namespace Game.Entities
}
}
public bool CanLeaderStartMoving()
{
foreach (var itr in m_members)
{
if (itr.Key != m_leader && itr.Key.IsAlive())
{
if (itr.Key.IsEngaged() || itr.Key.IsReturningHome())
return false;
}
}
return true;
}
public Creature GetLeader() { return m_leader; }
public uint GetId() { return m_groupID; }
public bool IsEmpty() { return m_members.Empty(); }
public bool IsFormed() { return m_Formed; }
public bool IsLeader(Creature creature) { return m_leader == creature; }
Creature m_leader;
Dictionary<Creature, FormationInfo> m_members = new Dictionary<Creature, FormationInfo>();
@@ -159,6 +159,28 @@ namespace Game.Entities
init.Stop();
}
public virtual void PauseMovement(uint timer = 0, MovementSlot slot = 0)
{
if (slot >= MovementSlot.Max)
return;
IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(slot);
if (movementGenerator != null)
movementGenerator.Pause(timer);
StopMoving();
}
public void ResumeMovement(uint timer = 0, MovementSlot slot = 0)
{
if (slot >= MovementSlot.Max)
return;
IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(slot);
if (movementGenerator != null)
movementGenerator.Resume(timer);
}
public void SetInFront(WorldObject target)
{
if (!HasUnitState(UnitState.CannotTurn))
+10 -1
View File
@@ -17,6 +17,7 @@
using Framework.Constants;
using Game.AI;
using Game.Movement;
using Game.Networking.Packets;
using Game.Spells;
using System.Collections.Generic;
@@ -351,8 +352,15 @@ namespace Game.Entities
if (IsTypeId(TypeId.Unit))
{
IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(MovementSlot.Idle);
if (movementGenerator != null)
movementGenerator.Pause(0);
GetMotionMaster().Clear(MovementSlot.Active);
StopMoving();
ToCreature().GetAI().OnCharmed(true);
GetMotionMaster().MoveIdle();
}
else
{
@@ -466,6 +474,7 @@ namespace Game.Entities
else
RestoreFaction();
///@todo Handle SLOT_IDLE motion resume
GetMotionMaster().InitDefault();
Creature creature = ToCreature();