private void SetRoute()
    {
        if (_goingToPosition != null && _movingToDirection == Direction.NONE)
        {
            _movingToDirection = MapHelpers.GetDirection(MapPosition, _goingToPosition);
            var timeToMove = (float)Formulas.GetTimeToMoveBetweenTwoTiles(MoveSpeed);

            SetDestination(new Vector3(_goingToPosition.X * 16, _goingToPosition.Y * 16, 0), timeToMove / 1000);

            SpriteSheets.ForEach(e => e.Direction = _movingToDirection);
            SpriteSheets.ForEach(e => e.Moving    = true);

            UnityClient.Map.EntityPositions.RemoveEntity(EntityWrapper, MapPosition);

            MapPosition.X = _goingToPosition.X;
            MapPosition.Y = _goingToPosition.Y;

            UnityClient.Map.EntityPositions.RemoveEntity(EntityWrapper, MapPosition);

            _goingToPosition = null;
        }
    }
Example #2
0
    private void PerformNextStep()
    {
        var player = UnityClient.Player;

        if (_nextStep != null && _movingToDirection == Direction.NONE)
        {
            _movingToDirection = MapHelpers.GetDirection(player.Position, _nextStep);
            var moveTimeInMs = Formulas.GetTimeToMoveBetweenTwoTiles(player.Speed);

            var moveTimeInSeconds = (float)moveTimeInMs / 1000;

            var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            _shouldArriveAt = now + moveTimeInMs;

            UnityClient.TcpClient.Send(new EntityMovePacket()
            {
                UID  = UnityClient.Player.UID,
                From = UnityClient.Player.Position,
                To   = _nextStep
            });

            StartMovement(new Vector3(_nextStep.X * 16, _nextStep.Y * 16, 0), moveTimeInSeconds);
            Debug.Log("Moving Player To " + _nextStep.X + " - " + _nextStep.Y);

            SpriteSheets.ForEach(e => e.Direction = _movingToDirection);
            SpriteSheets.ForEach(e => e.Moving    = true);

            UnityClient.Map.EntityPositions.RemoveEntity(UnityClient.Player, UnityClient.Player.Position);

            UnityClient.Player.Position.X = _nextStep.X;
            UnityClient.Player.Position.Y = _nextStep.Y;

            UnityClient.Map.EntityPositions.AddEntity(UnityClient.Player, UnityClient.Player.Position);

            _nextStep = null;
        }
    }