@@ -15,14 +15,7 @@ EndScriptData */
15
15
16
16
const float MAX_PLAYER_DISTANCE = 66 .0f ;
17
17
18
- enum
19
- {
20
- POINT_LAST_POINT = 0xFFFFFF ,
21
- POINT_HOME = 0xFFFFFE
22
- };
23
-
24
18
npc_escortAI::npc_escortAI (Creature* pCreature) : ScriptedAI(pCreature),
25
- m_uiWPWaitTimer(2500 ),
26
19
m_uiPlayerCheckTimer(1000 ),
27
20
m_uiEscortState(STATE_ESCORT_NONE),
28
21
m_pQuestForEscort(NULL ),
@@ -43,10 +36,8 @@ void npc_escortAI::GetAIInformation(ChatHandler& reader)
43
36
44
37
if (HasEscortState (STATE_ESCORT_ESCORTING))
45
38
{
46
- oss << " \n EscortFlags: Escorting" << (HasEscortState (STATE_ESCORT_RETURNING) ? " , Returning" : " " ) << (HasEscortState (STATE_ESCORT_PAUSED) ? " , Paused" : " " );
47
-
48
- if (CurrentWP != WaypointList.end ())
49
- oss << " \n Next Waypoint Id = " << CurrentWP->uiId << " Position: " << CurrentWP->fX << " " << CurrentWP->fY << " " << CurrentWP->fZ ;
39
+ oss << " \n EscortFlags: Escorting" << (HasEscortState (STATE_ESCORT_RETURNING) ? " , Returning" : " " ) << (HasEscortState (STATE_ESCORT_PAUSED) ? " , Paused" : " " ) << " \n " ;
40
+ m_creature->GetMotionMaster ()->GetWaypointPathInformation (oss);
50
41
}
51
42
52
43
reader.PSendSysMessage (oss.str ().c_str ());
@@ -60,36 +51,6 @@ bool npc_escortAI::IsVisible(Unit* pWho) const
60
51
return m_creature->IsWithinDist (pWho, VISIBLE_RANGE) && pWho->isVisibleForOrDetect (m_creature, m_creature, true );
61
52
}
62
53
63
- void npc_escortAI::AttackStart (Unit* pWho)
64
- {
65
- if (!pWho)
66
- return ;
67
-
68
- if (m_creature->Attack (pWho, true ))
69
- {
70
- m_creature->AddThreat (pWho);
71
- m_creature->SetInCombatWith (pWho);
72
- pWho->SetInCombatWith (m_creature);
73
-
74
- if (m_creature->GetMotionMaster ()->GetCurrentMovementGeneratorType () == POINT_MOTION_TYPE)
75
- m_creature->GetMotionMaster ()->MovementExpired ();
76
-
77
- if (IsCombatMovement ())
78
- m_creature->GetMotionMaster ()->MoveChase (pWho);
79
- }
80
- }
81
-
82
- void npc_escortAI::EnterCombat (Unit* pEnemy)
83
- {
84
- // Store combat start position
85
- m_creature->SetCombatStartPosition (m_creature->GetPositionX (), m_creature->GetPositionY (), m_creature->GetPositionZ ());
86
-
87
- if (!pEnemy)
88
- return ;
89
-
90
- Aggro (pEnemy);
91
- }
92
-
93
54
void npc_escortAI::Aggro (Unit* /* pEnemy*/ ) {}
94
55
95
56
// see followerAI
@@ -201,36 +162,6 @@ void npc_escortAI::JustRespawned()
201
162
if (!IsCombatMovement ())
202
163
SetCombatMovement (true );
203
164
204
- // add a small delay before going to first waypoint, normal in near all cases
205
- m_uiWPWaitTimer = 2500 ;
206
-
207
- Reset ();
208
- }
209
-
210
- void npc_escortAI::EnterEvadeMode ()
211
- {
212
- m_creature->RemoveAllAurasOnEvade ();
213
- m_creature->DeleteThreatList ();
214
- m_creature->CombatStop (true );
215
- m_creature->SetLootRecipient (NULL );
216
-
217
- if (HasEscortState (STATE_ESCORT_ESCORTING))
218
- {
219
- // We have left our path
220
- if (m_creature->GetMotionMaster ()->GetCurrentMovementGeneratorType () != POINT_MOTION_TYPE)
221
- {
222
- debug_log (" SD2: EscortAI has left combat and is now returning to CombatStartPosition." );
223
-
224
- AddEscortState (STATE_ESCORT_RETURNING);
225
-
226
- float fPosX , fPosY , fPosZ ;
227
- m_creature->GetCombatStartPosition (fPosX , fPosY , fPosZ );
228
- m_creature->GetMotionMaster ()->MovePoint (POINT_LAST_POINT, fPosX , fPosY , fPosZ );
229
- }
230
- }
231
- else
232
- m_creature->GetMotionMaster ()->MoveTargetedHome ();
233
-
234
165
Reset ();
235
166
}
236
167
@@ -256,66 +187,8 @@ bool npc_escortAI::IsPlayerOrGroupInRange()
256
187
return false ;
257
188
}
258
189
259
- // Returns false, if npc is despawned
260
- bool npc_escortAI::MoveToNextWaypoint ()
261
- {
262
- // Do nothing if escorting is paused
263
- if (HasEscortState (STATE_ESCORT_PAUSED))
264
- return true ;
265
-
266
- // Final Waypoint reached (and final wait time waited)
267
- if (CurrentWP == WaypointList.end ())
268
- {
269
- debug_log (" SD2: EscortAI reached end of waypoints" );
270
-
271
- if (m_bCanReturnToStart)
272
- {
273
- float fRetX , fRetY , fRetZ ;
274
- m_creature->GetRespawnCoord (fRetX , fRetY , fRetZ );
275
-
276
- m_creature->GetMotionMaster ()->MovePoint (POINT_HOME, fRetX , fRetY , fRetZ );
277
-
278
- m_uiWPWaitTimer = 0 ;
279
-
280
- debug_log (" SD2: EscortAI are returning home to spawn location: %u, %f, %f, %f" , POINT_HOME, fRetX , fRetY , fRetZ );
281
- return true ;
282
- }
283
-
284
- if (m_bCanInstantRespawn)
285
- {
286
- m_creature->SetDeathState (JUST_DIED);
287
- m_creature->Respawn ();
288
- }
289
- else
290
- m_creature->ForcedDespawn ();
291
-
292
- return false ;
293
- }
294
-
295
- m_creature->GetMotionMaster ()->MovePoint (CurrentWP->uiId , CurrentWP->fX , CurrentWP->fY , CurrentWP->fZ );
296
- debug_log (" SD2: EscortAI start waypoint %u (%f, %f, %f)." , CurrentWP->uiId , CurrentWP->fX , CurrentWP->fY , CurrentWP->fZ );
297
-
298
- WaypointStart (CurrentWP->uiId );
299
-
300
- m_uiWPWaitTimer = 0 ;
301
-
302
- return true ;
303
- }
304
-
305
190
void npc_escortAI::UpdateAI (const uint32 uiDiff)
306
191
{
307
- // Waypoint Updating
308
- if (HasEscortState (STATE_ESCORT_ESCORTING) && !m_creature->getVictim () && m_uiWPWaitTimer && !HasEscortState (STATE_ESCORT_RETURNING))
309
- {
310
- if (m_uiWPWaitTimer <= uiDiff)
311
- {
312
- if (!MoveToNextWaypoint ())
313
- return ;
314
- }
315
- else
316
- m_uiWPWaitTimer -= uiDiff;
317
- }
318
-
319
192
// Check if player or any member of his group is within range
320
193
if (HasEscortState (STATE_ESCORT_ESCORTING) && m_playerGuid && !m_creature->getVictim () && !HasEscortState (STATE_ESCORT_RETURNING))
321
194
{
@@ -356,107 +229,40 @@ void npc_escortAI::UpdateEscortAI(const uint32 /*uiDiff*/)
356
229
357
230
void npc_escortAI::MovementInform (uint32 uiMoveType, uint32 uiPointId)
358
231
{
359
- if (uiMoveType != POINT_MOTION_TYPE || !HasEscortState (STATE_ESCORT_ESCORTING))
232
+ if (uiMoveType < EXTERNAL_WAYPOINT_MOVE || !HasEscortState (STATE_ESCORT_ESCORTING))
360
233
return ;
361
234
362
- // Combat start position reached, continue waypoint movement
363
- if (uiPointId == POINT_LAST_POINT)
364
- {
365
- debug_log (" SD2: EscortAI has returned to original position before combat" );
235
+ // uint32 pathId = uiMoveType & 0xFF;
366
236
367
- m_creature->SetWalk (!m_bIsRunning);
368
- RemoveEscortState (STATE_ESCORT_RETURNING);
369
- }
370
- else if (uiPointId == POINT_HOME)
237
+ if (uiMoveType < EXTERNAL_WAYPOINT_MOVE_START)
238
+ WaypointReached (uiPointId);
239
+ else if (uiMoveType < EXTERNAL_WAYPOINT_FINISHED_LAST)
240
+ WaypointStart (uiPointId);
241
+ else // Last WP Reached
371
242
{
372
- debug_log (" SD2: EscortAI has returned to original home location and will continue from beginning of waypoint list." );
373
-
374
- CurrentWP = WaypointList.begin ();
375
- m_uiWPWaitTimer = 0 ;
376
- }
377
- else
378
- {
379
- // Make sure that we are still on the right waypoint
380
- if (CurrentWP->uiId != uiPointId)
243
+ if (m_bCanInstantRespawn)
381
244
{
382
- script_error_log ( " EscortAI for Npc %u reached waypoint out of order %u, expected %u. " , m_creature->GetEntry (), uiPointId, CurrentWP-> uiId );
383
- return ;
245
+ m_creature->SetDeathState (JUST_DIED );
246
+ m_creature-> Respawn () ;
384
247
}
385
-
386
- debug_log (" SD2: EscortAI waypoint %u reached." , CurrentWP->uiId );
387
-
388
- // In case we were moving while in combat, we should evade back to this position
389
- m_creature->SetCombatStartPosition (m_creature->GetPositionX (), m_creature->GetPositionY (), m_creature->GetPositionZ ());
390
-
391
- // Call WP function
392
- WaypointReached (CurrentWP->uiId );
393
-
394
- m_uiWPWaitTimer = CurrentWP->uiWaitTime ;
395
-
396
- ++CurrentWP;
397
- }
398
-
399
- if (!m_uiWPWaitTimer)
400
- {
401
- // Continue WP Movement if Can
402
- if (HasEscortState (STATE_ESCORT_ESCORTING) && !HasEscortState (STATE_ESCORT_PAUSED | STATE_ESCORT_RETURNING) && !m_creature->getVictim ())
403
- MoveToNextWaypoint ();
404
248
else
405
- m_uiWPWaitTimer = 1 ;
406
- }
407
- }
408
-
409
- /* void npc_escortAI::AddWaypoint(uint32 id, float x, float y, float z, uint32 WaitTimeMs)
410
- {
411
- Escort_Waypoint t(id, x, y, z, WaitTimeMs);
412
-
413
- WaypointList.push_back(t);
414
- }*/
415
-
416
- void npc_escortAI::FillPointMovementListForCreature ()
417
- {
418
- std::vector<ScriptPointMove> const & pPointsEntries = pSystemMgr.GetPointMoveList (m_creature->GetEntry ());
419
-
420
- if (pPointsEntries.empty ())
421
- return ;
422
-
423
- std::vector<ScriptPointMove>::const_iterator itr;
424
-
425
- for (itr = pPointsEntries.begin (); itr != pPointsEntries.end (); ++itr)
426
- {
427
- Escort_Waypoint pPoint (itr->uiPointId , itr->fX , itr->fY , itr->fZ , itr->uiWaitTime );
428
- WaypointList.push_back (pPoint);
249
+ m_creature->ForcedDespawn ();
429
250
}
430
251
}
431
252
432
253
void npc_escortAI::SetCurrentWaypoint (uint32 uiPointId)
433
254
{
434
255
if (!(HasEscortState (STATE_ESCORT_PAUSED))) // Only when paused
435
- return ;
436
-
437
- if (uiPointId == CurrentWP->uiId ) // Already here
438
- return ;
439
-
440
- bool bFoundWaypoint = false ;
441
- for (std::list<Escort_Waypoint>::iterator itr = WaypointList.begin (); itr != WaypointList.end (); ++itr)
442
256
{
443
- if (itr->uiId == uiPointId)
444
- {
445
- CurrentWP = itr; // Set to found itr
446
- bFoundWaypoint = true ;
447
- break ;
448
- }
257
+ script_error_log (" EscortAI for %s tried to set new waypoint %u, but not paused" , m_creature->GetGuidStr ().c_str (), uiPointId);
258
+ return ;
449
259
}
450
260
451
- if (!bFoundWaypoint )
261
+ if (!m_creature-> GetMotionMaster ()-> SetNextWaypoint (uiPointId) )
452
262
{
453
- debug_log ( " SD2: EscortAI current waypoint tried to set to id %u, but doesn't exist in WaypointList " , uiPointId);
263
+ script_error_log ( " EscortAI for %s current waypoint tried to set to id %u, but doesn't exist in this path " , m_creature-> GetGuidStr (). c_str () , uiPointId);
454
264
return ;
455
265
}
456
-
457
- m_uiWPWaitTimer = 1 ;
458
-
459
- debug_log (" SD2: EscortAI current waypoint set to id %u" , CurrentWP->uiId );
460
266
}
461
267
462
268
void npc_escortAI::SetRun (bool bRun)
@@ -493,14 +299,9 @@ void npc_escortAI::Start(bool bRun, const Player* pPlayer, const Quest* pQuest,
493
299
return ;
494
300
}
495
301
496
- if (!WaypointList.empty ())
497
- WaypointList.clear ();
498
-
499
- FillPointMovementListForCreature ();
500
-
501
- if (WaypointList.empty ())
302
+ if (!pSystemMgr.GetPathInfo (m_creature->GetEntry (), 1 ))
502
303
{
503
- error_db_log ( " SD2: EscortAI Start with 0 waypoints (possible missing entry in script_waypoint). " );
304
+ script_error_log ( " EscortAI attempt to start escorting for %s, but has no waypints loaded " , m_creature-> GetGuidStr (). c_str () );
504
305
return ;
505
306
}
506
307
@@ -516,24 +317,19 @@ void npc_escortAI::Start(bool bRun, const Player* pPlayer, const Quest* pQuest,
516
317
if (m_bCanReturnToStart && m_bCanInstantRespawn)
517
318
debug_log (" SD2: EscortAI is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn." );
518
319
519
- if (m_creature->GetMotionMaster ()->GetCurrentMovementGeneratorType () == WAYPOINT_MOTION_TYPE)
520
- {
521
- m_creature->GetMotionMaster ()->MovementExpired ();
522
- m_creature->GetMotionMaster ()->MoveIdle ();
523
- debug_log (" SD2: EscortAI start with WAYPOINT_MOTION_TYPE, changed to MoveIdle." );
524
- }
525
-
526
320
// disable npcflags
527
321
m_creature->SetUInt32Value (UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
528
322
529
- debug_log (" SD2: EscortAI started with " SIZEFMTD " waypoints. Run = %d, PlayerGuid = %s" , WaypointList.size (), m_bIsRunning, m_playerGuid.GetString ().c_str ());
530
-
531
- CurrentWP = WaypointList.begin ();
323
+ AddEscortState (STATE_ESCORT_ESCORTING);
532
324
533
325
// Set initial speed
534
326
m_creature->SetWalk (!m_bIsRunning);
535
327
536
- AddEscortState (STATE_ESCORT_ESCORTING);
328
+ m_creature->StopMoving ();
329
+
330
+ // Start moving along the path with 2500ms delay
331
+ m_creature->GetMotionMaster ()->Clear (false , true );
332
+ m_creature->GetMotionMaster ()->MoveWaypoint (1 , 3 , 2500 );
537
333
538
334
JustStartedEscort ();
539
335
}
@@ -544,7 +340,13 @@ void npc_escortAI::SetEscortPaused(bool bPaused)
544
340
return ;
545
341
546
342
if (bPaused)
343
+ {
547
344
AddEscortState (STATE_ESCORT_PAUSED);
345
+ m_creature->addUnitState (UNIT_STAT_WAYPOINT_PAUSED);
346
+ }
548
347
else
348
+ {
549
349
RemoveEscortState (STATE_ESCORT_PAUSED);
350
+ m_creature->clearUnitState (UNIT_STAT_WAYPOINT_PAUSED);
351
+ }
550
352
}
0 commit comments