Exemplo n.º 1
0
        public void CastSpell_CalculatesCorrectDamage(
            [Values(40, 80)] int magicStrength,
            [Values(0, 6)] int magicBonus,
            [Values(null, 0.25, 1.5)] double?individualMagicStrengthMultiplier,
            [Values(null, 0.5, 2.0)] double?teamMagicStrengthMultiplier,
            [Values(0, 4)] int resistance,
            [Values(0, 2)] int resistanceBonus,
            [Values(FighterMagicRelationshipType.Weak, FighterMagicRelationshipType.Resistant, FighterMagicRelationshipType.Immune)] FighterMagicRelationshipType relationshipType,
            [Values(MagicType.Ice, MagicType.All)] MagicType affinityMagicType,
            [Values(MagicType.Ice, MagicType.Lightning)] MagicType spellMagicType,
            [Values(false, true)] bool useAllTypeMultiplier
            )
        {
            const int maxHealth     = 500;
            const int spellStrength = 10;
            int       totalStrength = magicStrength + spellStrength + magicBonus;

            totalStrength = ApplyNullableMultiplier(totalStrength, individualMagicStrengthMultiplier);
            totalStrength = ApplyNullableMultiplier(totalStrength, teamMagicStrengthMultiplier);

            MagicType magicMultiplierType = (useAllTypeMultiplier) ? MagicType.All : spellMagicType;

            if (individualMagicStrengthMultiplier != null)
            {
                MagicMultiplierStatus status = new MagicMultiplierStatus(1, magicMultiplierType, individualMagicStrengthMultiplier.Value);
                _human.AddStatus(status);
            }

            if (teamMagicStrengthMultiplier != null)
            {
                MagicMultiplierStatus status = new MagicMultiplierStatus(1, magicMultiplierType, teamMagicStrengthMultiplier.Value);
                _humanTeam.AddStatus(status);
            }

            int totalResistance = resistance + resistanceBonus;

            int total = totalStrength - totalResistance;

            switch (relationshipType)
            {
            case FighterMagicRelationshipType.Immune:
                _enemy.SetElementalImmunity(affinityMagicType);
                if (affinityMagicType == MagicType.All || affinityMagicType == spellMagicType)
                {
                    total = 0;
                }
                break;

            case FighterMagicRelationshipType.Resistant:
                _enemy.SetElementalResistance(affinityMagicType);
                if (affinityMagicType == MagicType.All || affinityMagicType == spellMagicType)
                {
                    total /= 2;
                }
                break;

            case FighterMagicRelationshipType.Weak:
                _enemy.SetElementalWeakness(affinityMagicType);
                if (affinityMagicType == MagicType.All || affinityMagicType == spellMagicType)
                {
                    total *= 2;
                }
                break;
            }

            int expectedRemainingHealth = (total >= maxHealth) ? 0 : maxHealth - total;

            var spell = new Spell("foo", spellMagicType, SpellType.Attack, TargetType.SingleEnemy, 0, spellStrength);

            _human.SetMagicStrength(magicStrength);
            _human.SetMagicBonus(spellMagicType, magicBonus);
            _human.SetDeathOnTurnEndEvent();
            _human.AddSpell(spell);
            _human.SetMove(spell);
            _human.SetMoveTarget(_enemy);

            _enemy.SetHealth(500);
            _enemy.SetMagicResistance(resistance);
            _enemy.SetResistanceBonus(spellMagicType, resistanceBonus);

            _battleManager.Battle(_humanTeam, _enemyTeam);

            Assert.AreEqual(expectedRemainingHealth, _enemy.CurrentHealth);
        }