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)); }
public ShortWarInfoViewModel(Entities.War war, IWarService warService) { WarID = war.ID; StatusName = war.Active ? "On going" : "Finished"; Attacker = new ShortWarCountryInfoViewModel() { AllyCount = war.CountryInWars.Where(ciw => ciw.IsAttacker).Count(), Flag = Images.GetCountryFlag(war.Attacker.Entity.Name).VM, Name = war.Attacker.Entity.Name }; Defender = new ShortWarCountryInfoViewModel() { AllyCount = war.CountryInWars.Where(ciw => ciw.IsAttacker == false).Count(), Flag = Images.GetCountryFlag(war.Defender.Entity.Name).VM, Name = war.Defender.Entity.Name }; StartDay = war.StartDay; EndDay = war.EndDay; Duration = string.Format("{0} - {1}", war.StartDay, war.EndDay?.ToString() ?? "?"); var entity = SessionHelper.CurrentEntity; var operatedCountry = warService.GetControlledCountryInWar(entity, war); CanInitiateBattle = warService.CanStartBattle(entity, operatedCountry, war).isSuccess; CanInitiateSurrender = warService.CanSurrenderWar(war, entity).isSuccess; var warSide = warService.GetWarSide(war, SessionHelper.CurrentEntity); if (war.AttackerOfferedSurrender.HasValue == false && CanInitiateSurrender) { SurrenderText = "Send surrender offer"; } if (((war.AttackerOfferedSurrender == true && warSide == WarSideEnum.Defender) || (war.AttackerOfferedSurrender == false && warSide == WarSideEnum.Attacker)) && CanInitiateSurrender) { SurrenderText = "Accept surrender"; } else if (CanInitiateSurrender == false && war.AttackerOfferedSurrender.HasValue && warSide != WarSideEnum.None && war.Active) { ShowAfterSurrenderText = true; AfterSurrenderText = "Surrender sent"; CanInitiateBattle = false; } CanCancelSurrender = warService.CanCancelSurrender(war, SessionHelper.CurrentEntity).isSuccess; AttackerBattleWon = war.Battles.Where(b => b.Active == false && b.WonByAttacker == true).Count(); DefenderBattleWon = war.Battles.Where(b => b.Active == false && b.WonByAttacker == false).Count(); if (war.IsTrainingWar) { Attacker = new ShortWarCountryInfoViewModel() { AllyCount = 0, Flag = Images.Placeholder.VM, Name = "Chuck Norris" }; Defender = new ShortWarCountryInfoViewModel() { AllyCount = 0, Flag = Images.Placeholder.VM, Name = "Bruce Lee" }; CanCancelSurrender = CanInitiateBattle = CanInitiateSurrender = false; } }
public WarInfoViewModel(Entities.War war, IWarRepository warRepository, IWarService warService) { Info = new ShortWarInfoViewModel(war, warService); Active = war.Active; var countriesInWar = warRepository.GetCountriesInWar(war.ID); var countries = new { Attackers = countriesInWar. Where(ciw => ciw.IsAttacker) .Select(ciw => ciw.Country) .ToList(), Defenders = countriesInWar .Where(ciw => ciw.IsAttacker == false) .Select(ciw => ciw.Country) .ToList() }; IsRessistance = war.IsRessistanceWar; foreach (var attacker in countries.Attackers) { AttackerAllies.Add(new ShortWarCountryInfoViewModel(attacker)); } foreach (var defender in countries.Defenders) { DefendedAllies.Add(new ShortWarCountryInfoViewModel(defender)); } var entity = SessionHelper.CurrentEntity; var operatedCountry = warService.GetControlledCountryInWar(entity, war); CanInitiateBattle = warService.CanStartBattle(entity, operatedCountry, war).isSuccess; CanInitiateSurrender = warService.CanSurrenderWar(war, entity).isSuccess; if (Active) { WarStateText = "Active"; if (war.AttackerOfferedSurrender == true) { WarStateText = "Attacker offered surrender"; } else if (war.AttackerOfferedSurrender == false) { WarStateText = "Defender offered surrender"; } } else { WarStateText = "Inactive"; } var warSide = warService.GetWarSide(war, SessionHelper.CurrentEntity); if (war.AttackerOfferedSurrender.HasValue == false && CanInitiateSurrender) { SurrenderText = "Send surrender offer"; } if (((war.AttackerOfferedSurrender == true && warSide == WarSideEnum.Defender) || (war.AttackerOfferedSurrender == false && warSide == WarSideEnum.Attacker)) && CanInitiateSurrender) { SurrenderText = "Accept surrender"; } CanCancelSurrender = warService.CanCancelSurrender(war, SessionHelper.CurrentEntity).isSuccess; var attackerHero = warService.GetWarHero(war, true); var defenderHero = warService.GetWarHero(war, false); if (attackerHero != null) { AttackerHero = new ShortBattleParticipantViewModel(attackerHero); } if (defenderHero != null) { DefenderHero = new ShortBattleParticipantViewModel(defenderHero); } if (war.IsTrainingWar) { AttackerAllies = new List <ShortWarCountryInfoViewModel>(); DefendedAllies = new List <ShortWarCountryInfoViewModel>(); CanCancelSurrender = CanInitiateBattle = CanInitiateSurrender = false; } //testAddAllies(war); createMenu(); }