diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index 9d0ea02be..517c8eeb2 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1723,7 +1723,9 @@ void NPC::AI_DoMovement() { // reached our randomly selected destination; force a pause if (cur_wp_pause == 0) { - if (Waypoints.size() > 0 && Waypoints[0].pause) + if (Waypoints.size() >= cur_wp && Waypoints[cur_wp].pause) + cur_wp_pause = Waypoints[cur_wp].pause; + else if (Waypoints.size() > 0 && Waypoints[0].pause) cur_wp_pause = Waypoints[0].pause; else cur_wp_pause = 38; diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 1beca2c01..f88c4df39 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -385,8 +385,49 @@ void NPC::CalculateNewWaypoint() { if (cur_wp == patrol) // reutilizing patrol member instead of making new member for this wander type; here we use it to save a random waypoint { + if (!Waypoints[cur_wp].centerpoint) + { + // if we have arrived at a waypoint that is NOT a centerpoint, then check for the existence of any centerpoint waypoint + // if any exists then randomly go to it otherwise go to one that exist. + std::vector random_centerpoints; + for (auto& w : Waypoints) + { + wplist wpl = w; + if (wpl.index != cur_wp && wpl.centerpoint) + { + random_centerpoints.push_back(w); + } + } + + if (random_centerpoints.size() == 1) + { + patrol = random_centerpoints[0].index; + break; + } + else if (random_centerpoints.size() > 1) + { + int windex = zone->random.Roll0(random_centerpoints.size()); + patrol = random_centerpoints[windex].index; + break; + } + } + while (patrol == cur_wp) - patrol = zone->random.Int(0, Waypoints.size() - 1); + { + // Setting a negative number in pause of the select waypoints will NOT be included in the group of waypoints to be random. + // This will cause the NPC to not stop and pause in any of the waypoints that is not part of random waypoints. + std::vector random_waypoints; + for (auto& w : Waypoints) + { + wplist wpl = w; + if (wpl.index != cur_wp && wpl.pause >= 0 && !wpl.centerpoint) + { + random_waypoints.push_back(w); + } + } + int windex = zone->random.Roll0(random_waypoints.size()); + patrol = random_waypoints[windex].index; + } } if (patrol > cur_wp) cur_wp = cur_wp + 1;