void WaypointMovementGenerator<Creature>::Initialize(Creature &u) { u.StopMoving(); //i_currentNode = -1; // uint32, become 0 in the first update //i_nextMoveTime.Reset(0); StopedByPlayer = false; if (!path_id) path_id = u.GetWaypointPath(); waypoints = sWaypointMgr->GetPath(path_id); i_currentNode = 0; if (waypoints && waypoints->size()) { node = waypoints->front(); Traveller<Creature> traveller(u); InitTraveller(u, *node); i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); //Call for creature group update if (u.GetFormation() && u.GetFormation()->getLeader() == &u) u.GetFormation()->LeaderMoveTo(node->x, node->y, node->z); } else node = NULL; }
void WaypointMovementGenerator<Creature>::Initialize(Creature &u) { u.StopMoving(); //i_currentNode = -1; // uint32, become 0 in the first update //i_nextMoveTime.Reset(0); StopedByPlayer = false; if (!path_id) path_id = u.GetWaypointPath(); waypoints = sWaypointMgr->GetPath(path_id); i_currentNode = 0; if (waypoints && waypoints->size()) { node = waypoints->front(); Traveller<Creature> traveller(u); InitTraveller(u, *node); MoveToNextNode(traveller); } else node = NULL; }
void WaypointMovementGenerator<Creature>::Initialize(Creature &u) { u.StopMoving(); StopedByPlayer = false; if (!path_id) path_id = u.GetWaypointPath(); waypoints = sWaypointMgr->GetPath(path_id); i_currentNode = 0; if (waypoints && waypoints->size()) { node = waypoints->front(); Traveller<Creature> traveller(u); InitTraveller(u, *node); MoveToNextNode(traveller); //Call for creature group update if (u.GetFormation() && u.GetFormation()->getLeader() == &u) u.GetFormation()->LeaderMoveTo(node->x, node->y, node->z); } else node = NULL; }
bool WaypointMovementGenerator<Creature>::Update(Creature &unit, const uint32 &diff) { if (!&unit) return true; if (!path_id) return false; // Waypoint movement can be switched on/off // This is quite handy for escort quests and other stuff if (unit.HasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED)) return true; // Clear the generator if the path doesn't exist if (!waypoints || !waypoints->size()) return false; Traveller<Creature> traveller(unit); i_nextMoveTime.Update(diff); i_destinationHolder.UpdateTraveller(traveller, diff, true); if (i_nextMoveTime.GetExpiry() < TIMEDIFF_NEXT_WP) { if (unit.IsStopped()) { if (StopedByPlayer) { ASSERT(node); InitTraveller(unit, *node); i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); StopedByPlayer = false; return true; } if (i_currentNode == waypoints->size() - 1) // If that's our last waypoint { if (repeating) // If the movement is repeating i_currentNode = 0; // Start moving all over again else { unit.SetHomePosition(node->x, node->y, node->z, unit.GetOrientation()); unit.GetMotionMaster()->Initialize(); return false; // Clear the waypoint movement } } else ++i_currentNode; node = waypoints->at(i_currentNode); InitTraveller(unit, *node); i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); //Call for creature group update if (unit.GetFormation() && unit.GetFormation()->getLeader() == &unit) unit.GetFormation()->LeaderMoveTo(node->x, node->y, node->z); } else { //Determine waittime if (node->delay) i_nextMoveTime.Reset(node->delay); //note: disable "start" for mtmap if (node->event_id && urand(0,99) < node->event_chance) unit.GetMap()->ScriptsStart(sWaypointScripts, node->event_id, &unit, NULL/*, false*/); i_destinationHolder.ResetTravelTime(); MovementInform(unit); unit.UpdateWaypointID(i_currentNode); unit.ClearUnitState(UNIT_STAT_ROAMING); unit.Relocate(node->x, node->y, node->z); } } else { if (unit.IsStopped() && !i_destinationHolder.HasArrived()) { if (!StopedByPlayer) { i_destinationHolder.IncreaseTravelTime(STOP_TIME_FOR_PLAYER); i_nextMoveTime.Reset(STOP_TIME_FOR_PLAYER); StopedByPlayer = true; } } } return true; }