public int PeekNextWaypointIndex() { if (this.WaypointSet == null || this.WaypointSet.Points.Count == 0) { return(this.CurrentWaypointIndex); } int currentWaypointIndex = this.CurrentWaypointIndex; Rust.Ai.WaypointSet.NavModes navMode = this.WaypointSet.NavMode; if (navMode == Rust.Ai.WaypointSet.NavModes.Loop) { currentWaypointIndex++; if (currentWaypointIndex >= this.WaypointSet.Points.Count) { currentWaypointIndex = 0; } else if (currentWaypointIndex < 0) { currentWaypointIndex = this.WaypointSet.Points.Count - 1; } } else if (navMode == Rust.Ai.WaypointSet.NavModes.PingPong) { currentWaypointIndex += this.WaypointDirection; if (currentWaypointIndex >= this.WaypointSet.Points.Count) { currentWaypointIndex = this.CurrentWaypointIndex - 1; } else if (currentWaypointIndex < 0) { currentWaypointIndex = 0; } } return(currentWaypointIndex); }
public int GetNextWaypointIndex() { if (this.WaypointSet == null || this.WaypointSet.Points.Count == 0 || this.WaypointSet.Points[this.PeekNextWaypointIndex()].IsOccupied) { return(this.CurrentWaypointIndex); } int currentWaypointIndex = this.CurrentWaypointIndex; if (currentWaypointIndex >= 0 && currentWaypointIndex < this.WaypointSet.Points.Count) { Rust.Ai.WaypointSet.Waypoint item = this.WaypointSet.Points[currentWaypointIndex]; item.IsOccupied = false; this.WaypointSet.Points[currentWaypointIndex] = item; } Rust.Ai.WaypointSet.NavModes navMode = this.WaypointSet.NavMode; if (navMode == Rust.Ai.WaypointSet.NavModes.Loop) { currentWaypointIndex++; if (currentWaypointIndex >= this.WaypointSet.Points.Count) { currentWaypointIndex = 0; } else if (currentWaypointIndex < 0) { currentWaypointIndex = this.WaypointSet.Points.Count - 1; } } else { if (navMode != Rust.Ai.WaypointSet.NavModes.PingPong) { throw new ArgumentOutOfRangeException(); } currentWaypointIndex += this.WaypointDirection; if (currentWaypointIndex >= this.WaypointSet.Points.Count) { currentWaypointIndex = this.CurrentWaypointIndex - 1; this.WaypointDirection = -1; } else if (currentWaypointIndex < 0) { currentWaypointIndex = 0; this.WaypointDirection = 1; } } if (currentWaypointIndex >= 0 && currentWaypointIndex < this.WaypointSet.Points.Count) { Rust.Ai.WaypointSet.Waypoint waypoint = this.WaypointSet.Points[currentWaypointIndex]; waypoint.IsOccupied = true; this.WaypointSet.Points[currentWaypointIndex] = waypoint; } return(currentWaypointIndex); }