diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index a620b28d9..b312e1af3 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -2506,10 +2506,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } case SMART_ACTION_START_CLOSEST_WAYPOINT: { - std::vector waypoints; - std::copy_if(e.action.closestWaypointFromList.wps.begin(), e.action.closestWaypointFromList.wps.end(), - std::back_inserter(waypoints), [](uint32 wp) { return wp != 0; }); - float distanceToClosest = std::numeric_limits::max(); uint32 closestWpId = 0; @@ -2519,13 +2515,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u { if (IsSmart(creature)) { - for (uint32 wp : waypoints) + for (uint32 wp = e.action.startClosestWaypoint.pathId1; wp <= e.action.startClosestWaypoint.pathId2; ++wp) { WPPath* path = sSmartWaypointMgr->GetPath(wp); if (!path || path->empty()) continue; - //waypoint pointid always starts at 1, never 0! auto itrWp = path->find(1); if (itrWp != path->end()) { @@ -2542,7 +2537,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } if (closestWpId) - CAST_AI(SmartAI, creature->AI())->StartPath(false, closestWpId, true); + { + bool repeat = e.action.startClosestWaypoint.repeat; + bool run = e.action.startClosestWaypoint.run; + + CAST_AI(SmartAI, creature->AI())->StartPath(repeat, closestWpId, run); + } } } } diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index 834e48007..0040e0bd3 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -806,7 +806,7 @@ bool SmartAIMgr::CheckUnusedActionParams(SmartScriptHolder const& e) case SMART_ACTION_REMOVE_POWER: return sizeof(SmartAction::power); case SMART_ACTION_GAME_EVENT_STOP: return sizeof(SmartAction::gameEventStop); case SMART_ACTION_GAME_EVENT_START: return sizeof(SmartAction::gameEventStart); - case SMART_ACTION_START_CLOSEST_WAYPOINT: return sizeof(SmartAction::closestWaypointFromList); + case SMART_ACTION_START_CLOSEST_WAYPOINT: return sizeof(SmartAction::startClosestWaypoint); case SMART_ACTION_RISE_UP: return sizeof(SmartAction::moveRandom); case SMART_ACTION_RANDOM_SOUND: return sizeof(SmartAction::randomSound); case SMART_ACTION_SET_CORPSE_DELAY: return sizeof(SmartAction::corpseDelay); @@ -1536,15 +1536,22 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) break; } case SMART_ACTION_START_CLOSEST_WAYPOINT: + { + if (e.action.startClosestWaypoint.pathId1 == 0 || e.action.startClosestWaypoint.pathId2 == 0 || e.action.startClosestWaypoint.pathId2 < e.action.startClosestWaypoint.pathId1) { - if (std::all_of(e.action.closestWaypointFromList.wps.begin(), e.action.closestWaypointFromList.wps.end(), [](uint32 wp) { return wp == 0; })) - { - LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} does not have any non-zero waypoint id", - e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType()); - return false; - } - break; + LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} has invalid pathId1 or pathId2, it must be greater than 0 and pathId1 > pathId2", + e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType()); + return false; } + if (e.action.startClosestWaypoint.repeat > 1 || e.action.startClosestWaypoint.run > 1) + { + LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} has invalid run ({}) or repeat ({}) parameter, must be 0 or 1.", + e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), + e.action.startClosestWaypoint.repeat, e.action.startClosestWaypoint.run); + return false; + } + break; + } case SMART_ACTION_INVOKER_CAST: if (e.GetScriptType() != SMART_SCRIPT_TYPE_TIMED_ACTIONLIST && e.GetEventType() != SMART_EVENT_LINK && !EventHasInvoker(e.event.type)) { diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index 994129ecf..4f29d9c51 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -1284,8 +1284,11 @@ struct SmartAction struct { - std::array wps; - } closestWaypointFromList; + uint32 pathId1; + uint32 pathId2; + uint32 repeat; + uint32 run; + } startClosestWaypoint; struct {