Пример #1
0
        public void AddResistance_ShouldAddDamageTypeToList()
        {
            // Arrange
            var instance = new HitPoints(42);

            // Act
            instance.AddResistance(DamageTypes.Fire);
            // Assert
            instance.Resistances.Should().HaveCount(1);
            instance.Resistances[0].Should().Be(DamageTypes.Fire);
        }
Пример #2
0
        public void DealDamages_ShouldOnlyDoHalfDamage_WhenMultipleResistances()
        {
            // Arrange
            var instance = new HitPoints(42);

            instance.AddResistance(DamageTypes.Fire);
            instance.AddResistance(DamageTypes.Fire);
            instance.AddResistance(DamageTypes.Fire);
            var damages = new DealDamage[]
            {
                new DealDamage {
                    DamageType = DamageTypes.Fire, Hp = 8
                }
            };

            // Act
            instance.DealDamages(damages);
            // Assert
            instance.CurrentHp.Should().Be(38);
        }
Пример #3
0
        public void DealDamages_ShouldDoHalfDamageRoundedDown_WhenResitance()
        {
            // Arrange
            var instance = new HitPoints(42);

            instance.AddResistance(DamageTypes.Fire);
            var damages = new DealDamage[]
            {
                new DealDamage {
                    DamageType = DamageTypes.Fire, Hp = 5
                }
            };

            // Act
            instance.DealDamages(damages);
            // Assert
            instance.CurrentHp.Should().Be(40);
        }
Пример #4
0
        public void DealDamages_ShouldProcessResistanceThenVulnerability_WhenBoth()
        {
            // Arrange
            var instance = new HitPoints(42);

            instance.AddResistance(DamageTypes.Fire);
            instance.AddVulnerability(DamageTypes.Fire);
            var damages = new DealDamage[]
            {
                new DealDamage {
                    DamageType = DamageTypes.Fire, Hp = 9
                }
            };

            // Act
            instance.DealDamages(damages);
            // Assert
            instance.CurrentHp.Should().Be(34);
        }
Пример #5
0
        private void AddDamageModifiers(HitPoints hitPoints, IEnumerable <CreateDefense> defenses)
        {
            foreach (var defense in defenses)
            {
                switch (defense.Defense)
                {
                case DamageModifierTypes.Immunity:
                    hitPoints.AddImmunity(defense.Type);
                    break;

                case DamageModifierTypes.Resistance:
                    hitPoints.AddResistance(defense.Type);
                    break;

                case DamageModifierTypes.Vulnerability:
                    hitPoints.AddVulnerability(defense.Type);
                    break;
                }
            }
        }