コード例 #1
0
        public void DoubleShotAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Archer)
            {
                MaxComboPoints = 100,
                ComboPoints    = 100,
                MaxHitPoints   = 100,
                HitPoints      = 10
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, InCombat = true
            };

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = player.Abilities.FindIndex(
                f => f.ArcAbilityCategory == ArcherAbility.Double);

            string[] inputInfo = new[] { "ability", "double" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Double Shot", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Combo Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 25", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual(
                "Two arrows are fired which each cause instant damage. Cost and damage are per arrow.",
                OutputHelper.Display.Output[4][2]);
            string[] input       = new[] { "use", "double" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("double", abilityName);
            int arrowCount = player.PlayerQuiver.Quantity;

            player.UseAbility(monster, input);
            Assert.AreEqual(arrowCount - 2, player.PlayerQuiver.Quantity);
            int?comboCost = player.Abilities[abilityIndex].ComboCost;
            int hitAmount = player.Abilities[abilityIndex].Offensive.Amount;

            Assert.AreEqual(monster.MaxHitPoints - (2 * hitAmount), monster.HitPoints);
            Assert.AreEqual(player.MaxComboPoints - (2 * comboCost), player.ComboPoints);
            string attackString = $"Your double shot hit the {monster.Name} for 25 physical damage.";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[5][2]);
            Assert.AreEqual(attackString, OutputHelper.Display.Output[6][2]);
            player.MaxComboPoints = 25;
            player.ComboPoints    = player.MaxComboPoints;
            monster.MaxHitPoints  = 100;
            monster.HitPoints     = monster.MaxHitPoints;
            arrowCount            = player.PlayerQuiver.Quantity;
            player.UseAbility(monster, input);
            Assert.AreEqual(arrowCount - 1, player.PlayerQuiver.Quantity);
            Assert.AreEqual(player.MaxComboPoints - comboCost, player.ComboPoints);
            Assert.AreEqual(attackString, OutputHelper.Display.Output[7][2]);
            const string outOfComboString = "You didn't have enough combo points for the second shot!";

            Assert.AreEqual(outOfComboString, OutputHelper.Display.Output[8][2]);
        }
コード例 #2
0
        public void PoisonBiteAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Spider)
            {
                HitPoints = 50, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = monster.Abilities.FindIndex(
                f => f.AbilityCategory == Ability.PoisonBite);

            foreach (IItem item in player.Inventory.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            monster.Abilities[abilityIndex].UseOffenseDamageAbility(monster, player, abilityIndex);
            int abilityCost = monster.Abilities[abilityIndex].EnergyCost;

            Assert.AreEqual(monster.MaxEnergyPoints - abilityCost, monster.EnergyPoints);
            int    abilityDamage         = monster.Abilities[abilityIndex].Offensive.Amount;
            int    abilityDamageOverTime = monster.Abilities[abilityIndex].Offensive.AmountOverTime;
            int    abilityCurRounds      = monster.Abilities[abilityIndex].Offensive.AmountCurRounds;
            int    abilityMaxRounds      = monster.Abilities[abilityIndex].Offensive.AmountMaxRounds;
            string attackString          = $"The {monster.Name} tries to bite you!";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string attackSuccessString = $"The {monster.Name} bites you for {abilityDamage} physical damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]);
            string bleedString = $"You are bleeding from {monster.Name}'s attack!";

            Assert.AreEqual(bleedString, OutputHelper.Display.Output[2][2]);
            Assert.AreEqual(true, player.Effects[0] is BleedingEffect);
            Assert.AreEqual(player.MaxHitPoints - abilityDamage, player.HitPoints);
            Assert.AreEqual(abilityCurRounds, player.Effects[0].CurrentRound);
            Assert.AreEqual(abilityMaxRounds, player.Effects[0].MaxRound);
            OutputHelper.Display.ClearUserOutput();
            BleedingEffect bleedEffect = player.Effects[0] as BleedingEffect;

            for (int i = 2; i < 5; i++)
            {
                bleedEffect.ProcessRound();
                int    bleedAmount      = bleedEffect.BleedDamageOverTime;
                string bleedRoundString = $"You bleed for {bleedAmount} physical damage.";
                Assert.AreEqual(bleedRoundString, OutputHelper.Display.Output[i - 2][2]);
                Assert.AreEqual(i, player.Effects[0].CurrentRound);
                GameHelper.RemovedExpiredEffectsAsync(player);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, player.Effects.Any());
            Assert.AreEqual(player.MaxHitPoints - abilityDamage - (abilityDamageOverTime * abilityMaxRounds),
                            player.HitPoints);
        }
コード例 #3
0
        public void WarCryAbilityUnitTest()
        {
            OutputHelper.Display.ClearUserOutput();
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100,
                RagePoints    = 100,
                InCombat      = true
            };

            player.Abilities.Add(new PlayerAbility(
                                     "war cry", 50, 1, WarriorAbility.WarCry, 4));
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.WarCry);

            string[] inputInfo = new[] { "ability", "war", "cry" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("War Cry", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 50", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("War Cry Amount: 25", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("Opponent's attacks are decreased by 25 for 3 rounds.",
                            OutputHelper.Display.Output[4][2]);
            string[] input       = new[] { "use", "war", "cry" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("war cry", abilityName);
            player.UseAbility(input);
            int?rageCost = player.Abilities[abilityIndex].RageCost;

            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            Assert.AreEqual("You shout a War Cry, intimidating your opponent, and decreasing incoming damage.",
                            OutputHelper.Display.Output[5][2]);
            OutputHelper.Display.ClearUserOutput();
            Assert.AreEqual(true, player.Effects[0] is ChangeMonsterDamageEffect);
            ChangeMonsterDamageEffect changeMonsterDmgEffect = player.Effects[0] as ChangeMonsterDamageEffect;

            for (int i = 2; i < 5; i++)
            {
                int baseAttackDamageM  = monster.UnarmedAttackDamage;
                int attackDamageM      = baseAttackDamageM;
                int changeDamageAmount = changeMonsterDmgEffect.ChangeAmount < attackDamageM ?
                                         changeMonsterDmgEffect.ChangeAmount : attackDamageM;
                attackDamageM -= changeDamageAmount;
                Assert.AreEqual(baseAttackDamageM - changeDamageAmount, attackDamageM);
                changeMonsterDmgEffect.ProcessChangeMonsterDamageRound(player);
                string changeDmgString = $"Incoming damage is decreased by {-1 * changeMonsterDmgEffect.ChangeAmount}.";
                Assert.AreEqual(i, player.Effects[0].CurrentRound);
                Assert.AreEqual(changeDmgString, OutputHelper.Display.Output[i - 2][2]);
            }
            GameHelper.RemovedExpiredEffectsAsync(player);
            Thread.Sleep(1000);
            Assert.AreEqual(false, player.Effects.Any());
        }
コード例 #4
0
        public void TailWhipAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 200, MaxHitPoints = 200
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Dragon);

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = monster.Abilities.FindIndex(
                f => f.AbilityCategory == Ability.TailWhip);

            foreach (IItem item in player.Inventory.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            monster.Abilities[abilityIndex].UseOffenseDamageAbility(monster, player, abilityIndex);
            int abilityCost = monster.Abilities[abilityIndex].EnergyCost;

            Assert.AreEqual(monster.MaxEnergyPoints - abilityCost, monster.EnergyPoints);
            int attackDamage = monster.Abilities[abilityIndex].Offensive.Amount;

            Assert.AreEqual(player.MaxHitPoints - attackDamage, player.HitPoints);
            string attackString = $"The {monster.Name} swings its tail at you!";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string attackSuccessString = $"The {monster.Name} strikes you with its tail for {attackDamage} physical damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]);
        }
