From c41fe84b8cf867ea07e71198eef1d63074e849c2 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Mon, 12 Apr 2021 10:32:44 +0200 Subject: [PATCH] Core/AI: reduce differences in ScriptedEscortAI between 4.x and 335 --- .../game/AI/ScriptedAI/ScriptedEscortAI.cpp | 26 +++++++++---------- .../WaypointMovementGenerator.cpp | 6 ++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index b2850abeb5b..804787b5381 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -174,7 +174,7 @@ bool EscortAI::IsPlayerOrGroupInRange() void EscortAI::UpdateAI(uint32 diff) { // Waypoint Updating - if (HasEscortState(STATE_ESCORT_ESCORTING) && !me->IsInCombat() && !HasEscortState(STATE_ESCORT_RETURNING)) + if (HasEscortState(STATE_ESCORT_ESCORTING) && !me->IsEngaged() && !HasEscortState(STATE_ESCORT_RETURNING)) { if (_pauseTimer <= diff) { @@ -227,7 +227,7 @@ void EscortAI::UpdateAI(uint32 diff) } // Check if player or any member of his group is within range - if (_despawnAtFar && HasEscortState(STATE_ESCORT_ESCORTING) && _playerGUID && !me->GetVictim() && !HasEscortState(STATE_ESCORT_RETURNING)) + if (_despawnAtFar && HasEscortState(STATE_ESCORT_ESCORTING) && _playerGUID && !me->IsEngaged() && !HasEscortState(STATE_ESCORT_RETURNING)) { if (_playerCheckTimer <= diff) { @@ -239,10 +239,13 @@ void EscortAI::UpdateAI(uint32 diff) if (CreatureData const* creatureData = me->GetCreatureData()) isEscort = (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (creatureData->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)); - if (_instantRespawn && !isEscort) - me->DespawnOrUnsummon(0, Seconds(1)); - else if (_instantRespawn && isEscort) - me->GetMap()->Respawn(SPAWN_TYPE_CREATURE, me->GetSpawnId()); + if (_instantRespawn) + { + if (!isEscort) + me->DespawnOrUnsummon(0s, 1s); + else + me->GetMap()->Respawn(SPAWN_TYPE_CREATURE, me->GetSpawnId()); + } else me->DespawnOrUnsummon(); @@ -368,16 +371,13 @@ void EscortAI::SetRun(bool on) void EscortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */, ObjectGuid playerGUID /* = 0 */, Quest const* quest /* = nullptr */, bool instantRespawn /* = false */, bool canLoopPath /* = false */, bool resetWaypoints /* = true */) { // Queue respawn from the point it starts - if (Map* map = me->GetMap()) + if (CreatureData const* cdata = me->GetCreatureData()) { - if (CreatureData const* cdata = me->GetCreatureData()) - { - if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)) - me->SaveRespawnTime(me->GetRespawnDelay()); - } + if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)) + me->SaveRespawnTime(me->GetRespawnDelay()); } - if (me->GetVictim()) + if (me->IsEngaged()) { TC_LOG_ERROR("scripts", "EscortAI::Start: (script: %s, creature entry: %u) attempts to Start while in combat", me->GetScriptName().c_str(), me->GetEntry()); return; diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index f31ee04585d..a13da64c4d4 100755 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -132,7 +132,7 @@ void WaypointMovementGenerator::HandleMovementInformationHooks(Creatur // Inform the AI that the path has ended. if (creature->IsAIEnabled) - creature->AI()->WaypointPathEnded(_path->Nodes.at(_currentNode).Id, _path->Id); + creature->AI()->WaypointPathEnded(waypoint.Id, _path->Id); } if (waypoint.EventId && urand(0, 99) < waypoint.EventChance) @@ -142,6 +142,8 @@ void WaypointMovementGenerator::HandleMovementInformationHooks(Creatur creature->GetMap()->ScriptsStart(sWaypointScripts, waypoint.EventId, creature, nullptr); } + creature->UpdateCurrentWaypointInfo(waypoint.Id, _path->Id); + // inform AI if (creature->IsAIEnabled) { @@ -149,8 +151,6 @@ void WaypointMovementGenerator::HandleMovementInformationHooks(Creatur creature->AI()->WaypointReached(waypoint.Id, _path->Id); } - creature->UpdateCurrentWaypointInfo(waypoint.Id, _path->Id); - // All hooks called and infos updated. Time to increment the waypoint node id if (_path && !_path->Nodes.empty()) // ensure that the path has not been changed in one of the hooks. _currentNode = (_currentNode + 1) % _path->Nodes.size();