예제 #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 CreatesDeltasWithCorrectValues()
        {
            var simulationId = ObjectId.GenerateNewId();
            var metadata     = new DeltaMetadata(simulationId, 54);

            var empireSystems = new StarSystem[]
            {
                new StarSystem(),
                new StarSystem(),
                new StarSystem(),
                new StarSystem(),
                new StarSystem()
            };
            var borderingSystems = new StarSystem[]
            {
                new StarSystem(),
                new StarSystem(),
                new StarSystem(),
                new StarSystem(),
                new StarSystem()
            };

            var view = new EmpireBorderView
            {
                Empire                 = new Empire(),
                EmpireSystems          = empireSystems,
                BorderingEmpire        = new Empire(),
                BorderingEmpireSystems = borderingSystems
            };

            _economicSimulator.ApplyDamage(metadata, view, 324, 4224.56);

            foreach (var system in empireSystems)
            {
                _starSystemRepository.Verify(
                    x => x.ApplyDamage(
                        It.Is <IEnumerable <Delta <double> > >(
                            deltas =>
                            deltas.Any(
                                delta =>
                                delta.DeltaType == DeltaType.SystemDevelopment &&
                                delta.SimulationId == simulationId &&
                                delta.Tick == 54 &&
                                delta.ReferenceId == system.Id &&
                                delta.Value == 324))),
                    Times.Once);
            }

            foreach (var system in borderingSystems)
            {
                _starSystemRepository.Verify(
                    x => x.ApplyDamage(
                        It.Is <IEnumerable <Delta <double> > >(
                            deltas =>
                            deltas.Any(
                                delta =>
                                delta.DeltaType == DeltaType.SystemDevelopment &&
                                delta.SimulationId == simulationId &&
                                delta.Tick == 54 &&
                                delta.ReferenceId == system.Id &&
                                delta.Value == 4224.56))),
                    Times.Once);
            }
        }