コード例 #5
0
        public void PlayerResistanceUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                MaxManaPoints = 100, ManaPoints = 100
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Elemental);

            while (monster.ElementalCategory != ElementalType.Air)
            {
                monster = new Monster(3, MonsterType.Elemental);
            }
            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            Assert.AreEqual(player.Level * 5, player.FireResistance);
            Assert.AreEqual(player.Level * 5, player.FrostResistance);
            Assert.AreEqual(player.Level * 5, player.ArcaneResistance);
            int    arcaneResistance = player.ArcaneResistance;
            double resistanceMod    = (100 - arcaneResistance) / 100.0;
            int    spellIndex       = monster.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Lightning);

            monster.Spellbook[spellIndex].CastArcaneOffense(monster, player, spellIndex);
            int reducedDamage = (int)(monster.Spellbook[spellIndex].Offensive.Amount * resistanceMod);

            Assert.AreEqual(player.HitPoints, player.MaxHitPoints - reducedDamage);
        }
コード例 #6
0
        public void FireballSpellUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                MaxManaPoints = 100, ManaPoints = 100, InCombat = true
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 50, MaxHitPoints = 100, FireResistance = 0
            };

            MonsterBuilder.BuildMonster(monster);
            player.PlayerWeapon.CritMultiplier = 1;             // Remove crit chance to remove "noise" in test
            string[] inputInfo  = new[] { "spell", "fireball" };
            int      spellIndex = player.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Fireball);

            PlayerHelper.SpellInfo(player, inputInfo);
            Assert.AreEqual("Fireball", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Mana Cost: 35", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 25", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("Damage Over Time: 5", OutputHelper.Display.Output[4][2]);
            Assert.AreEqual("Fire damage over time will burn for 3 rounds.",
                            OutputHelper.Display.Output[5][2]);
            OutputHelper.Display.ClearUserOutput();
            string[] input     = new[] { "cast", "fireball" };
            string   spellName = InputHelper.ParseInput(input);

            Assert.AreEqual("fireball", spellName);
            player.CastSpell(monster, spellName);
            Assert.AreEqual(player.MaxManaPoints - player.Spellbook[spellIndex].ManaCost, player.ManaPoints);
            Assert.AreEqual(25, monster.HitPoints);
            Assert.AreEqual(3, monster.Effects[0].MaxRound);
            Assert.AreEqual($"You hit the {monster.Name} for {player.Spellbook[spellIndex].Offensive.Amount} fire damage.",
                            OutputHelper.Display.Output[0][2]);
            Assert.AreEqual($"The {monster.Name} bursts into flame!",
                            OutputHelper.Display.Output[1][2]);
            BurningEffect burnEffect = monster.Effects[0] as BurningEffect;

            for (int i = 2; i < 5; i++)
            {
                burnEffect.ProcessRound();
                Assert.AreEqual(
                    $"The {monster.Name} burns for {burnEffect.FireDamageOverTime} fire damage.",
                    OutputHelper.Display.Output[i][2]);
                Assert.AreEqual(i, monster.Effects[0].CurrentRound);
                GameHelper.RemovedExpiredEffectsAsync(monster);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, monster.Effects.Any());
            Assert.AreEqual(10, monster.HitPoints);
        }
コード例 #7
0
        public void OnslaughtAbilityUnitTest()
        {
            OutputHelper.Display.ClearUserOutput();
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100,
                RagePoints    = 100,
                InCombat      = true
            };

            player.Abilities.Add(new PlayerAbility(
                                     "onslaught", 25, 1, WarriorAbility.Onslaught, 8));
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, InCombat = true
            };

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Onslaught);

            string[] inputInfo = new[] { "ability", "onslaught" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Onslaught", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 25", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual(
                "Two attacks are launched which each cause instant damage. Cost and damage are per attack.",
                OutputHelper.Display.Output[4][2]);
            string[] input       = new[] { "use", "onslaught" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("onslaught", abilityName);
            player.UseAbility(monster, input);
            int?rageCost  = player.Abilities[abilityIndex].RageCost;
            int hitAmount = player.Abilities[abilityIndex].Offensive.Amount;

            Assert.AreEqual(monster.MaxHitPoints - (2 * hitAmount), monster.HitPoints);
            Assert.AreEqual(player.MaxRagePoints - (2 * rageCost), player.RagePoints);
            string attackString = $"Your onslaught hit the {monster.Name} for 25 physical damage.";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[5][2]);
            Assert.AreEqual(attackString, OutputHelper.Display.Output[6][2]);
            player.MaxRagePoints = 25;
            player.RagePoints    = player.MaxRagePoints;
            monster.MaxHitPoints = 100;
            monster.HitPoints    = monster.MaxHitPoints;
            player.UseAbility(monster, input);
            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            Assert.AreEqual(attackString, OutputHelper.Display.Output[7][2]);
            const string outOfRageString = "You didn't have enough rage points for the second attack!";

            Assert.AreEqual(outOfRageString, OutputHelper.Display.Output[8][2]);
        }
コード例 #8
0
        public void FirebreathSpellUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 200, MaxHitPoints = 200, FireResistance = 0
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Dragon);

            MonsterBuilder.BuildMonster(monster);
            int spellIndex = monster.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Fireball);

            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            monster.MonsterWeapon.CritMultiplier = 1;             // Remove crit chance to remove "noise" in test
            monster.Spellbook[spellIndex].CastFireOffense(monster, player, spellIndex);
            int spellCost = monster.Spellbook[spellIndex].EnergyCost;

            Assert.AreEqual(monster.MaxEnergyPoints - spellCost, monster.EnergyPoints);
            int spellDamage = monster.Spellbook[spellIndex].Offensive.Amount;

            Assert.AreEqual(player.MaxHitPoints - spellDamage, player.HitPoints);
            int spellMaxRounds = monster.Spellbook[spellIndex].Offensive.AmountMaxRounds;

            Assert.AreEqual(spellMaxRounds, player.Effects[0].MaxRound);
            string attackString = $"The {monster.Name} breathes a pillar of fire at you!";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string attackSuccessString = $"The {monster.Name} hits you for {spellDamage} fire damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]);
            const string onFireString = "You burst into flame!";

            Assert.AreEqual(onFireString, OutputHelper.Display.Output[2][2]);
            Assert.AreEqual(true, player.Effects[0] is BurningEffect);
            int           burnDamage = monster.Spellbook[spellIndex].Offensive.AmountOverTime;
            BurningEffect burnEffect = player.Effects[0] as BurningEffect;

            for (int i = 2; i < 5; i++)
            {
                burnEffect.ProcessRound();
                string burnString = $"You burn for {burnDamage} fire damage.";
                Assert.AreEqual(burnString, OutputHelper.Display.Output[i + 1][2]);
                Assert.AreEqual(i, player.Effects[0].CurrentRound);
                GameHelper.RemovedExpiredEffectsAsync(player);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, player.Effects.Any());
            Assert.AreEqual(player.MaxHitPoints - spellDamage - (burnDamage * 3), player.HitPoints);
        }
