Exemplo n.º 1
0
        /// <summary>
        /// Handling a base ranged attack.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="packet">The packet.</param>
        public static void Handle(Controllers.Entities.AttackableEntityController attacker, Models.Packets.Entities.InteractionPacket packet)
        {
            Controllers.Entities.AttackableEntityController target;
            var canAttack = attacker.ValidateAttack(packet, out target);

            if (canAttack == 0 && target != null)
            {
                var player = attacker as Player;

                if (player != null)
                {
                    if (!ProcessPlayer(player, packet, 1))
                    {
                        return;
                    }
                }

                uint damage = Calculations.RangedCalculations.GetDamage(attacker as IAttackableEntity, target as IAttackableEntity);
                Damage.Process(attacker, target, ref damage, true);

                if (damage > 0 && player != null)
                {
                    var targetMonster = target as Monster;

                    if (targetMonster != null)
                    {
                        uint newExperience = Calculations.Experience.GetProficiencyExperience(player, targetMonster, damage);

                        if (packet.WeaponTypeRight > 0)
                        {
                            var prof = player.Spells.GetOrCreateProficiency(packet.WeaponTypeRight);
                            if (prof != null)
                            {
                                prof.Raise(newExperience);
                            }
                        }
                    }

                    DecreaseArrows(player, 1);
                }

                packet.Data = damage;
                attacker.UpdateScreen(false, packet);
                if (player != null)
                {
                    player.ClientSocket.Send(packet);

                    packet.ActivationType  = 0;
                    packet.ActivationValue = 0;
                    player.AttackPacket    = packet;
                    player.UseAutoAttack(packet);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles a base physical attack.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="packet">The packet.</param>
        public static void Handle(Controllers.Entities.AttackableEntityController attacker, Models.Packets.Entities.InteractionPacket packet)
        {
            Controllers.Entities.AttackableEntityController target;
            var canAttack = attacker.ValidateAttack(packet, out target);

            if (canAttack == 0 && target != null)
            {
                var player = attacker as Player;

                if (player != null)
                {
                    if (!ProcessPlayer(player, packet))
                    {
                        return;
                    }
                }

                if ((attacker.AttackableEntity.Level + 15) < target.AttackableEntity.Level)
                {
                    if (!attacker.ContainsStatusFlag(Enums.StatusFlag.StarOfAccuracy) &&
                        Tools.CalculationTools.ChanceSuccess(10))
                    {
                        return;
                    }
                    else if (Tools.CalculationTools.ChanceSuccess(5))
                    {
                        return;
                    }
                }

                uint damage = Calculations.PhysicalCalculations.GetDamage(attacker.AttackableEntity, target.AttackableEntity);
                Damage.Process(attacker, target, ref damage, true);

                var targetMonster = target as Monster;

                if (damage > 0 && player != null && targetMonster != null)
                {
                    uint newExperience = Calculations.Experience.GetProficiencyExperience(player, targetMonster, damage);

                    if (packet.WeaponTypeRight > 0)
                    {
                        var prof = player.Spells.GetOrCreateProficiency(packet.WeaponTypeRight);
                        if (prof != null)
                        {
                            prof.Raise(newExperience);
                        }
                    }

                    if (packet.WeaponTypeLeft > 0)
                    {
                        var prof = player.Spells.GetOrCreateProficiency(packet.WeaponTypeLeft);
                        if (prof != null)
                        {
                            prof.Raise(newExperience);
                        }
                    }
                }

                packet.Data = damage;
                attacker.UpdateScreen(false, packet);
                if (player != null)
                {
                    player.ClientSocket.Send(packet);
                }
            }
        }