private async Task <bool> walkStraightLine(ILocation destination, CancellationTokenSource token, List <IObject> debugRenderers) { if (debugRenderers != null) { GLLineRenderer line = new GLLineRenderer(_glUtils, _translate.X, _translate.Y, destination.X, destination.Y); IObject renderer = _objFactory.GetObject("Debug Line"); renderer.CustomRenderer = line; await renderer.ChangeRoomAsync(_room.Room); debugRenderers.Add(renderer); } if (_cutscene.IsSkipping) { _translate.X = destination.X; _translate.Y = destination.Y; return(true); } if (!isDistanceVeryShort(destination)) { var lastDirection = _faceDirection.Direction; var walkAnimation = _outfit.Outfit[AGSOutfit.Walk]; bool alreadyWalking = _faceDirection.CurrentDirectionalAnimation == walkAnimation; _faceDirection.CurrentDirectionalAnimation = walkAnimation; await _faceDirection.FaceDirectionAsync(_translate.X, _translate.Y, destination.X, destination.Y); if (lastDirection != _faceDirection.Direction && alreadyWalking) { await Task.Delay(200); } } float xSteps = Math.Abs(destination.X - _translate.X); float ySteps = Math.Abs(destination.Y - _translate.Y); float numSteps = Math.Max(xSteps, ySteps); bool isBaseStepX = xSteps >= ySteps; float xStep = xSteps / numSteps; if (_translate.X > destination.X) { xStep = -xStep; } float yStep = ySteps / numSteps; if (_translate.Y > destination.Y) { yStep = -yStep; } WalkLineInstruction instruction = new WalkLineInstruction(token, numSteps, xStep, yStep, isBaseStepX, destination); _currentWalkLine = instruction; Task timeout = Task.Delay(WalkLineTimeoutInMilliseconds); Task completedTask = await Task.WhenAny(instruction.OnCompletion.Task, timeout); if (completedTask == timeout) { instruction.CancelToken.Cancel(); return(false); } if (instruction.CancelToken.IsCancellationRequested || !isWalkable(_translate.Location)) { return(false); } _translate.X = destination.X; _translate.Y = destination.Y; return(true); }
private async Task<bool> walkStraightLine(ILocation destination, CancellationTokenSource token, List<IObject> debugRenderers) { if (debugRenderers != null) { GLLineRenderer line = new GLLineRenderer (_glUtils, _obj.X, _obj.Y, destination.X, destination.Y); IObject renderer = _objFactory.GetObject("Debug Line"); renderer.CustomRenderer = line; renderer.ChangeRoom(_obj.Room); debugRenderers.Add (renderer); } if (_cutscene.IsSkipping) { _obj.X = destination.X; _obj.Y = destination.Y; return true; } if (!isDistanceVeryShort(destination)) { var lastDirection = _faceDirection.Direction; var walkAnimation = _outfit.Outfit[AGSOutfit.Walk]; bool alreadyWalking = _faceDirection.CurrentDirectionalAnimation == walkAnimation; _faceDirection.CurrentDirectionalAnimation = walkAnimation; await _faceDirection.FaceDirectionAsync(_obj.X, _obj.Y, destination.X, destination.Y); if (lastDirection != _faceDirection.Direction && alreadyWalking) { await Task.Delay(200); } } float xSteps = Math.Abs (destination.X - _obj.X); float ySteps = Math.Abs (destination.Y - _obj.Y); float numSteps = Math.Max (xSteps, ySteps); bool isBaseStepX = xSteps >= ySteps; float xStep = xSteps / numSteps; if (_obj.X > destination.X) xStep = -xStep; float yStep = ySteps / numSteps; if (_obj.Y > destination.Y) yStep = -yStep; WalkLineInstruction instruction = new WalkLineInstruction(token, numSteps, xStep, yStep, isBaseStepX, destination); _currentWalkLine = instruction; Task timeout = Task.Delay(WalkLineTimeoutInMilliseconds); Task completedTask = await Task.WhenAny(instruction.OnCompletion.Task, timeout); if (completedTask == timeout) { instruction.CancelToken.Cancel(); return false; } if (instruction.CancelToken.IsCancellationRequested) return false; _obj.X = destination.X; _obj.Y = destination.Y; return true; }