Пример #1
0
        public static void Process(Mover attacker, Mover defender)
        {
            AttackFlags flags = GetAttackFlags(attacker, defender);
            int damages = CalculateMeleeDamages(attacker, defender);

            if (flags.HasFlag(AttackFlags.AF_BLOCKING))
            {
                float blockFactor = GetBlockFactor(attacker, defender);

                if (blockFactor < 1f)
                    damages = (int)(damages * blockFactor);

                Log.Debug("=> {0} blocking {1}", defender.Name, attacker.Name);
            }
            if (flags.HasFlag(AttackFlags.AF_CRITICAL))
            {
                damages *= 2; // TODO: GetCriticalHitFactor

                Log.Debug("=> {0} inflicts a critical hit to {1}", attacker.Name, defender.Name);
            }
            
            damages -= GetDefense(attacker, defender, flags);

            if (flags == AttackFlags.AF_MISS)
            {
                Log.Debug("{0} misses {1}", attacker.Name, defender.Name);
                damages = 0;
            }

            if (damages < 0)
                damages = 0;

            Log.Debug("{0} inflicted {1} damages to {2}", attacker.Name, damages, defender.Name);

            // Send damages
            if (flags.HasFlag(AttackFlags.AF_FLYING)) // KnockBack
                SendDamagesFly(attacker, defender, damages, flags);
            else
                attacker.SendDamagesTo(defender, damages, flags);

            defender.Attributes[DefineAttributes.HP] -= damages;

            if (defender.Attributes[DefineAttributes.HP] <= 0)
                defender.Die();

            if (defender.IsDead)
            {
                if (defender is Monster && attacker is Player)
                {
                    var monster = defender as Monster;
                    var player = attacker as Player;
                    int experience = player.CalculateExperience(monster.Data.ExpValue);

                    // TODO: give experience for party
                    if (player.GiveExperience(experience))
                    {
                        player.SendSetLevel();
                        player.SendStatPoints();
                    }

                    player.SendExperience();
                }

                if (defender is Player && attacker is Monster)
                {
                }
            }
        }