Exemple #1
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));
        }
Exemple #2
0
        public ActionResult StartBattle(int warID)
        {
            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 vm = new StartBattleViewModel(war, warRepository, warService);

            return(View(vm));
        }