Esempio n. 1
0
        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;
            }
        }