public void InAdventureScreen_InfoNotUpdatedUntilReset()
        {
            _data.InAdventureScreen = true;
            _data.MockDungeonInfo   = new[]
            {
                new MockDungeonInfo
                {
                    RunActive = true,
                    DbfIds    = new List <int> {
                        Backstab
                    },
                    LootA = new List <int> {
                        Category, DeadlyPoison
                    },
                    LootB = new List <int> {
                        Category, PitSnake
                    },
                    LootC = new List <int> {
                        Category, SinisterStrike
                    },
                    Treasure = new List <int> {
                        BattleTotem, PotionOfVitality, CrystalGem
                    },
                    PlayerChosenLoot     = 1,
                    PlayerChosenTreasure = 1
                },
                new MockDungeonInfo
                {
                    RunActive = false,
                }
            };

            _watcher.Update();
            Assert.IsNotNull(_info);

            _info = null;
            _watcher.Update();
            Assert.IsNull(_info);

            _watcher.Run();
            Thread.Sleep(130);
            Assert.IsNotNull(_info);
        }
Esempio n. 2
0
        private async void LoadingScreenParser_OnModeChanged(ModeChangedEventArgs args)
        {
            if (args.PreviousMode >= Mode.LOGIN && !_game.Account.IsLoaded)
            {
                _game.OnHearthstoneLoaded();
                var battleTag = await Retry(_gameData.GetBattleTag);

                var account = await Retry(_gameData.GetAccountId);

                if (battleTag != null && account != null)
                {
                    _game.Account.Update(account.Hi, account.Lo, battleTag.Name, battleTag.Number);
                    _game.Region = (BnetRegion)((account.Hi >> 32) & 0xFF);
                }
            }

            if (ShouldUpdateCollection(args.PreviousMode, args.PreviousMode))
            {
                var collection = await Retry(_gameData.GetFullCollection);

                if (collection != null)
                {
                    var cards = collection.Cards
                                .GroupBy(x => x.Id)
                                .Select(g => new CollectionCard(g.Key,
                                                                g.FirstOrDefault(x => !x.Premium)?.Count ?? 0,
                                                                g.FirstOrDefault(x => x.Premium)?.Count ?? 0
                                                                )).ToList();
                    var favoriteHeroes = collection.FavoriteHeroes.Values.Select(x =>
                                                                                 new CollectionCard(x.Id, x.Premium ? 0 : 1, x.Premium ? 1 : 0))
                                         .ToList();
                    _game.Collection.Update(cards, collection.CardBacks, favoriteHeroes,
                                            collection.FavoriteCardBack, collection.Dust, collection.Gold);
                }
            }

            if (args.CurrentMode == Mode.DRAFT)
            {
                _arenaWatcher.Run();
            }
            else
            {
                _arenaWatcher.Stop().Forget();
            }

            if (args.CurrentMode == Mode.PACKOPENING)
            {
                _packWatcher.Run();
            }
            else
            {
                _packWatcher.Stop().Forget();
            }

            if (args.CurrentMode == Mode.ADVENTURE || args.PreviousMode == Mode.ADVENTURE && args.CurrentMode == Mode.GAMEPLAY)
            {
                _dungeonRunWatcher.Run();
            }
            else
            {
                _dungeonRunWatcher.Stop().Forget();
            }

            if (args.CurrentMode == Mode.TAVERN_BRAWL)
            {
                var brawlInfo = _gameData.GetBrawlInfo();
                if (brawlInfo != null)
                {
                    _game.TavernBrawl.Update(brawlInfo);
                }
            }

            if (args.CurrentMode == Mode.FATAL_ERROR)
            {
                _game.OnHearthstoneExited();
            }
        }