Esempio n. 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));
        }
Esempio n. 2
0
        private async Task PerformAutoAttack()
        {
            // TODO: revalidate that on every attack
            int  attackSpeed = (int)(470000 / _character.CharacterStat.PAttackSpeed); // TODO: calculate real attack speed
            bool dual        = true;                                                  // is dual weapon, harcode for now

            while (IsAttacking && CanAttack())
            {
                Attack attackPacket = new Attack(_character, GenerateSimpleHit(dual));

                if (dual)
                {
                    attackPacket.Hits.Add(GenerateSimpleHit(dual));
                }

                await _character.BroadcastPacketAsync(attackPacket);

                StartAutoAttack();
                _target.CharAttack.StartAutoAttack();

                await Task.Delay(dual?attackSpeed / 2 : attackSpeed - 5);

                if (!IsAttacking || !CanAttack())
                {
                    break;
                }

                PerformHit(attackPacket.Hits[0]);

                if (dual)
                {
                    await Task.Delay(attackSpeed / 2 - 5);

                    if (!IsAttacking || !CanAttack())
                    {
                        break;
                    }

                    PerformHit(attackPacket.Hits[1]);
                }
            }

            IsAttacking = false;
            _target     = null;
        }