bool SetNextWaypoint(uint pointId, bool setPosition, bool resetWaypointsOnFail) { if (!WaypointList.Empty()) { WaypointList.Clear(); } FillPointMovementListForCreature(); if (WaypointList.Empty()) { return(false); } int size = WaypointList.Count; Escort_Waypoint waypoint; do { waypoint = WaypointList.First(); WaypointList.RemoveAt(0); if (waypoint.Id == pointId) { if (setPosition) { me.UpdatePosition(waypoint.X, waypoint.Y, waypoint.Z, me.GetOrientation()); } CurrentWPIndex = 0; return(true); } }while (!WaypointList.Empty()); // we failed. // we reset the waypoints in the start; if we pulled any, reset it again if (resetWaypointsOnFail && size != WaypointList.Count) { if (!WaypointList.Empty()) { WaypointList.Clear(); } FillPointMovementListForCreature(); } return(false); }
/// todo get rid of this many variables passed in function. public void Start(bool isActiveAttacker = true, bool run = false, ObjectGuid playerGUID = default, Quest quest = null, bool instantRespawn = false, bool canLoopPath = false, bool resetWaypoints = true) { if (me.GetVictim()) { Log.outError(LogFilter.Server, "TSCR ERROR: EscortAI (script: {0}, creature entry: {1}) attempts to Start while in combat", me.GetScriptName(), me.GetEntry()); return; } if (HasEscortState(EscortState.Escorting)) { Log.outError(LogFilter.Scripts, "EscortAI (script: {0}, creature entry: {1}) attempts to Start while already escorting", me.GetScriptName(), me.GetEntry()); return; } if (!ScriptWP && resetWaypoints) { if (!WaypointList.Empty()) { WaypointList.Clear(); } FillPointMovementListForCreature(); } if (WaypointList.Empty()) { Log.outError(LogFilter.Scripts, $"EscortAI (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) starts with 0 waypoints (possible missing entry in script_waypoint. Quest: {(quest != null ? quest.Id : 0)})."); return; } //set variables m_bIsActiveAttacker = isActiveAttacker; m_bIsRunning = run; m_uiPlayerGUID = playerGUID; m_pQuestForEscort = quest; m_bCanInstantRespawn = instantRespawn; m_bCanReturnToStart = canLoopPath; if (m_bCanReturnToStart && m_bCanInstantRespawn) { Log.outDebug(LogFilter.Scripts, "EscortAI is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn."); } if (me.GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Waypoint) { me.GetMotionMaster().MovementExpired(); me.GetMotionMaster().MoveIdle(); Log.outDebug(LogFilter.Scripts, "EscortAI start with WAYPOINT_MOTION_TYPE, changed to MoveIdle."); } //disable npcflags me.SetNpcFlags(NPCFlags.None); me.SetNpcFlags2(NPCFlags2.None); if (me.HasUnitFlag(UnitFlags.ImmuneToNpc)) { HasImmuneToNPCFlags = true; me.RemoveUnitFlag(UnitFlags.ImmuneToNpc); } Log.outDebug(LogFilter.Scripts, $"EscortAI started. ActiveAttacker = {m_bIsActiveAttacker}, Run = {m_bIsRunning}, PlayerGUID = {m_uiPlayerGUID.ToString()}"); CurrentWPIndex = 0; //Set initial speed if (m_bIsRunning) { me.SetWalk(false); } else { me.SetWalk(true); } AddEscortState(EscortState.Escorting); }
public void Clear() { WaypointList.Clear(); }