Example #1
0
        public async Task MoveTo(int x, int y, int z)
        {
            if (!CanMove())
            {
                _character.SendActionFailedAsync();
                return;
            }

            if (_character.IsAttacking())
            {
                _character.AbortAttack();
            }

            if (IsMoving)
            {
                UpdatePosition();
                await NotifyStopMove(false);
            }

            float dx = x - X;
            float dy = y - Y;
            float dz = z - Z;


            if (dx * dx + dy * dy > 9900 * 9900)
            {
                _character.SendActionFailedAsync();
                return;
            }

            DestinationX = x;
            DestinationY = y;
            DestinationZ = z;

            Vector2 targetVector = new Vector2(dx, dy);

            targetVector /= targetVector.Length();

            Heading = (int)(Math.Atan2(-targetVector.X, -targetVector.Y) * 10430.378 + short.MaxValue);

            _movementUpdateTime = _movementLastTime = DateTime.UtcNow.Ticks;
            _attackTarget       = null;
            IsMoving            = true;

            await _character.BroadcastPacketAsync(new CharMoveToLocation(_character));
        }