Exemple #1
0
        public AttackResult ComputeAttack(WorldEntity from, WorldEntity to)
        {
            if (null == to)
            {
                return AttackResult.Miss;
            }

            int dodgeMod = to.Stats.Get(EntityStatsContainer.AT_DODGE);
            int hitMod = from.Stats.Get(EntityStatsContainer.AT_HIT);

            bool crit = false;
            Random rndm = new Random();
            int rollToHit = rndm.Next(20) + 1;
            if (rollToHit == 20)
            {
                crit = true;
            }

            rollToHit += hitMod;
            if (rollToHit > 10 + dodgeMod)
            {
                int atk = from.Stats.Get(EntityStatsContainer.AT_ATK);
                int atk_rng = (int)Math.Max(atk * 0.1f, 1); //Minimum 1 damage

                if (crit)
                {
                    atk += atk_rng;
                }
                else
                {
                    atk += rndm.Next(2 * atk_rng) - atk_rng;
                }
                to.TakeDamage(atk, crit);

                return (crit ? AttackResult.Critical : AttackResult.Hit);
            }

            return AttackResult.Miss;
        }