コード例 #9
0
        public void PreciseShotAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Archer)
            {
                MaxComboPoints = 100,
                ComboPoints    = 100,
                MaxHitPoints   = 100,
                HitPoints      = 10
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            string[] inputInfo    = new[] { "ability", "precise" };
            int      abilityIndex = player.Abilities.FindIndex(
                f => f.ArcAbilityCategory == ArcherAbility.Precise);

            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Precise Shot", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Combo Cost: 40", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 50", OutputHelper.Display.Output[3][2]);
            string[] input       = new[] { "use", "precise" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("precise", abilityName);
            int arrowCount = player.PlayerQuiver.Quantity;

            player.UseAbility(monster, input);
            Assert.AreEqual(arrowCount - 1, player.PlayerQuiver.Quantity);
            int?comboCost = player.Abilities[abilityIndex].ComboCost;

            Assert.AreEqual(player.MaxComboPoints - comboCost, player.ComboPoints);
            int abilityDamage = player.Abilities[abilityIndex].Offensive.Amount;

            Assert.AreEqual(monster.HitPoints, monster.MaxHitPoints - abilityDamage);
            string abilitySuccessString = $"Your {player.Abilities[abilityIndex].Name} hit the {monster.Name} for {abilityDamage} physical damage.";

            Assert.AreEqual(abilitySuccessString, OutputHelper.Display.Output[4][2]);
        }
コード例 #10
0
        public void DisarmAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100,
                RagePoints    = 100,
                MaxHitPoints  = 100,
                HitPoints     = 100
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Disarm);

            string[] inputInfo = new[] { "ability", "disarm" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Disarm", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 25", OutputHelper.Display.Output[2][2]);
            string abilityString = $"{player.Abilities[abilityIndex].Offensive.Amount}% chance to disarm opponent's weapon.";

            Assert.AreEqual(abilityString, OutputHelper.Display.Output[3][2]);
            player.Abilities[abilityIndex].Offensive.Amount = 0;             // Set disarm success chance to 0% for test
            string[] input       = new[] { "use", "disarm" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("disarm", abilityName);
            player.UseAbility(monster, input);
            int?rageCost = player.Abilities[abilityIndex].RageCost;

            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            Assert.AreEqual(true, monster.MonsterWeapon.Equipped);
            string disarmFailString = $"You tried to disarm {monster.Name} but failed!";

            Assert.AreEqual(disarmFailString, OutputHelper.Display.Output[4][2]);
            player.Abilities[abilityIndex].Offensive.Amount = 100;             // Set disarm success chance to 100% for test
            player.UseAbility(monster, input);
            Assert.AreEqual(player.MaxRagePoints - (rageCost * 2), player.RagePoints);
            Assert.AreEqual(false, monster.MonsterWeapon.Equipped);
            string disarmSuccessString = $"You successfully disarmed {monster.Name}!";

            Assert.AreEqual(disarmSuccessString, OutputHelper.Display.Output[5][2]);
        }
コード例 #11
0
        public void ValueUnitTests()
        {
            // Test RoundNumber method in Helper class
            Assert.AreEqual(110, GameHelper.RoundNumber(107));
            Assert.AreEqual(110, GameHelper.RoundNumber(105));
            Assert.AreEqual(100, GameHelper.RoundNumber(104));

            /* Test _Monster constructor HP and exp smoothing
             * if values smoothed correctly, % should be 0 */
            Monster monster = new Monster(1, MonsterType.Skeleton);

            MonsterBuilder.BuildMonster(monster);
            Assert.AreEqual(0, monster.MaxHitPoints % 10);
            Assert.AreEqual(0, monster.ExperienceProvided % 10);
        }
コード例 #12
0
        public void DetermineAttackUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 100, MaxHitPoints = 100
            };
            Monster monster = new Monster(3, MonsterType.Dragon);

            MonsterBuilder.BuildMonster(monster);
            OutputHelper.Display.ClearUserOutput();
            AttackOption attackChoice = monster.DetermineAttack(player, false);

            Assert.AreEqual(AttackType.Spell, attackChoice.AttackCategory);
            monster.EnergyPoints = 0;
            attackChoice         = monster.DetermineAttack(player, false);
            Assert.AreEqual(AttackType.Physical, attackChoice.AttackCategory);
        }
コード例 #13
0
        public void AmbushAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Archer)
            {
                MaxComboPoints = 100,
                ComboPoints    = 100,
                MaxHitPoints   = 100,
                HitPoints      = 10
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            player.Abilities.Add(new PlayerAbility(
                                     "ambush", 75, 1, ArcherAbility.Ambush, 4));
            string[] inputInfo = new[] { "ability", "ambush" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Ambush", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Combo Cost: 75", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 50", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("A surprise attack is launched, which initiates combat.",
                            OutputHelper.Display.Output[4][2]);
            string[] input = new[] { "use", "ambush", monster.Name };
            player.InCombat = true;
            int arrowCount = player.PlayerQuiver.Quantity;

            player.UseAbility(monster, input);
            Assert.AreEqual($"You can't ambush {monster.Name}, you're already in combat!",
                            OutputHelper.Display.Output[5][2]);
            player.InCombat = false;
            player.UseAbility(monster, input);
            int index = player.Abilities.FindIndex(
                f => f.ArcAbilityCategory == ArcherAbility.Ambush);
            int    abilityDamage = player.Abilities[index].Offensive.Amount;
            string attackString  = "Your ambush hit the " + monster.Name + " for " + abilityDamage + " physical damage.";

            Assert.AreEqual(arrowCount - 1, player.PlayerQuiver.Quantity);
            Assert.AreEqual(attackString, OutputHelper.Display.Output[6][2]);
            Assert.AreEqual(monster.HitPoints, monster.MaxHitPoints - abilityDamage);
        }
コード例 #14
0
        public void LightningSpellUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                MaxManaPoints = 100, ManaPoints = 100
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, ArcaneResistance = 0
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            string[] inputInfo  = new[] { "spell", "lightning" };
            int      spellIndex = player.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Lightning);

            PlayerHelper.SpellInfo(player, inputInfo);
            Assert.AreEqual("Lightning", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Mana Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 35", OutputHelper.Display.Output[3][2]);
            string[] input     = new[] { "cast", "lightning" };
            string   spellName = InputHelper.ParseInput(input);

            Assert.AreEqual("lightning", spellName);
            player.PlayerWeapon.Durability = 100;
            player.CastSpell(monster, spellName);
            Assert.AreEqual(player.MaxManaPoints - player.Spellbook[spellIndex].ManaCost, player.ManaPoints);
            int arcaneSpellDamage = player.Spellbook[spellIndex].Offensive.Amount;

            Assert.AreEqual(monster.HitPoints, monster.MaxHitPoints - arcaneSpellDamage);
            string attackSuccessString = $"You hit the {monster.Name} for {arcaneSpellDamage} arcane damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[4][2]);
        }
コード例 #15
0
        public void SlashAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100, RagePoints = 100
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            string[] inputInfo    = new[] { "ability", "slash" };
            int      abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Slash);

            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Slash", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 40", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 50", OutputHelper.Display.Output[3][2]);
            string[] input       = new[] { "use", "slash" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("slash", abilityName);
            player.UseAbility(monster, input);
            Assert.AreEqual(player.MaxRagePoints - player.Abilities[abilityIndex].RageCost,
                            player.RagePoints);
            int abilityDamage = player.Abilities[abilityIndex].Offensive.Amount;

            Assert.AreEqual(monster.HitPoints, monster.MaxHitPoints - abilityDamage);
            string abilitySuccessString = $"Your {player.Abilities[abilityIndex].Name} hit the {monster.Name} for {abilityDamage} physical damage.";

            Assert.AreEqual(abilitySuccessString, OutputHelper.Display.Output[4][2]);
        }
