Ejemplo n.º 1
0
        /// <summary>Handles the message.</summary>
        /// <param name="message">The message.</param>
        public void Handle(GameStarted message)
        {
            EnsureInitialized();
            GameMode     = message.GameMode;
            Hero         = Heroes.FirstOrDefault(x => x.Key == message.Hero);
            OpponentHero = Heroes.FirstOrDefault(x => x.Key == message.OpponentHero);
            GoFirst      = message.GoFirst;
            StartTime    = message.StartTime;
            IsRunning    = true;
            Deck         = deckManager.GetOrCreateDeckBySlot(BindableServerCollection.Instance.DefaultName, message.Deck);
            events.PublishOnBackgroundThread(new ToggleFlyoutCommand(Flyouts.CurrentGame)
            {
                Show = true
            });
            events.PublishOnBackgroundThread(new ToggleFlyoutCommand(Flyouts.EditGame)
            {
                Show = false
            });
            var vm = IoC.Get <GameStartedBalloonViewModel>();

            vm.SetGameResult(message);
            events.PublishOnBackgroundThread(new TrayNotification("A new game has started", vm, 10000)
            {
                BalloonType = BalloonTypes.GameStartEnd
            });
            RefreshStats();
        }
Ejemplo n.º 2
0
        private void UpdateVillageHeroes(CocApi cocApi, VillageApiModel downloadedVillage)
        {
            List <TroopApiModel> newTroops = new List <TroopApiModel>();

            foreach (TroopApiModel troop in downloadedVillage.Heroes.EmptyIfNull())
            {
                TroopApiModel?oldTroop = Heroes.FirstOrDefault(t => t.Name == troop.Name);

                if (oldTroop == null || oldTroop.Level < troop.Level)
                {
                    newTroops.Add(troop);
                }
            }

            if (newTroops.Count() > 0)
            {
                cocApi.VillageHeroesChangedEvent(this, newTroops);

                //Heroes = downloadedVillage.Heroes;
            }
        }
Ejemplo n.º 3
0
        /// <summary>Handles the message.</summary>
        /// <param name="message">The message.</param>
        public async Task Handle(GameEnded message)
        {
            events.PublishOnBackgroundThread(new ResetCurrentGame());

            // TODO: do not override if manually set.
            GameMode  = message.GameMode;
            StartTime = message.StartTime;

            if (!string.IsNullOrWhiteSpace(message.Hero))
            {
                Hero = Heroes.FirstOrDefault(x => x.Key == message.Hero);
            }

            if (!string.IsNullOrWhiteSpace(message.OpponentHero))
            {
                OpponentHero = Heroes.FirstOrDefault(x => x.Key == message.OpponentHero);
            }

            if (message.GoFirst.HasValue)
            {
                GoFirst = message.GoFirst.Value;
            }

            IsRunning = false;
            Turns     = message.Turns;

            GameMode = message.GameMode;
            Conceded = message.Conceded;

            GoFirst      = !message.GoFirst.HasValue || message.GoFirst.Value;
            Hero         = Heroes.FirstOrDefault(x => x.Key == message.Hero);
            OpponentHero = Heroes.FirstOrDefault(x => x.Key == message.OpponentHero);
            Started      = message.StartTime;
            Stopped      = message.EndTime;
            Victory      = message.Victory.HasValue && message.Victory.Value;
            Deck         = deckManager.GetOrCreateDeckBySlot(BindableServerCollection.Instance.DefaultName, message.Deck);

            await Save();
        }
Ejemplo n.º 4
0
 public MainViewModel()
 {
     Heroes      = HeroesRepository.GetAllHeroes();
     CurrentHero = Heroes.FirstOrDefault();
 }
Ejemplo n.º 5
0
 public Hero LookupHero(Tile tile)
 {
     return(Heroes.FirstOrDefault(x => x.ID == tile.OwnerId));
 }
Ejemplo n.º 6
0
 public int?HeroLevelOrDefault(string name) => Heroes.FirstOrDefault(h => h.Name == name)?.Level;