public GameWorldDebug(GameWorldController gameWorldController) { _gameWorldController = gameWorldController; _pathComputer = new PathComputer(); DebugRegistry.SetToggle("entity.pathfinding.render_debug_path", false); DebugRegistry.SetToggle("entity.pathfinding.render_nav_mesh", false); DebugRegistry.SetToggle("entity.pathfinding.render_visibility", false); DebugRegistry.SetToggle("ui.outline_hover_widget", false); DebugRegistry.SetToggle("ui.show_cursor_position", false); }
public static bool AddPathRequest( RoomKey roomKey, Point3d startPoint, Point3d endPoint, PathComputer.OnPathComputerComplete onComplete) { bool success = false; if (m_instance != null) { PathComputer pathComputer = new PathComputer(); AsyncRPGSharedLib.Navigation.NavMesh navMesh = GetNavMesh(roomKey); if (pathComputer.NonBlockingPathRequest(navMesh, roomKey, startPoint, endPoint, onComplete)) { m_instance.m_requestQueue.Add(pathComputer); success = true; } } return success; }
private void OnPathComputed(PathComputer pathResult) { // If the path find succeeded, the entity will set the new destination and start walking toward it if (pathResult.ResultCode == PathComputer.eResult.success) { // Tell the server where we would like to go AsyncJSONRequest serverRequest = AsyncJSONRequest.Create(m_requestOwnerObject); Dictionary<string, object> requestPayload = new Dictionary<string, object>(); requestPayload["character_id"] = m_entity.MyCharacterData.character_id; requestPayload["x"] = OriginPortalEntryPoint.x; requestPayload["y"] = OriginPortalEntryPoint.y; requestPayload["z"] = OriginPortalEntryPoint.z; requestPayload["angle"] = pathResult.DestinationFacingAngle; requestPayload["portal_id"] = OriginPortal.portal_id; Status = eRequestStatus.pending_server_response; serverRequest.POST( ServerConstants.characterPortalRequestURL, requestPayload, this.OnServerRequestComplete); } else { Status = eRequestStatus.completed; ResultCode = eResult.failed_path; ResultDetails = "Path Failure Code: " + pathResult.ResultCode.ToString(); // Notify the caller that the request is completed m_onCompleteCallback(this); } }
private bool ComputePlayerPaths( out string result_code) { PathComputer pathComputer = new PathComputer(); bool success = true; result_code = SuccessMessages.GENERAL_SUCCESS; foreach (GameEventParameters gameEvent in m_relevantGameEvents) { if (gameEvent.GetEventType() == eGameEventType.character_moved) { GameEvent_CharacterMoved movedEvent = (GameEvent_CharacterMoved)gameEvent; success = pathComputer.BlockingPathRequest( m_room.runtime_nav_mesh, m_room.room_key, new Point3d((float)movedEvent.from_x, (float)movedEvent.from_y, (float)movedEvent.from_z), new Point3d((float)movedEvent.to_x, (float)movedEvent.to_y, (float)movedEvent.to_z)); if (success) { m_playerPaths.Add( new EntityPath() { entity_id = movedEvent.character_id, path = pathComputer.FinalPath }); } else { result_code = ErrorMessages.CANT_COMPUTE_PATH; break; } } } return success; }
public void RequestMoveTo( Point3d point, float angle, PathComputer.OnPathComputedCallback onPathComputed) { // Set our new destination. // The position will update as we move along our path m_pathfindingComponent.SubmitPathRequest( point, MathConstants.GetUnitVectorForAngle(angle), (PathComputer pathResult) => { if (pathResult == null) { // No result means we stopped in out tracks m_mobData.x = Position.x; m_mobData.y = Position.y; m_mobData.z = Position.z; m_mobData.angle = angle; onPathComputed(PathComputer.eResult.success); } else { if (pathResult.ResultCode == PathComputer.eResult.success) { // Set the character data immediately to the destination m_mobData.x = point.x; m_mobData.y = point.y; m_mobData.z = point.z; m_mobData.angle = angle; } onPathComputed(pathResult.ResultCode); } }); }
public void RequestMoveTo(Point3d point, float angle, PathComputer.OnPathComputedCallback onPathComputed) { SnapTo(point, angle); onPathComputed(PathComputer.eResult.success); }
// Events private void OnPathCompleted(PathComputer pathResult) { m_state = ePathFindingState.completed; if (m_pathCompleteCallback != null) { m_pathCompleteCallback(pathResult); m_pathCompleteCallback = null; } }
// Requests public bool SubmitPathRequest( Point3d point, Vector2d facing, PathComputer.OnPathComputerComplete pathCompletedCallback) { bool success = false; m_pathSteps = new List<PathStep>(); m_pathStepIndex = 0; m_pathCompleteCallback = pathCompletedCallback; m_destinationPoint.Set(point); m_destinationFacing.Copy(facing); if (Point3d.DistanceSquared(m_destinationPoint, m_entity.Position) > MathConstants.EPSILON_SQUARED) { success = PathfindingSystem.AddPathRequest( m_entity.CurrentRoomKey, m_entity.Position, m_destinationPoint, (PathComputer pathResult) => { if (pathResult.ResultCode == PathComputer.eResult.success) { m_state = ePathFindingState.in_progress; m_pathSteps = pathResult.FinalPath; } else { OnPathCompleted(pathResult); } }); } else { OnPathCompleted(null); success = true; } return success; }