예제 #1
0
        public void ExpectedHitsTest()
        {
            // Setup
            Monster actor = new Monster
            {
                Hits     = 1,
                Accuracy = 99
            };

            Monster target = new Monster();

            // Test expected hit messages and miss threshold
            int missThreshold = 20; // 2% (1% expected)

            for (int i = 0; i < 1000; i++)
            {
                AttackResult res = AttackManager.AttackMonster(actor, target);
                if (String.Equals(res.DamageMessage, "Miss"))
                {
                    missThreshold--;
                }
                else
                {
                    Assert.IsTrue(String.Equals(res.HitsMessage, "1xHit"));
                }
            }

            // Ensure some misses happened, but not too many
            Assert.AreNotEqual(20, missThreshold);
            Assert.IsTrue(missThreshold > 0);
        }
예제 #2
0
        public void AttackMonsterInputsTest()
        {
            // Setup
            Monster actor  = new Monster();
            Monster target = new Monster();

            // Test valid input
            Assert.IsNotNull(AttackManager.AttackMonster(actor, target));

            // Test invalid inputs
            Assert.ThrowsException <ArgumentNullException>(() => AttackManager.AttackMonster(null, target));
            Assert.ThrowsException <ArgumentNullException>(() => AttackManager.AttackMonster(actor, null));
            Assert.ThrowsException <ArgumentNullException>(() => AttackManager.AttackMonster(null, null));
        }
예제 #3
0
 private void testDamageRange(Monster actor, Monster target, int min, int max)
 {
     for (int i = 0; i < 100; i++)
     {
         AttackResult atkRes = AttackManager.AttackMonster(actor, target);
         // Ignore misses
         if (!String.Equals(atkRes.DamageMessage, "Miss"))
         {
             // Extract the damage value from the damage message ("xxx DMG");
             int dmg = int.Parse(atkRes.DamageMessage.Split()[0]);
             Assert.IsTrue(dmg >= min);
             Assert.IsTrue(dmg <= max);
         }
     }
 }
예제 #4
0
        public void DrainHPTouchTest()
        {
            // Setup
            Monster actor = new Monster
            {
                HPMax    = 1000,
                HP       = 1,
                Hits     = 10,
                Accuracy = 99,
                Strength = 10
            };

            actor.AttackEffects.Add("Drain HP");

            Monster target = new Monster
            {
                HPMax = 1600,
                HP    = 1600
            };

            // Test normal logic
            AttackManager.AttackMonster(actor, target);
            Assert.IsTrue(actor.HP > 1);
            Assert.IsTrue(target.HP < target.HPMax);

            // Ensure an undead target reverses the drain
            actor.HP  = actor.HPMax;
            target.HP = 1;
            target.Families.Add(MonsterFamily.Undead);

            AttackManager.AttackMonster(actor, target);
            Assert.IsTrue(actor.HP < actor.HPMax);
            Assert.IsTrue(target.HP > 1);
            target.Families.Clear();

            // Ensure that the drain effect alone deals 1/16th max HP damage per hit
            target.HP = target.HPMax;
            AttackResult atkRes = AttackManager.AttackMonster(actor, target);
            int          hits   = int.Parse(atkRes.HitsMessage.Split('x')[0]);

            Assert.AreNotEqual(1600 - (hits * 100), target.HP);

            actor.Strength = 0;
            target.HP      = target.HPMax;
            atkRes         = AttackManager.AttackMonster(actor, target);
            hits           = int.Parse(atkRes.HitsMessage.Split('x')[0]);
            Assert.AreEqual(1600 - (hits * 100), target.HP);
        }
예제 #5
0
        public void ExpectedDamageAndCritsTest()
        {
            // Setup
            Monster actor = new Monster
            {
                Hits     = 1,
                Accuracy = 99,
                Strength = 10
            };

            Monster target = new Monster();

            // Test expected damage, crit expectancy
            int critThreshold = 75; // 7.5% (5% expected)

            for (int i = 0; i < 1000; i++)
            {
                AttackResult atkRes = AttackManager.AttackMonster(actor, target);
                // Ignore misses
                if (!String.Equals(atkRes.DamageMessage, "Miss"))
                {
                    // Damage range is (str...str*2+str);
                    // Extract the damage value from the damage message ("xxx DMG");
                    int dmg = int.Parse(atkRes.DamageMessage.Split()[0]);
                    Assert.IsTrue(dmg >= actor.Strength);
                    Assert.IsTrue(dmg <= actor.Strength * 3);
                    if (atkRes.Results.Contains("Critical Hit!"))
                    {
                        critThreshold--;
                    }
                }
            }
            // Ensure some crits happened, but not too many
            Assert.AreNotEqual(75, critThreshold);
            Assert.IsTrue(critThreshold > 0);
        }