Skip to content

Commit 1db1a0e

Browse files
committed
Core/Movement: Enable MotionMaster::MovePath for players
1 parent 1f1c859 commit 1db1a0e

File tree

10 files changed

+198
-147
lines changed

10 files changed

+198
-147
lines changed

src/server/game/AI/CreatureAISelector.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,7 @@ namespace FactorySelector
131131

132132
MovementGenerator* SelectMovementGenerator(Unit* unit)
133133
{
134-
MovementGeneratorType type = unit->GetDefaultMovementType();
135-
if (Creature* creature = unit->ToCreature())
136-
if (!creature->GetPlayerMovingMe())
137-
type = creature->GetDefaultMovementType();
138-
139-
MovementGeneratorCreator const* mv_factory = sMovementGeneratorRegistry->GetRegistryItem(type);
134+
MovementGeneratorCreator const* mv_factory = sMovementGeneratorRegistry->GetRegistryItem(unit->GetDefaultMovementType());
140135
return ASSERT_NOTNULL(mv_factory)->Create(unit);
141136
}
142137

src/server/game/Entities/Creature/Creature.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,14 @@ bool Creature::CanSwim() const
29732973
return false;
29742974
}
29752975

2976+
MovementGeneratorType Creature::GetDefaultMovementType() const
2977+
{
2978+
if (!GetPlayerMovingMe())
2979+
return m_defaultMovementType;
2980+
2981+
return IDLE_MOTION_TYPE;
2982+
}
2983+
29762984
void Creature::AllLootRemovedFromCorpse()
29772985
{
29782986
time_t now = GameTime::GetGameTime();

src/server/game/Entities/Creature/Creature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
160160
bool CanEnterWater() const override { return (CanSwim() || IsAmphibious()); };
161161
bool CanFly() const override { return (IsFlying() || HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY)); }
162162

163-
MovementGeneratorType GetDefaultMovementType() const override { return m_defaultMovementType; }
163+
MovementGeneratorType GetDefaultMovementType() const override;
164164
void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
165165

166166
CreatureClassifications GetCreatureClassification() const { return GetCreatureTemplate()->Classification; }

src/server/game/Movement/MotionMaster.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,6 @@ void MotionMaster::MoveCharge(PathGenerator const& path, float speed /*= SPEED_C
803803

804804
void MotionMaster::MoveKnockbackFrom(Position const& origin, float speedXY, float speedZ, float angle /*= M_PI*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/)
805805
{
806-
// This function may make players fall below map
807-
if (_owner->GetTypeId() == TYPEID_PLAYER)
808-
return;
809-
810806
if (std::abs(speedXY) < 0.01f && std::abs(speedZ) < 0.01f)
811807
return;
812808

@@ -1144,8 +1140,13 @@ void MotionMaster::MovePath(uint32 pathId, bool repeatable, Optional<Millisecond
11441140

11451141
TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MovePath: '{}', starts moving over path Id: {} (repeatable: {})",
11461142
_owner->GetGUID(), pathId, repeatable ? "YES" : "NO");
1147-
Add(new WaypointMovementGenerator<Creature>(pathId, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd,
1148-
wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, exactSplinePath, generatePath, std::move(scriptResult)), MOTION_SLOT_DEFAULT);
1143+
1144+
if (_owner->GetTypeId() == TYPEID_UNIT)
1145+
Add(new WaypointMovementGenerator<Creature>(pathId, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd,
1146+
wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, exactSplinePath, generatePath, std::move(scriptResult)), MOTION_SLOT_DEFAULT);
1147+
else
1148+
Add(new WaypointMovementGenerator<Player>(pathId, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd,
1149+
wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, exactSplinePath, generatePath, std::move(scriptResult)), MOTION_SLOT_DEFAULT);
11491150
}
11501151

11511152
void MotionMaster::MovePath(WaypointPath const& path, bool repeatable, Optional<Milliseconds> duration /*= {}*/, Optional<float> speed /*= {}*/,
@@ -1157,8 +1158,13 @@ void MotionMaster::MovePath(WaypointPath const& path, bool repeatable, Optional<
11571158
{
11581159
TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MovePath: '{}', starts moving over path Id: {} (repeatable: {})",
11591160
_owner->GetGUID(), path.Id, repeatable ? "YES" : "NO");
1160-
Add(new WaypointMovementGenerator<Creature>(path, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd,
1161-
wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, exactSplinePath, generatePath, std::move(scriptResult)), MOTION_SLOT_DEFAULT);
1161+
1162+
if (_owner->GetTypeId() == TYPEID_UNIT)
1163+
Add(new WaypointMovementGenerator<Creature>(path, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd,
1164+
wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, exactSplinePath, generatePath, std::move(scriptResult)), MOTION_SLOT_DEFAULT);
1165+
else
1166+
Add(new WaypointMovementGenerator<Player>(path, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd,
1167+
wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, exactSplinePath, generatePath, std::move(scriptResult)), MOTION_SLOT_DEFAULT);
11621168
}
11631169

11641170
void MotionMaster::MoveRotate(uint32 id, RotateDirection direction, Optional<Milliseconds> time /*= {}*/,

src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct TaxiPathNodeEntry;
3030
* FlightPathMovementGenerator generates movement of the player for the paths
3131
* and hence generates ground and activities for the player.
3232
*/
33-
class FlightPathMovementGenerator : public MovementGeneratorMedium<Player, FlightPathMovementGenerator>, public PathMovementBase<Player, std::vector<TaxiPathNodeEntry const*>>
33+
class FlightPathMovementGenerator : public MovementGeneratorMedium<Player, FlightPathMovementGenerator>, public PathMovementBase<std::vector<TaxiPathNodeEntry const*>>
3434
{
3535
public:
3636
explicit FlightPathMovementGenerator(Optional<float> speed,

src/server/game/Movement/MovementGenerators/PathMovementBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "Define.h"
2222
#include <string>
2323

24-
template<class Entity, class BasePath>
24+
template<class BasePath>
2525
class PathMovementBase
2626
{
2727
public:

0 commit comments

Comments
 (0)