Exemple #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));
        }
        public async void DoAttack(L2Character target) // TODO: Add skill
        {
            if (!CanAttack(target) || target == _target)
            {
                _character.SendActionFailedAsync();
                return;
            }

            if (IsAttacking)
            {
                await CancelAttack();
            }

            IsAttacking = true;

            _target = target;

            _autoAttackTask = Task.Factory.StartNew(PerformAutoAttack); // for bow and melee weapon
        }