コード例 #16
0
        public void BloodLeechAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Vampire)
            {
                HitPoints = 10, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            int abilityIndex = monster.Abilities.FindIndex(
                f => f.AbilityCategory == Ability.BloodLeech);

            foreach (IItem item in player.Inventory.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            int monsterHealthBase = monster.HitPoints;

            monster.Abilities[abilityIndex].UseBloodLeechAbility(monster, player, abilityIndex);
            int abilityCost = monster.Abilities[abilityIndex].EnergyCost;

            Assert.AreEqual(monster.MaxEnergyPoints - abilityCost, monster.EnergyPoints);
            int leechAmount = monster.Abilities[abilityIndex].Offensive.Amount;

            Assert.AreEqual(player.MaxHitPoints - leechAmount, player.HitPoints);
            Assert.AreEqual(monsterHealthBase + leechAmount, monster.HitPoints);
            string attackString = $"The {monster.Name} tries to sink its fangs into you and suck your blood!";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string attackSuccessString = $"The {monster.Name} leeches {leechAmount} life from you.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]);
        }
コード例 #17
0
        public void LightningSpellUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 200, MaxHitPoints = 200, ArcaneResistance = 0
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Elemental);

            while (monster.ElementalCategory != ElementalType.Air)
            {
                monster = new Monster(3, MonsterType.Elemental);
            }
            MonsterBuilder.BuildMonster(monster);
            int spellIndex = monster.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Lightning);

            foreach (IItem item in player.Inventory.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            monster.Spellbook[spellIndex].CastArcaneOffense(monster, player, spellIndex);
            int spellCost = monster.Spellbook[spellIndex].EnergyCost;

            Assert.AreEqual(monster.MaxEnergyPoints - spellCost, monster.EnergyPoints);
            int spellDamage = monster.Spellbook[spellIndex].Offensive.Amount;

            Assert.AreEqual(player.MaxHitPoints - spellDamage, player.HitPoints);
            string attackString = $"The {monster.Name} casts a bolt of lightning at you!";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string attackSuccessString = $"The {monster.Name} hits you for {spellDamage} arcane damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]);
        }
コード例 #18
0
        public void MonsterResistanceUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                MaxManaPoints = 100, ManaPoints = 100
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            Assert.AreEqual(monster.Level * 5, monster.FireResistance);
            Assert.AreEqual(monster.Level * 5, monster.FrostResistance);
            Assert.AreEqual(monster.Level * 5, monster.ArcaneResistance);
            int    arcaneResistance = monster.ArcaneResistance;
            double resistanceMod    = (100 - arcaneResistance) / 100.0;

            string[] input      = new[] { "cast", "lightning" };
            int      spellIndex = player.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Lightning);
            string spellName = InputHelper.ParseInput(input);

            player.CastSpell(monster, spellName);
            int reducedDamage = (int)(player.Spellbook[spellIndex].Offensive.Amount * resistanceMod);

            Assert.AreEqual(monster.HitPoints, monster.MaxHitPoints - reducedDamage);
        }
コード例 #19
0
        public void ImmolatingArrowAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Archer)
            {
                MaxComboPoints = 100,
                ComboPoints    = 100,
                MaxHitPoints   = 100,
                HitPoints      = 10,
                InCombat       = true
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, InCombat = true, FireResistance = 0
            };

            MonsterBuilder.BuildMonster(monster);
            player.PlayerWeapon.CritMultiplier = 1;             // Remove crit chance to remove "noise" in test
            player.Abilities.Add(new PlayerAbility(
                                     "immolating arrow", 35, 1, ArcherAbility.ImmolatingArrow, 8));
            string[] input = new[] { "use", "immolating", "arrow" };
            PlayerHelper.AbilityInfo(player, input);
            Assert.AreEqual("Immolating Arrow", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Combo Cost: 35", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 25", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("Damage Over Time: 5", OutputHelper.Display.Output[4][2]);
            Assert.AreEqual("Fire damage over time for 3 rounds.", OutputHelper.Display.Output[5][2]);
            int arrowCount = player.PlayerQuiver.Quantity;

            player.UseAbility(monster, input);
            Assert.AreEqual(arrowCount - 1, player.PlayerQuiver.Quantity);
            int index = player.Abilities.FindIndex(
                f => f.ArcAbilityCategory == ArcherAbility.ImmolatingArrow);

            Assert.AreEqual(player.ComboPoints, player.MaxComboPoints - player.Abilities[index].ComboCost);
            string attackString = $"Your immolating arrow hit the {monster.Name} for 25 physical damage.";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[6][2]);
            Assert.AreEqual(monster.HitPoints,
                            monster.MaxHitPoints - player.Abilities[index].Offensive.Amount);
            OutputHelper.Display.ClearUserOutput();
            Assert.AreEqual(true, monster.Effects[0] is BurningEffect);
            Assert.AreEqual(3, monster.Effects[0].MaxRound);
            BurningEffect burnEffect = monster.Effects[0] as BurningEffect;

            for (int i = 0; i < 3; i++)
            {
                int baseHitPoints = monster.HitPoints;
                burnEffect.ProcessRound();
                Assert.AreEqual(i + 2, monster.Effects[0].CurrentRound);
                Assert.AreEqual(monster.HitPoints, baseHitPoints - burnEffect.FireDamageOverTime);
                string burnString = $"The {monster.Name} burns for {burnEffect.FireDamageOverTime} fire damage.";
                Assert.AreEqual(burnString, OutputHelper.Display.Output[i][2]);
                GameHelper.RemovedExpiredEffectsAsync(monster);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, monster.Effects.Any());
        }
コード例 #20
0
        public void ChargeAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100,
                RagePoints    = 100,
                InCombat      = true
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, InCombat = true
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Charge);

            string[] inputInfo = new[] { "ability", "charge" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Charge", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 15", OutputHelper.Display.Output[3][2]);
            string abilityInfoString = $"Stuns opponent for {player.Abilities[abilityIndex].Stun.StunMaxRounds} rounds, preventing their attacks.";

            Assert.AreEqual(abilityInfoString, OutputHelper.Display.Output[4][2]);
            string[] input       = new[] { "use", "charge" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("charge", abilityName);
            player.UseAbility(monster, input);
            int?rageCost = player.Abilities[abilityIndex].RageCost;

            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            int    abilityDamage       = player.Abilities[abilityIndex].Stun.DamageAmount;
            int    abilityCurRounds    = player.Abilities[abilityIndex].Stun.StunCurRounds;
            int    abilityMaxRounds    = player.Abilities[abilityIndex].Stun.StunMaxRounds;
            string attackSuccessString = $"You {player.Abilities[abilityIndex].Name} the {monster.Name} for {abilityDamage} physical damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[5][2]);
            string stunString = $"The {monster.Name} is stunned!";

            Assert.AreEqual(stunString, OutputHelper.Display.Output[6][2]);
            Assert.AreEqual(monster.MaxHitPoints - abilityDamage, monster.HitPoints);
            Assert.AreEqual(true, monster.Effects[0] is StunnedEffect);
            Assert.AreEqual(abilityCurRounds, monster.Effects[0].CurrentRound);
            Assert.AreEqual(abilityMaxRounds, monster.Effects[0].MaxRound);
            StunnedEffect stunnedEffect = monster.Effects[0] as StunnedEffect;

            OutputHelper.Display.ClearUserOutput();
            for (int i = 2; i < 4; i++)
            {
                stunnedEffect.ProcessRound();
                string stunnedString = $"The {monster.Name} is stunned and cannot attack.";
                Assert.AreEqual(stunnedString, OutputHelper.Display.Output[i - 2][2]);
                Assert.AreEqual(i, monster.Effects[0].CurrentRound);
                GameHelper.RemovedExpiredEffectsAsync(monster);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, monster.Effects.Any());
        }
