private void initCanFight(Entities.Battle battle, IWarService warService) { bool canFight = SessionHelper.CurrentEntity.GetEntityType() == Entities.enums.EntityTypeEnum.Citizen && SessionHelper.CurrentEntity.Citizen.HitPoints > 5; if (canFight) { var fightingSide = warService.GetFightingSide(battle.War, SessionHelper.CurrentEntity.Citizen); if (fightingSide == Entities.enums.WarSideEnum.Attacker) { CanFightAsAttacker = true; } else if (fightingSide == Entities.enums.WarSideEnum.Defender) { CanFighstAsDefender = true; } else { if (battle.RegionID == SessionHelper.CurrentEntity.GetCurrentRegion().ID) { CanFighstAsDefender = CanFightAsAttacker = true; } } if (!battle.AttackerInitiatedBattle) { var att = CanFightAsAttacker; CanFightAsAttacker = CanFighstAsDefender; CanFighstAsDefender = att; } } }
private void initBasic(Entities.Battle battle) { WallHealth = (double)Math.Round(battle.WallHealth, 1); BattleID = battle.ID; RegionName = battle.Region.Name; StartDay = battle.StartDay; }
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)); }
public BattleViewModel(Entities.Battle battle, IBattleRepository battleRepository, IBattleService battleService, IWarRepository warRepository, IWarService warService) { Info = new WarInfoViewModel(battle.War, warRepository, warService); initBasic(battle); initCanFight(battle, warService); initTime(battle); IsActive = battle.Active; CanFight = (CanFighstAsDefender || CanFightAsAttacker) && IsActive && WaitingForResolve == false; if (IsActive == false) { AttackerWon = battle.WonByAttacker; GoldTaken = (double?)battle.GoldTaken; } addRealLastParticipants(battle); addDummiesIfNeeded(); AttackerInitiated = battle.AttackerInitiatedBattle; var attackerHero = battleService.GetBattleHero(battle, true); var defenderHero = battleService.GetBattleHero(battle, false); if (attackerHero != null) { AttackerHero = new ShortBattleParticipantViewModel(attackerHero); } if (defenderHero != null) { DefenderHero = new ShortBattleParticipantViewModel(defenderHero); } if (battle.War.IsTrainingWar) { CanFighstAsDefender = true; CanFight = SessionHelper.CurrentEntity.Is(EntityTypeEnum.Citizen); CanFightAsAttacker = true; RegionName = "Edge of the Earth"; TimeLeft = ""; WaitingForResolve = false; } if (CanFight) { AvailableWeaponQualities = battleService.GetUsableQualitiesOfWeapons(SessionHelper.LoggedCitizen); } AttackerName = Info.Info.Attacker.Name; DefenderName = Info.Info.Defender.Name; if (battle.AttackerInitiatedBattle == false) { AttackerName = Info.Info.Defender.Name; DefenderName = Info.Info.Attacker.Name; } }
private void initTime(Entities.Battle battle) { var timeLeft = TimeHelper.CalculateTimeLeft(battle.StartDay, GameHelper.CurrentDay, 1, battle.StartTime); if (timeLeft.TotalSeconds > 0) { TimeLeft = string.Format("{0:00}:{1:00}:{2:00}", Math.Floor(timeLeft.TotalHours), timeLeft.Minutes, timeLeft.Seconds); WaitingForResolve = false; } else { TimeLeft = "00:00:00"; WaitingForResolve = true; } }
private void addRealLastParticipants(Entities.Battle battle) { var lastAttackers = battle.BattleParticipants.Where(p => p.IsAttacker).OrderByDescending(p => p.ID).Take(5).ToList(); var lastDefenders = battle.BattleParticipants.Where(p => p.IsAttacker == false).OrderByDescending(p => p.ID).Take(5).ToList(); foreach (var attacker in lastAttackers) { AttackerBattleParticipants.Add(new ShortBattleParticipantViewModel(attacker)); } foreach (var defender in lastDefenders) { DefenderBattleParticipants.Add(new ShortBattleParticipantViewModel(defender)); } // AttackerBattleParticipants.Reverse(); //DefenderBattleParticipants.Reverse(); }
public SummaryBattleViewModel(Entities.Battle battle) { AttackerName = battle.War.Attacker.Entity.Name; DefenderName = battle.War.Defender.Entity.Name; AttackerImage = Images.GetCountryFlag(AttackerName).VM; DefenderImage = Images.GetCountryFlag(DefenderName).VM; WallHealth = (int)battle.WallHealth; RegionName = battle.Region.Name; BattleID = battle.ID; BattleStatus = battle.GetBattleStatus(); if (BattleStatus != BattleStatusEnum.OnGoing) { CanFight = false; } BattleStatusText = BattleStatus.ToHumanReadable(); var timeLeft = battle.GetTimeLeft(GameHelper.CurrentDay); if (timeLeft.TotalSeconds > 0) { TimeLeft = string.Format("{0:00}:{1:00}:{2:00}", Math.Floor(timeLeft.TotalHours), timeLeft.Minutes, timeLeft.Seconds); } else { CanFight = false; } if (battle.War.IsTrainingWar) { CanFight = true; AttackerImage = Images.Placeholder.VM; DefenderImage = AttackerImage; RegionName = "Edge of the Earth"; AttackerName = "Chuck Norris"; DefenderName = "Bruce Lee"; } }