Core/Movement: fixed waypoint movement commits up to 2ce9a0a094a3d86a86a9323693c93ed6a2bbcaaf

This commit is contained in:
Ovahlord committed 2018-08-02 16:20:02 +02:00
1 parent 075a79dac1
commit 78e0328356
14 files changed
+150 -75

No files matched your search

+78 -26
View File
@@ -31,8 +31,8 @@
SmartAI::SmartAI(Creature* creature) : CreatureAI(creature), mIsCharmed(false), mFollowCreditType(0), mFollowArrivedTimer(0), mFollowCredit(0), mFollowArrivedEntry(0), mFollowDist(0.f), mFollowAngle(0.f),
_escortState(SMART_ESCORT_NONE), _escortNPCFlags(0), _escortInvokerCheckTimer(1000), _currentWaypointNode(0), _waypointReached(false), _waypointPauseTimer(0), _waypointPauseForced(false), _repeatWaypointPath(false),
_OOCReached(false), _waypointPathEnded(false), mRun(true), mEvadeDisabled(false), mCanAutoAttack(true), mCanCombatMove(true), mInvincibilityHpLevel(0), mDespawnTime(0), mDespawnState(0), mJustReset(false),
mConditionsTimer(0), _gossipReturn(false)
_OOCReached(false), _waypointPathEnded(false), mRun(true), mEvadeDisabled(false), mCanAutoAttack(true), mCanCombatMove(true), mInvincibilityHpLevel(0), mDespawnTime(0), mDespawnState(0), mConditionsTimer(0),
_gossipReturn(false)
{
mHasConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, creature->GetEntry());
}
@@ -129,7 +129,15 @@ bool SmartAI::LoadPath(uint32 entry)
void SmartAI::PausePath(uint32 delay, bool forced)
{
if (!HasEscortState(SMART_ESCORT_ESCORTING))
{
me->PauseMovement(delay, MOTION_SLOT_IDLE, forced);
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
{
std::pair<uint32, uint32> waypointInfo = me->GetCurrentWaypointInfo();
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_PAUSED, nullptr, waypointInfo.first, waypointInfo.second);
}
return;
}
if (HasEscortState(SMART_ESCORT_PAUSED))
{
@@ -156,7 +164,28 @@ void SmartAI::PausePath(uint32 delay, bool forced)
void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
{
if (!HasEscortState(SMART_ESCORT_ESCORTING))
{
std::pair<uint32, uint32> waypointInfo = { 0, 0 };
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
waypointInfo = me->GetCurrentWaypointInfo();
if (mDespawnState != 2)
SetDespawnTime(DespawnTime);
me->GetMotionMaster()->MoveIdle();
if (waypointInfo.first)
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_STOPPED, nullptr, waypointInfo.first, waypointInfo.second);
if (!fail)
{
if (waypointInfo.first)
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, waypointInfo.first, waypointInfo.second);
if (mDespawnState == 1)
StartDespawn();
}
return;
}
if (quest)
mEscortQuestID = quest;
@@ -393,6 +422,16 @@ bool SmartAI::IsEscortInvokerInRange()
return true;
}
///@todo move escort related logic
void SmartAI::WaypointPathStarted(uint32 nodeId, uint32 pathId)
{
if (!HasEscortState(SMART_ESCORT_ESCORTING))
{
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, nodeId, pathId);
return;
}
}
///@todo Implement new smart event SMART_EVENT_WAYPOINT_STARTED
void SmartAI::WaypointStarted(uint32 /*nodeId*/, uint32 /*pathId*/)
{
@@ -400,6 +439,12 @@ void SmartAI::WaypointStarted(uint32 /*nodeId*/, uint32 /*pathId*/)
void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId)
{
if (!HasEscortState(SMART_ESCORT_ESCORTING))
{
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, nodeId, pathId);
return;
}
_currentWaypointNode = nodeId;
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, _currentWaypointNode, pathId);
@@ -419,6 +464,16 @@ void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId)
}
}
///@todo move escort related logic
void SmartAI::WaypointPathEnded(uint32 nodeId, uint32 pathId)
{
if (!HasEscortState(SMART_ESCORT_ESCORTING))
{
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, nodeId, pathId);
return;
}
}
void SmartAI::MovementInform(uint32 type, uint32 id)
{
if (type == POINT_MOTION_TYPE && id == SMART_ESCORT_LAST_OOC_POINT)
@@ -452,10 +507,16 @@ void SmartAI::EnterEvadeMode(EvadeReason /*why*/)
me->AddUnitState(UNIT_STATE_EVADE);
GetScript()->ProcessEventsFor(SMART_EVENT_EVADE);//must be after aura clear so we can cast spells from db
GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); // must be after _EnterEvadeMode (spells, auras, ...)
SetRun(mRun);
if (HasEscortState(SMART_ESCORT_ESCORTING))
if (Unit* owner = me->GetCharmerOrOwner())
{
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
me->ClearUnitState(UNIT_STATE_EVADE);
}
else if (HasEscortState(SMART_ESCORT_ESCORTING))
{
AddEscortState(SMART_ESCORT_RETURNING);
ReturnToLastOOCPos();
@@ -466,11 +527,6 @@ void SmartAI::EnterEvadeMode(EvadeReason /*why*/)
// evade is not cleared in MoveFollow, so we can't keep it
me->ClearUnitState(UNIT_STATE_EVADE);
}
else if (Unit* owner = me->GetCharmerOrOwner())
{
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
me->ClearUnitState(UNIT_STATE_EVADE);
}
else
me->GetMotionMaster()->MoveTargetedHome();
@@ -544,11 +600,13 @@ void SmartAI::JustAppeared()
mDespawnTime = 0;
mDespawnState = 0;
_escortState = SMART_ESCORT_NONE;
me->SetVisible(true);
if (me->GetFaction() != me->GetCreatureTemplate()->faction)
me->RestoreFaction();
mJustReset = true;
JustReachedHome();
GetScript()->OnReset();
GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN);
mFollowGuid.Clear(); // do not reset follower on Reset(), we need it after combat evade
mFollowDist = 0;
@@ -562,24 +620,18 @@ void SmartAI::JustAppeared()
void SmartAI::JustReachedHome()
{
GetScript()->OnReset();
GetScript()->ProcessEventsFor(SMART_EVENT_REACHED_HOME);
if (!mJustReset)
CreatureGroup* formation = me->GetFormation();
if (!formation || formation->getLeader() == me || !formation->isFormed())
{
GetScript()->ProcessEventsFor(SMART_EVENT_REACHED_HOME);
CreatureGroup* formation = me->GetFormation();
if (!formation || formation->getLeader() == me || !formation->isFormed())
{
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE && me->GetWaypointPath())
me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true);
else
me->ResumeMovement();
}
else if (formation->isFormed())
me->GetMotionMaster()->MoveIdle(); // wait the order of leader
if (me->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_IDLE) != WAYPOINT_MOTION_TYPE && me->GetWaypointPath())
me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true);
else
me->ResumeMovement();
}
mJustReset = false;
else if (formation->isFormed())
me->GetMotionMaster()->MoveIdle(); // wait the order of leader
}
void SmartAI::JustEngagedWith(Unit* enemy)