Ejemplo n.º 1
0
        public War StartRessistanceWar(Citizen startingCitizen, Country attackingCountry, Region defendingRegion, IBattleService battleService)
        {
            var defendingCountry = defendingRegion.Country;
            var war = new War()
            {
                Attacker             = attackingCountry,
                Defender             = defendingCountry,
                StartDay             = GameHelper.CurrentDay,
                Active               = true,
                EndDay               = null,
                IsRessistanceWar     = true,
                RessistanceStarterID = startingCitizen.ID
            };

            List <CountryInWar> participatingCountries = getParticipatingCountries(attackingCountry, defendingCountry, isRessistanceWar: true);

            war.CountryInWars = participatingCountries;


            using (var trs = transactionScopeProvider.CreateTransactionScope())
            {
                warRepository.Add(war);
                ConditionalSaveChanges(warRepository);

                transactionService.PayForResistanceWar(startingCitizen, defendingRegion, this);
                battleService.CreateBattle(war, defendingRegion.ID, WarSideEnum.Attacker);

                trs.Complete();
                return(war);
            }
        }
Ejemplo n.º 2
0
        public ActionResult StartBattle(int warID, StartBattleViewModel vm)
        {
            var war = warRepository.GetById(warID);

            if (war == null)
            {
                return(NoWarRedirect());
            }

            var entity          = SessionHelper.CurrentEntity;
            var operatedCountry = warService.GetControlledCountryInWar(entity, war);

            MethodResult result;

            if ((result = warService.CanStartBattle(SessionHelper.CurrentEntity, operatedCountry, war)).IsError)
            {
                AddError(result);
                return(RedirectToAction("View", new { warID = warID }));
            }

            var warSide = warService.GetWarSide(war, SessionHelper.CurrentEntity);

            if (warSide == WarSideEnum.None)
            {
                AddError("You are not participating in this war!");
                return(RedirectToAction("View", new { warID = warID }));
            }


            var conquerableRegions = warRepository.GetAttackableRegions(war.ID, warSide == WarSideEnum.Attacker);

            if (conquerableRegions.Any(c => c.ID == vm.SelectedRegionID) == false)
            {
                AddError("You cannot attack this region!");
                return(RedirectToAction("View", new { warID = warID }));
            }

            var country    = war.GetMainCountry(warSide);
            var walletID   = country.Entity.WalletID;
            var region     = regionRepository.GetById(vm.SelectedRegionID);
            var goldNeeded = warService.GetGoldNeededToStartBattle(war, region);

            if (walletRepository.HaveMoney(walletID, CurrencyTypeEnum.Gold, goldNeeded) == false)
            {
                AddError("You do not have enough gold to attack this region!");
                return(RedirectToAction("View", new { warID = warID }));
            }

            if (ModelState.IsValid)
            {
                Entities.Battle battle = battleService.CreateBattle(war, vm.SelectedRegionID, warSide);
                return(RedirectToAction("View", "Battle", new { battleID = battle.ID }));
            }

            vm = new StartBattleViewModel(war, warRepository, warService);

            return(View(vm));
        }
Ejemplo n.º 3
0
        public Battle StartRessistanceBattle(Citizen startingCitizen, Region defendingRegion, IBattleService battleService)
        {
            Country attackingCountry = startingCitizen.Country;
            var     activeWar        = GetActiveRessistanceWar(attackingCountry, defendingRegion.CountryID.Value);

            if (activeWar == null)
            {
                return(StartRessistanceWar(startingCitizen, attackingCountry, defendingRegion, battleService).Battles.First());
            }
            else
            {
                using (var trs = transactionScopeProvider.CreateTransactionScope())
                {
                    transactionService.PayForResistanceBattle(startingCitizen, defendingRegion, this);
                    var battle = battleService.CreateBattle(activeWar, defendingRegion.ID, WarSideEnum.Attacker);

                    trs.Complete();
                    return(battle);
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([FromBody] CreateBattleCommand command)
        {
            await _battleService.CreateBattle(command.Range);

            return(Ok());
        }
Ejemplo n.º 5
0
 public void CreateMatrix([FromBody] CreateMatrixRequest model)
 {
     _service.CreateBattle(model.Range);
 }
Ejemplo n.º 6
0
 public async Task <IActionResult> CreateBattle(int intiatorId, int opponentId)
 {
     return(Ok(await _battleService.CreateBattle(intiatorId, opponentId)));
 }