예제 #1
0
        private void RunWar(DeltaMetadata deltaMetadata, War war)
        {
            var borderView   = _empireRepository.GetEmpireBorderView(war.AttackerId, war.DefenderId);
            var attacker     = borderView.Empire;
            var defender     = borderView.BorderingEmpire;
            var combatResult = _militaryCalculator.Combat(attacker, defender);

            _warRepository.ContinueWar(
                deltaMetadata,
                war.Id,
                combatResult.AttackerDamage.MilitaryDamage,
                combatResult.DefenderDamage.MilitaryDamage);
            _economicSimulator.ApplyDamage(
                deltaMetadata,
                borderView,
                combatResult.AttackerDamage.CollateralDamage,
                combatResult.DefenderDamage.CollateralDamage);
            _empireRepository.ApplyMilitaryDamage(
                deltaMetadata,
                war.AttackerId,
                combatResult.DefenderDamage.MilitaryDamage);
            _empireRepository.ApplyMilitaryDamage(
                deltaMetadata,
                war.DefenderId,
                combatResult.AttackerDamage.MilitaryDamage);
            SystemTransfer(deltaMetadata, combatResult.TerritoryGain, borderView);
            TryEndWar(deltaMetadata, war.Id, combatResult.TerritoryGain, war.AttackerId, war.DefenderId);
        }
예제 #2
0
        public void DamageIsProductOfEmpireMilitaryAndRandomNumber(double attackerMilitary, double defenderMilitary, double attackerRandom, double defenderRandom)
        {
            _random.Setup(x => x.DoubleSet(Parameters.MilitaryDamageRateMinimum, Parameters.MilitaryDamageRateMaximum, 2))
            .Returns(new double[] { attackerRandom, defenderRandom });
            var attacker = new Empire {
                Military = attackerMilitary
            };
            var defender = new Empire {
                Military = defenderMilitary
            };
            var expectedAttackerDamage = attackerMilitary * attackerRandom;
            var expectedDefenderDamage = defenderMilitary * defenderRandom;

            var result = _militaryCalculator.Combat(attacker, defender);

            Assert.Equal(expectedAttackerDamage, result.AttackerDamage.MilitaryDamage);
            Assert.Equal(expectedDefenderDamage, result.DefenderDamage.MilitaryDamage);
        }