コード例 #21
0
        public void ReflectDamageSpellUnitTest()
        {
            OutputHelper.Display.ClearUserOutput();
            Player player = new Player("test", PlayerClassType.Mage)
            {
                MaxManaPoints = 100, ManaPoints = 100
            };
            Monster monster = new Monster(3, MonsterType.Zombie)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            player.Spellbook.Add(new PlayerSpell(
                                     "reflect", 100, 1, SpellType.Reflect, 4));
            string[] inputInfo  = new[] { "spell", "reflect" };
            int      spellIndex = player.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Reflect);

            PlayerHelper.SpellInfo(player, inputInfo);
            Assert.AreEqual("Reflect", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Mana Cost: 100", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Reflect Damage Amount: 25", OutputHelper.Display.Output[3][2]);
            string reflectInfoString = $"Damage up to {player.Spellbook[spellIndex].ChangeAmount.Amount} will be reflected for " +
                                       $"{player.Spellbook[spellIndex].ChangeAmount.ChangeMaxRound} rounds.";

            Assert.AreEqual(reflectInfoString, OutputHelper.Display.Output[4][2]);
            string[] input     = new[] { "cast", "reflect" };
            string   spellName = InputHelper.ParseInput(input);

            Assert.AreEqual("reflect", spellName);
            player.CastSpell(spellName);
            Assert.AreEqual(player.MaxManaPoints - player.Spellbook[spellIndex].ManaCost, player.ManaPoints);
            Assert.AreEqual("You create a shield around you that will reflect damage.",
                            OutputHelper.Display.Output[5][2]);
            Assert.AreEqual(true, player.Effects.Any());
            Assert.AreEqual(true, player.Effects[0] is ReflectDamageEffect);
            ReflectDamageEffect reflectDmgEffect = player.Effects[0] as ReflectDamageEffect;

            OutputHelper.Display.ClearUserOutput();
            for (int i = 2; i < 5; i++)
            {
                int attackDamageM = monster.MonsterWeapon.Attack();
                int reflectAmount = reflectDmgEffect.ReflectDamageAmount < attackDamageM ?
                                    reflectDmgEffect.ReflectDamageAmount : attackDamageM;
                Assert.AreEqual(true, reflectAmount <= reflectDmgEffect.ReflectDamageAmount);
                monster.HitPoints -= reflectAmount;
                Assert.AreEqual(monster.HitPoints, monster.MaxHitPoints - (reflectAmount * (i - 1)));
                reflectDmgEffect.ProcessChangeDamageRound(reflectAmount);
                Assert.AreEqual(
                    $"You reflected {reflectAmount} damage back at your opponent!",
                    OutputHelper.Display.Output[i - 2][2]);
            }
            GameHelper.RemovedExpiredEffectsAsync(player);
            Thread.Sleep(1000);
            Assert.AreEqual(false, player.Effects.Any());
        }
コード例 #22
0
        public void FrostboltSpellUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                MaxManaPoints = 100, ManaPoints = 100
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, FrostResistance = 0
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            string[] inputInfo  = new[] { "spell", "frostbolt" };
            int      spellIndex = player.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Frostbolt);

            PlayerHelper.SpellInfo(player, inputInfo);
            Assert.AreEqual("Frostbolt", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Mana Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 15", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("Frost damage will freeze opponent for 2 rounds.",
                            OutputHelper.Display.Output[4][2]);
            Assert.AreEqual("Frozen opponents take 1.5x physical, arcane and frost damage.",
                            OutputHelper.Display.Output[5][2]);
            OutputHelper.Display.ClearUserOutput();
            string[] input     = new[] { "cast", "frostbolt" };
            string   spellName = InputHelper.ParseInput(input);

            Assert.AreEqual("frostbolt", spellName);
            player.PlayerWeapon.Durability = 100;
            double baseDamage = player.PhysicalAttack(monster);

            player.CastSpell(monster, spellName);
            Assert.AreEqual(player.MaxManaPoints - player.Spellbook[spellIndex].ManaCost, player.ManaPoints);
            Assert.AreEqual(85, monster.HitPoints);
            Assert.AreEqual(1, monster.Effects[0].CurrentRound);
            Assert.AreEqual(2, monster.Effects[0].MaxRound);
            string attackString = $"You hit the {monster.Name} for {player.Spellbook[spellIndex].Offensive.Amount} frost damage.";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string frozenString = $"The {monster.Name} is frozen. Physical, frost and arcane damage to it will be increased by 50%!";

            Assert.AreEqual(frozenString, OutputHelper.Display.Output[1][2]);
            FrozenEffect frozenEffect           = monster.Effects[0] as FrozenEffect;
            int          monsterHitPointsBefore = monster.HitPoints;
            double       totalBaseDamage        = 0.0;
            double       totalFrozenDamage      = 0.0;
            double       multiplier             = frozenEffect.EffectMultiplier;

            for (int i = 2; i < 4; i++)
            {
                frozenEffect.ProcessRound();
                Assert.AreEqual(i, monster.Effects[0].CurrentRound);
                Assert.AreEqual(frozenString, OutputHelper.Display.Output[i][2]);
                player.PlayerWeapon.Durability = 100;
                double frozenDamage = player.PhysicalAttack(monster);
                monster.HitPoints -= (int)frozenDamage;
                totalBaseDamage   += baseDamage;
                totalFrozenDamage += frozenDamage;
            }
            GameHelper.RemovedExpiredEffectsAsync(monster);
            Thread.Sleep(1000);
            Assert.AreEqual(false, monster.Effects.Any());
            int finalBaseDamageWithMod = (int)(totalBaseDamage * multiplier);
            int finalTotalFrozenDamage = (int)totalFrozenDamage;

            Assert.AreEqual(finalTotalFrozenDamage, finalBaseDamageWithMod, 14);
            Assert.AreEqual(monster.HitPoints, monsterHitPointsBefore - (int)totalFrozenDamage);
        }
コード例 #23
0
        public void FrostboltSpellUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Mage)
            {
                HitPoints = 200, MaxHitPoints = 200, FrostResistance = 0
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(1, MonsterType.Skeleton);

            while (monster.SkeletonCategory != SkeletonType.Mage)
            {
                monster = new Monster(1, MonsterType.Skeleton);
            }
            MonsterBuilder.BuildMonster(monster);
            monster.MonsterWeapon.CritMultiplier = 1;             // Remove crit chance to remove "noise" in test
            int spellIndex = monster.Spellbook.FindIndex(
                f => f.SpellCategory == SpellType.Frostbolt);

            foreach (IItem item in player.Inventory.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            monster.Spellbook[spellIndex].CastFrostOffense(monster, player, spellIndex);
            int spellCost = monster.Spellbook[spellIndex].EnergyCost;

            Assert.AreEqual(monster.MaxEnergyPoints - spellCost, monster.EnergyPoints);
            int spellDamage = monster.Spellbook[spellIndex].Offensive.Amount;

            Assert.AreEqual(player.MaxHitPoints - spellDamage, player.HitPoints);
            int spellMaxRounds = monster.Spellbook[spellIndex].Offensive.AmountMaxRounds;

            Assert.AreEqual(spellMaxRounds, player.Effects[0].MaxRound);
            string attackString = $"The {monster.Name} conjures up a frostbolt and launches it at you!";

            Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]);
            string attackSuccessString = $"The {monster.Name} hits you for {spellDamage} frost damage.";

            Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]);
            const string frozenString = "You are frozen. Physical, frost and arcane damage to you will be increased by 50%!";

            Assert.AreEqual(frozenString, OutputHelper.Display.Output[2][2]);
            Assert.AreEqual(true, player.Effects[0] is FrozenEffect);
            FrozenEffect frozenEffect = player.Effects[0] as FrozenEffect;

            // Remove all spells after casting to make monster decide to use physical attack for unit test
            monster.Spellbook = null;
            for (int i = 2; i < 4; i++)
            {
                int    playerHitPointsBefore = player.HitPoints;
                double multiplier            = frozenEffect.EffectMultiplier;
                int    baseDamage            = monster.MonsterWeapon.RegDamage;
                int    frozenDamage          = (int)(monster.MonsterWeapon.RegDamage * multiplier);
                Assert.AreEqual(frozenDamage, baseDamage * multiplier, 1);
                monster.MonsterWeapon.Durability = 100;
                monster.Attack(player);
                Assert.AreEqual(i, player.Effects[0].CurrentRound);
                Assert.AreEqual(frozenString, OutputHelper.Display.Output[i][2]);
                Assert.AreEqual(playerHitPointsBefore - frozenDamage, player.HitPoints, 7);
            }
            GameHelper.RemovedExpiredEffectsAsync(player);
            Thread.Sleep(1000);
            Assert.AreEqual(false, player.Effects.Any());
        }
