Core/Movement: allow MotionMaster::MovePoint to use velocity arguments and implement speed paramemters for SMART_ACTION_MOVE_OFFSET and SMART_ACTION_MOVE_TO_POS

This commit is contained in:
Ovahlord committed 2020-10-30 18:57:09 +01:00
1 parent 9320382d90
commit 961f82988d
4 files changed
+19 -9

No files matched your search

@@ -1207,13 +1207,15 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
Position pos = target->GetPosition();
float speed = (float)e.action.moveOffset.speed / 10;
// Use forward/backward/left/right cartesian plane movement
float x, y, z, o;
o = pos.GetOrientation();
x = pos.GetPositionX() + (std::cos(o - (M_PI / 2))*e.target.x) + (std::cos(o)*e.target.y);
y = pos.GetPositionY() + (std::sin(o - (M_PI / 2))*e.target.x) + (std::sin(o)*e.target.y);
z = pos.GetPositionZ() + e.target.z;
target->ToCreature()->GetMotionMaster()->MovePoint(SMART_RANDOM_POINT, x, y, z);
target->ToCreature()->GetMotionMaster()->MovePoint(SMART_RANDOM_POINT, x, y, z, true, speed);
}
break;
}
@@ -1500,6 +1502,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
target = Trinity::Containers::SelectRandomContainerElement(targets);
}
float speed = (float)e.action.MoveToPos.speed / 10;
if (!target)
{
G3D::Vector3 dest(e.target.x, e.target.y, e.target.z);
@@ -1507,7 +1511,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (TransportBase* trans = me->GetDirectTransport())
trans->CalculatePassengerPosition(dest.x, dest.y, dest.z);
me->GetMotionMaster()->MovePoint(e.action.MoveToPos.pointId, dest.x, dest.y, dest.z, e.action.MoveToPos.disablePathfinding == 0);
me->GetMotionMaster()->MovePoint(e.action.MoveToPos.pointId, dest.x, dest.y, dest.z, e.action.MoveToPos.disablePathfinding == 0, speed);
}
else
{
@@ -1515,7 +1519,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
target->GetPosition(x, y, z);
if (e.action.MoveToPos.ContactDistance > 0)
target->GetContactPoint(me, x, y, z, e.action.MoveToPos.ContactDistance);
me->GetMotionMaster()->MovePoint(e.action.MoveToPos.pointId, x + e.target.x, y + e.target.y, z + e.target.z, e.action.MoveToPos.disablePathfinding == 0);
me->GetMotionMaster()->MovePoint(e.action.MoveToPos.pointId, x + e.target.x, y + e.target.y, z + e.target.z, e.action.MoveToPos.disablePathfinding == 0, speed);
}
break;
}
@@ -826,6 +826,11 @@ struct SmartAction
uint32 distance;
} moveRandom;
struct
{
uint32 speed;
} moveOffset;
struct
{
uint32 state;
@@ -1027,6 +1032,7 @@ struct SmartAction
uint32 transport;
uint32 disablePathfinding;
uint32 ContactDistance;
uint32 speed;
} MoveToPos;
struct
+3 -3
View File
@@ -309,17 +309,17 @@ void MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
Mutate(new FleeingMovementGenerator<Player>(enemy->GetGUID()), MOTION_SLOT_CONTROLLED);
}
void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generatePath)
void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generatePath, float speed)
{
if (_owner->GetTypeId() == TYPEID_PLAYER)
{
TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MovePoint: '%s', targeted point Id: %u (X: %f, Y: %f, Z: %f)", _owner->GetGUID().ToString().c_str(), id, x, y, z);
Mutate(new PointMovementGenerator<Player>(id, x, y, z, generatePath, 0.0f), MOTION_SLOT_ACTIVE);
Mutate(new PointMovementGenerator<Player>(id, x, y, z, generatePath, speed), MOTION_SLOT_ACTIVE);
}
else
{
TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MovePoint: '%s', targeted point Id: %u (X: %f, Y: %f, Z: %f)", _owner->GetGUID().ToString().c_str(), id, x, y, z);
Mutate(new PointMovementGenerator<Creature>(id, x, y, z, generatePath, 0.0f), MOTION_SLOT_ACTIVE);
Mutate(new PointMovementGenerator<Creature>(id, x, y, z, generatePath, speed), MOTION_SLOT_ACTIVE);
}
}
+3 -3
View File
@@ -155,12 +155,12 @@ class TC_GAME_API MotionMaster
void MoveConfused();
void MoveFleeing(Unit* enemy, uint32 time = 0);
void MovePoint(uint32 id, Position const& pos, bool generatePath = true)
void MovePoint(uint32 id, Position const& pos, bool generatePath = true, float speed = 0.f)
{
MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath);
MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath, speed);
}
void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true);
void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true, float speed = 0.f);
/* Makes the unit move toward the target until it is at a certain distance from it. The unit then stops.
Only works in 2D.