示例#1
0
        // checks
        public static bool CheckAttackLanded(this Creature attacker, Item weapon, Creature defender)
        {
            double attackersHitRate =
                (attacker.GetWeaponSkill(attacker.Body.MainHand) + (attacker.Stats.Attributes[Attribute.Dexterity] / 2.5) + (dice.Next(0, attacker.Stats.Attributes[Attribute.Luck]) / 10))
                * (0.75 + 0.5 * attacker.Stats.Resources[Resource.SP] / attacker.Stats.Resources[Resource.MaxSP]);

            double defendersEvasion =
                ((defender.Stats.Attributes[Attribute.Agility] / 5) + (dice.Next(0, defender.Stats.Attributes[Attribute.Luck]) / 10))
                * (0.75 + 0.5 * defender.Stats.Resources[Resource.SP] / defender.Stats.Resources[Resource.MaxSP]);

            double maxMissChance = 150;
            double chanceToMiss  = maxMissChance - attackersHitRate;
            double chanceToDodge = attackersHitRate - (attackersHitRate - defendersEvasion);

            int diceRoll = Program.RNG.Next(0, (int)maxMissChance);

            if (diceRoll <= chanceToMiss)
            {
                Program.MsgConsole.WriteLine($"{attacker.Name}'s attack missed.");
                attacker.LvlWeaponSkill(weapon, 10);
                return(false);
            }

            diceRoll = dice.Next(0, (int)attackersHitRate + 2);
            if (diceRoll <= chanceToDodge)
            {
                Program.MsgConsole.WriteLine($"{defender.Name} evaded {attacker.Name}'s attack.");
                attacker.LvlWeaponSkill(weapon, 20);
                return(false);
            }

            attacker.LvlWeaponSkill(weapon, 40);

            return(true);
        }