コード例 #24
0
        public DungeonRoom(int levelRangeLow, int levelRangeHigh)
        {
            RoomObjects = new List <IName>();
            Commands    = new List <string> {
                "[I]nventory", "Save", "[Q]uit"
            };
            CombatCommands = new List <string> {
                "[F]ight", "[I]nventory", "Flee"
            };
            DungeonLevel = GameHelper.GetRandomNumber(levelRangeLow, levelRangeHigh);
            int randomNum = GameHelper.GetRandomNumber(1, 100);

            // Reserving numbers 80-100 for chance of room not having a monster
            if (randomNum <= 16)
            {
                // 20% chance of spawning based on cumulative 0.2 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Zombie);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 32)
            {
                // 20% chance of spawning based on cumulative 0.4 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Skeleton);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 40)
            {
                // 10% chance of spawning based on cumulative 0.5 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Elemental);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 48)
            {
                // 10% chance of spawning based on cumulative 0.6 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Vampire);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 60)
            {
                // 15% chance of spawning based on cumulative 0.75 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Troll);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 68)
            {
                // 10% chance of spawning based on cumulative 0.85 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Demon);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 76)
            {
                // 10% chance of spawning based on cumulative 0.95 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Spider);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
            else if (randomNum <= 80)
            {
                // 5% chance of spawning based on cumulative 1 * 80
                Monster = new Monster(DungeonLevel, Monsters.MonsterType.Dragon);
                MonsterBuilder.BuildMonster(Monster);
                RoomObjects.Add(Monster);
            }
        }
コード例 #25
0
        public void BlockAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100,
                RagePoints    = 100,
                InCombat      = true,
                MaxHitPoints  = 100,
                HitPoints     = 100,
                DodgeChance   = 0,
                Level         = 3
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Zombie)
            {
                HitPoints = 100, MaxHitPoints = 100, InCombat = true
            };

            MonsterBuilder.BuildMonster(monster);
            monster.MonsterWeapon.CritMultiplier = 1;
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Block);

            string[] inputInfo = new[] { "ability", "block" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Block", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Block Damage: 50", OutputHelper.Display.Output[3][2]);
            const string blockInfoString =
                "Block damage will prevent incoming damage from opponent until block damage is used up.";

            Assert.AreEqual(blockInfoString, OutputHelper.Display.Output[4][2]);
            string[] input       = new[] { "use", "block" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("block", abilityName);
            player.UseAbility(monster, input);
            int?rageCost = player.Abilities[abilityIndex].RageCost;

            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            int    blockAmount = player.Abilities[abilityIndex].Defensive.BlockDamage;
            string blockString = $"You start blocking your opponent's attacks! You will block {blockAmount} damage.";

            Assert.AreEqual(blockString, OutputHelper.Display.Output[5][2]);
            OutputHelper.Display.ClearUserOutput();
            Assert.AreEqual(true, player.Effects[0] is BlockDamageEffect);
            Assert.AreEqual(player.MaxHitPoints, player.HitPoints);
            BlockDamageEffect blockDmgEffect = player.Effects[0] as BlockDamageEffect;
            int blockAmountRemaining         = blockDmgEffect.BlockAmount;

            Assert.AreEqual(blockAmount, blockAmountRemaining);
            int i = 0;

            while (blockAmountRemaining > 0)
            {
                monster.MonsterWeapon.Durability = 100;
                int blockAmountBefore = blockAmountRemaining;
                monster.Attack(player);
                blockAmountRemaining = player.Effects.Any() ? blockDmgEffect.BlockAmount : 0;
                if (blockAmountRemaining > 0)
                {
                    Assert.AreEqual(player.MaxHitPoints, player.HitPoints);
                    string blockRoundString = $"Your defensive move blocked {(blockAmountBefore - blockAmountRemaining)} damage!";
                    Assert.AreEqual(blockRoundString, OutputHelper.Display.Output[i + (i * 1)][2]);
                }
                else
                {
                    GameHelper.RemovedExpiredEffectsAsync(player);
                    int attackAmount = monster.MonsterWeapon.Attack() - blockAmountBefore;
                    Assert.AreEqual(player.MaxHitPoints - attackAmount, player.HitPoints);
                    const string blockEndString = "You are no longer blocking damage!";
                    Assert.AreEqual(blockEndString, OutputHelper.Display.Output[i + 3][2]);
                    Thread.Sleep(1000);
                    Assert.AreEqual(false, player.Effects.Any());
                    string hitString = $"The {monster.Name} hits you for {attackAmount} physical damage.";
                    Assert.AreEqual(hitString, OutputHelper.Display.Output[i + 4][2]);
                }
                i++;
            }
        }
コード例 #26
0
        public void RendAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100, RagePoints = 100
            };

            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Rend);

            string[] inputInfo = new[] { "ability", "rend" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Rend", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 15", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("Damage Over Time: 5", OutputHelper.Display.Output[4][2]);
            string bleedOverTimeString = $"Bleeding damage over time for {player.Abilities[abilityIndex].Offensive.AmountMaxRounds} rounds.";

            Assert.AreEqual(bleedOverTimeString, OutputHelper.Display.Output[5][2]);
            string[] input       = new[] { "use", "rend" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("rend", abilityName);
            player.UseAbility(monster, input);
            int?rageCost = player.Abilities[abilityIndex].RageCost;

            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            int    abilityDamage         = player.Abilities[abilityIndex].Offensive.Amount;
            int    abilityDamageOverTime = player.Abilities[abilityIndex].Offensive.AmountOverTime;
            int    abilityCurRounds      = player.Abilities[abilityIndex].Offensive.AmountCurRounds;
            int    abilityMaxRounds      = player.Abilities[abilityIndex].Offensive.AmountMaxRounds;
            string abilitySuccessString  = $"Your {player.Abilities[abilityIndex].Name} hit the {monster.Name} for {abilityDamage} physical damage.";

            Assert.AreEqual(abilitySuccessString, OutputHelper.Display.Output[6][2]);
            string bleedString = $"The {monster.Name} is bleeding!";

            Assert.AreEqual(bleedString, OutputHelper.Display.Output[7][2]);
            Assert.AreEqual(true, monster.Effects[0] is BleedingEffect);
            Assert.AreEqual(monster.MaxHitPoints - abilityDamage, monster.HitPoints);
            Assert.AreEqual(abilityCurRounds, monster.Effects[0].CurrentRound);
            Assert.AreEqual(abilityMaxRounds, monster.Effects[0].MaxRound);
            BleedingEffect bleedEffect = monster.Effects[0] as BleedingEffect;

            OutputHelper.Display.ClearUserOutput();
            for (int i = 2; i < 5; i++)
            {
                bleedEffect.ProcessRound();
                int    bleedAmount      = bleedEffect.BleedDamageOverTime;
                string bleedRoundString = $"The {monster.Name} bleeds for {bleedAmount} physical damage.";
                Assert.AreEqual(bleedRoundString, OutputHelper.Display.Output[i - 2][2]);
                Assert.AreEqual(i, monster.Effects[0].CurrentRound);
                GameHelper.RemovedExpiredEffectsAsync(monster);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, monster.Effects.Any());
            Assert.AreEqual(monster.MaxHitPoints - abilityDamage - (abilityDamageOverTime * abilityMaxRounds),
                            monster.HitPoints);
        }
コード例 #27
0
        public void BerserkAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Warrior)
            {
                MaxRagePoints = 100,
                RagePoints    = 100,
                InCombat      = true,
                MaxHitPoints  = 100,
                HitPoints     = 100,
                DodgeChance   = 0
            };

            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            Monster monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100, InCombat = true
            };

            MonsterBuilder.BuildMonster(monster);
            foreach (IItem item in monster.MonsterItems.Where(item => item is IEquipment eItem && eItem.Equipped))
            {
                IEquipment eItem = item as IEquipment;
                eItem.Equipped = false;
            }
            int abilityIndex = player.Abilities.FindIndex(
                f => f.WarAbilityCategory == WarriorAbility.Berserk);

            string[] inputInfo = new[] { "ability", "berserk" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Berserk", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Rage Cost: 40", OutputHelper.Display.Output[2][2]);
            string dmgIncreaseString = $"Damage Increase: {player.Abilities[abilityIndex].Offensive.Amount}";

            Assert.AreEqual(dmgIncreaseString, OutputHelper.Display.Output[3][2]);
            string armDecreaseString = $"Armor Decrease: {player.Abilities[abilityIndex].ChangeAmount.Amount}";

            Assert.AreEqual(armDecreaseString, OutputHelper.Display.Output[4][2]);
            string dmgInfoString = $"Damage increased at cost of armor decrease for {player.Abilities[abilityIndex].ChangeAmount.ChangeMaxRound} rounds";

            Assert.AreEqual(dmgInfoString, OutputHelper.Display.Output[5][2]);
            string[] input       = new[] { "use", "berserk" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("berserk", abilityName);
            int baseArmorRating = GearHelper.CheckArmorRating(player);
            int baseDamage      = player.PhysicalAttack(monster);

            player.UseAbility(monster, input);
            int?rageCost = player.Abilities[abilityIndex].RageCost;

            Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints);
            Assert.AreEqual(2, player.Effects.Count);
            Assert.AreEqual(true, player.Effects[0] is ChangePlayerDamageEffect);
            Assert.AreEqual(true, player.Effects[1] is ChangeArmorEffect);
            ChangePlayerDamageEffect changePlayerDmgEffect = player.Effects[0] as ChangePlayerDamageEffect;
            ChangeArmorEffect        changeArmorEffect     = player.Effects[1] as ChangeArmorEffect;
            const string             berserkString         = "You go into a berserk rage!";

            Assert.AreEqual(berserkString, OutputHelper.Display.Output[6][2]);
            for (int i = 2; i < 6; i++)
            {
                OutputHelper.Display.ClearUserOutput();
                int berserkArmorAmount  = player.Abilities[abilityIndex].ChangeAmount.Amount;
                int berserkDamageAmount = player.Abilities[abilityIndex].Offensive.Amount;
                int berserkArmorRating  = GearHelper.CheckArmorRating(player);
                int berserkDamage       = player.PhysicalAttack(monster);
                Assert.AreEqual(berserkArmorRating, baseArmorRating + berserkArmorAmount);
                Assert.AreEqual(berserkDamage, baseDamage + berserkDamageAmount, 5);
                changePlayerDmgEffect.ProcessChangePlayerDamageRound(player);
                string changeDmgString = $"Your damage is increased by {berserkDamageAmount}.";
                Assert.AreEqual(changeDmgString, OutputHelper.Display.Output[0][2]);
                changeArmorEffect.ProcessChangeArmorRound();
                string changeArmorString = $"Your armor is decreased by {berserkArmorAmount * -1}.";
                Assert.AreEqual(changeArmorString, OutputHelper.Display.Output[1][2]);
                GameHelper.RemovedExpiredEffectsAsync(player);
                Thread.Sleep(1000);
            }
            Assert.AreEqual(false, player.Effects.Any());
        }
コード例 #28
0
        public void WeaponUnitTests()
        {
            // Test weapon creation values
            // Test case 1, weapon on level 1 skeleton based on possible weapon types
            // _Name check
            Monster skeletonLevelOne = new Monster(1, MonsterType.Skeleton);

            MonsterBuilder.BuildMonster(skeletonLevelOne);
            Weapon skeletonWeapon = skeletonLevelOne.MonsterWeapon;

            switch (skeletonWeapon.Quality)
            {
            case 1:
                switch (skeletonWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                    Assert.AreEqual("chipped dagger", skeletonWeapon.Name);
                    break;

                case WeaponType.OneHandedSword:
                    Assert.AreEqual("chipped sword (1H)", skeletonWeapon.Name);
                    break;

                case WeaponType.TwoHandedSword:
                    Assert.AreEqual("chipped sword (2H)", skeletonWeapon.Name);
                    break;

                case WeaponType.Axe:
                case WeaponType.Bow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 2:
                switch (skeletonWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                    Assert.AreEqual("chipped sturdy dagger", skeletonWeapon.Name);
                    break;

                case WeaponType.OneHandedSword:
                    Assert.AreEqual("chipped sturdy sword (1H)", skeletonWeapon.Name);
                    break;

                case WeaponType.TwoHandedSword:
                    Assert.AreEqual("chipped sturdy sword (2H)", skeletonWeapon.Name);
                    break;

                case WeaponType.Axe:
                case WeaponType.Bow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 3:
                switch (skeletonWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                    Assert.AreEqual("chipped fine dagger", skeletonWeapon.Name);
                    break;

                case WeaponType.OneHandedSword:
                    Assert.AreEqual("chipped fine sword (1H)", skeletonWeapon.Name);
                    break;

                case WeaponType.TwoHandedSword:
                    Assert.AreEqual("chipped fine sword (2H)", skeletonWeapon.Name);
                    break;

                case WeaponType.Axe:
                case WeaponType.Bow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;
            }
            // Test case 2, weapon on level 1 spider based on possible weapon types
            // _Name check
            Monster spiderLevelOne = new Monster(1, MonsterType.Spider);

            MonsterBuilder.BuildMonster(spiderLevelOne);
            Weapon spiderWeapon = spiderLevelOne.MonsterWeapon;

            switch (spiderWeapon.Quality)
            {
            case 1:
                switch (spiderWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                    Assert.AreEqual("venomous fang", spiderWeapon.Name);
                    break;

                case WeaponType.OneHandedSword:
                case WeaponType.TwoHandedSword:
                case WeaponType.Axe:
                case WeaponType.Bow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 2:
                switch (spiderWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                    Assert.AreEqual("sturdy venomous fang", spiderWeapon.Name);
                    break;

                case WeaponType.OneHandedSword:
                case WeaponType.TwoHandedSword:
                case WeaponType.Axe:
                case WeaponType.Bow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 3:
                switch (spiderWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                    Assert.AreEqual("fine venomous fang", spiderWeapon.Name);
                    break;

                case WeaponType.OneHandedSword:
                case WeaponType.TwoHandedSword:
                case WeaponType.Axe:
                case WeaponType.Bow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;
            }
            // Test case 3, weapon on level 3 zombie based on possible weapon types
            // _Name check
            Monster zombieLevelThree = new Monster(3, MonsterType.Zombie);

            MonsterBuilder.BuildMonster(zombieLevelThree);
            Weapon zombieWeapon = zombieLevelThree.MonsterWeapon;

            switch (zombieWeapon.Quality)
            {
            case 1:
                switch (zombieWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                case WeaponType.OneHandedSword:
                case WeaponType.TwoHandedSword:
                case WeaponType.Bow:
                    break;

                case WeaponType.Axe:
                    Assert.AreEqual("worn axe", zombieWeapon.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 2:
                switch (zombieWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                case WeaponType.OneHandedSword:
                case WeaponType.TwoHandedSword:
                case WeaponType.Bow:
                    break;

                case WeaponType.Axe:
                    Assert.AreEqual("worn sturdy axe", zombieWeapon.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 3:
                switch (zombieWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                case WeaponType.OneHandedSword:
                case WeaponType.TwoHandedSword:
                case WeaponType.Bow:
                    break;

                case WeaponType.Axe:
                    Assert.AreEqual("worn fine axe", zombieWeapon.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;
            }
            // Test case 3, weapon on level 3 zombie based on possible weapon types
            // _Name check
            Monster demonLevelTwo = new Monster(2, MonsterType.Demon);

            MonsterBuilder.BuildMonster(demonLevelTwo);
            Weapon demonWeapon = demonLevelTwo.MonsterWeapon;

            switch (demonWeapon.Quality)
            {
            case 1:
                switch (demonWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                case WeaponType.Bow:
                    break;

                case WeaponType.OneHandedSword:
                    Assert.AreEqual("dull sword (1H)", demonWeapon.Name);
                    break;

                case WeaponType.TwoHandedSword:
                    Assert.AreEqual("dull sword (2H)", demonWeapon.Name);
                    break;

                case WeaponType.Axe:
                    Assert.AreEqual("dull axe", demonWeapon.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 2:
                switch (demonWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                case WeaponType.Bow:
                    break;

                case WeaponType.OneHandedSword:
                    Assert.AreEqual("dull sturdy sword (1H)", demonWeapon.Name);
                    break;

                case WeaponType.TwoHandedSword:
                    Assert.AreEqual("dull sturdy sword (2H)", demonWeapon.Name);
                    break;

                case WeaponType.Axe:
                    Assert.AreEqual("dull sturdy axe", demonWeapon.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case 3:
                switch (demonWeapon.WeaponGroup)
                {
                case WeaponType.Dagger:
                case WeaponType.Bow:
                    break;

                case WeaponType.OneHandedSword:
                    Assert.AreEqual("dull fine sword (1H)", demonWeapon.Name);
                    break;

                case WeaponType.TwoHandedSword:
                    Assert.AreEqual("dull fine sword (2H)", demonWeapon.Name);
                    break;

                case WeaponType.Axe:
                    Assert.AreEqual("dull fine axe", demonWeapon.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;
            }
        }
コード例 #29
0
        public void DistanceShotAbilityUnitTest()
        {
            Player player = new Player("test", PlayerClassType.Archer)
            {
                MaxComboPoints = 100,
                ComboPoints    = 100,
                MaxHitPoints   = 100,
                HitPoints      = 10
            };

            RoomHelper.Rooms = new Dictionary <Coordinate, IRoom> {
                { new Coordinate(0, 0, 0), new DungeonRoom(1, 1) },
                { new Coordinate(0, 1, 0), new DungeonRoom(1, 1) },
                { new Coordinate(1, 0, 0), new DungeonRoom(1, 1) }
            };
            Coordinate roomOneCoord = new Coordinate(0, 1, 0);
            Coordinate roomTwoCoord = new Coordinate(1, 0, 0);

            RoomHelper.Rooms[roomTwoCoord].Monster = null;
            RoomHelper.Rooms[roomOneCoord].Monster = new Monster(3, MonsterType.Demon)
            {
                HitPoints = 100, MaxHitPoints = 100
            };
            Monster monster = RoomHelper.Rooms[roomOneCoord].Monster;

            MonsterBuilder.BuildMonster(monster);
            RoomHelper.SetPlayerLocation(player, 0, 0, 0);
            GearHelper.EquipInitialGear(player);
            OutputHelper.Display.ClearUserOutput();
            string[] inputInfo = new[] { "ability", "distance" };
            PlayerHelper.AbilityInfo(player, inputInfo);
            Assert.AreEqual("Distance Shot", OutputHelper.Display.Output[0][2]);
            Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]);
            Assert.AreEqual("Combo Cost: 25", OutputHelper.Display.Output[2][2]);
            Assert.AreEqual("Instant Damage: 25", OutputHelper.Display.Output[3][2]);
            Assert.AreEqual("50% chance to hit monster in attack direction.",
                            OutputHelper.Display.Output[4][2]);
            Assert.AreEqual("Usage example if monster is in room to north. 'use distance north'",
                            OutputHelper.Display.Output[5][2]);
            string[] input       = new[] { "use", "distance", "south" };
            string   abilityName = InputHelper.ParseInput(input);

            Assert.AreEqual("distance south", abilityName);
            int arrowCount = player.PlayerQuiver.Quantity;

            player.UseAbility(input);
            Assert.AreEqual(arrowCount, player.PlayerQuiver.Quantity);
            Assert.AreEqual("You can't attack in that direction!", OutputHelper.Display.Output[6][2]);
            Assert.AreEqual(player.MaxComboPoints, player.ComboPoints);
            input = new[] { "use", "distance", "east" };
            player.UseAbility(input);
            Assert.AreEqual(arrowCount, player.PlayerQuiver.Quantity);
            Assert.AreEqual("There is no monster in that direction to attack!",
                            OutputHelper.Display.Output[7][2]);
            Assert.AreEqual(player.MaxComboPoints, player.ComboPoints);
            Assert.AreEqual(player.MaxComboPoints, player.ComboPoints);
            int abilityIndex = player.Abilities.FindIndex(
                f => f.ArcAbilityCategory == ArcherAbility.Distance);
            int?comboCost = player.Abilities[abilityIndex].ComboCost;

            player.Abilities[abilityIndex].Offensive.ChanceToSucceed = 0;
            input = new[] { "use", "distance", "north" };
            player.UseAbility(input);
            Assert.AreEqual(arrowCount - 1, player.PlayerQuiver.Quantity);
            string missString = $"You tried to shoot {monster.Name} from afar but failed!";

            Assert.AreEqual(missString, OutputHelper.Display.Output[8][2]);
            Assert.AreEqual(player.MaxComboPoints - comboCost, player.ComboPoints);
            player.Abilities[abilityIndex].Offensive.ChanceToSucceed = 100;
            player.ComboPoints = player.MaxComboPoints;
            arrowCount         = player.PlayerQuiver.Quantity;
            player.UseAbility(input);
            Assert.AreEqual(arrowCount - 1, player.PlayerQuiver.Quantity);
            int    abilityDmg  = player.Abilities[abilityIndex].Offensive.Amount;
            string shootString = $"You successfully shot {monster.Name} from afar for {abilityDmg} damage!";

            Assert.AreEqual(shootString, OutputHelper.Display.Output[9][2]);
            Assert.AreEqual(player.MaxComboPoints - comboCost, player.ComboPoints);
            Assert.AreEqual(monster.MaxHitPoints - abilityDmg, monster.HitPoints);
        }