Exemple #1
0
        public void HandleGameStart(DateTime timestamp)
        {
            if (_game.CurrentGameMode == Practice && !_game.IsInMenu && !_handledGameEnd &&
                _lastGameStartTimestamp > DateTime.MinValue && timestamp > _lastGameStartTimestamp)
            {
                HandleAdventureRestart();
            }
            _lastGameStartTimestamp = timestamp;
            if (DateTime.Now - _lastGameStart < new TimeSpan(0, 0, 0, 5))            //game already started
            {
                return;
            }
            _handledGameEnd = false;
            _lastGameStart  = DateTime.Now;
            Log.Info("--- Game start ---");

            if (Config.Instance.FlashHsOnTurnStart)
            {
                User32.FlashHs();
            }
            if (Config.Instance.BringHsToForeground)
            {
                User32.BringHsToForeground();
            }
            _lastTurnStart[0]  = _lastTurnStart[1] = 0;
            _arenaRewardDialog = null;
            _showedNoteDialog  = false;
            _game.IsInMenu     = false;
            _savedReplay       = false;
            _game.Reset();
            _game.CacheMatchInfo();
            _game.CacheGameType();
            _game.CacheSpectator();
            _game.MetaData.ServerInfo = Reflection.GetServerInfo();
            if (!string.IsNullOrEmpty(_game.MetaData.ServerInfo?.Address))
            {
                var region = Helper.GetRegionByServerIp(_game.MetaData.ServerInfo.Address);
                if (_game.CurrentRegion == Region.UNKNOWN || region == Region.CHINA)
                {
                    _game.CurrentRegion = region;
                    Log.Info("Set current region to" + region);
                }
            }
            TurnTimer.Instance.Start(_game).Forget();

            var selectedDeck = DeckList.Instance.ActiveDeckVersion;

            if (selectedDeck != null)
            {
                _game.IsUsingPremade = true;
            }
            Core.Windows.CapturableOverlay?.UpdateContentVisibility();
            GameEvents.OnGameStart.Execute();
            LiveDataManager.WatchBoardState();
        }
Exemple #2
0
 [Route("inputdata/refreshsampleandkernel")] // diag
 public async Task <ApiResult> RefreshInputDataAndKernel([FromBody] JObject jObject)
 {
     try
     {
         RolesCheck.EnsureWriter(Request);
         LiveDataManager ldm = new LiveDataManager(_logger, _configuration);
         return(await ldm.RefreshInputDataAndKernel(jObject));
     }
     catch (Exception e)
     {
         _logger.LogError(e, e.Message);
         return(ApiResult.CreateError(e.Message));
     }
 }
        public void HandleGameStart(DateTime timestamp)
        {
            if (_game.CurrentGameMode == Practice && !_game.IsInMenu && !_handledGameEnd &&
                _lastGameStartTimestamp > DateTime.MinValue && timestamp > _lastGameStartTimestamp)
            {
                HandleAdventureRestart();
            }
            _lastGameStartTimestamp = timestamp;
            if (DateTime.Now - _lastGameStart < new TimeSpan(0, 0, 0, 5))            //game already started
            {
                return;
            }
            _handledGameEnd = false;
            _lastGameStart  = DateTime.Now;
            Log.Info("--- Game start ---");

            switch (Config.Instance.TurnStartAction)
            {
            case HsActionType.Flash:
                User32.FlashHs();
                break;

            case HsActionType.Popup:
                User32.BringHsToForeground();
                break;
            }
            _lastTurnStart[0]  = _lastTurnStart[1] = 0;
            _arenaRewardDialog = null;
            _showedNoteDialog  = false;
            _game.IsInMenu     = false;
            _savedReplay       = false;
            _game.Reset();
            _game.CacheMatchInfo();
            _game.CacheGameType();
            _game.CacheSpectator();
            _game.MetaData.ServerInfo = Reflection.GetServerInfo();
            TurnTimer.Instance.Start(_game).Forget();

            var selectedDeck = DeckList.Instance.ActiveDeckVersion;

            if (selectedDeck != null)
            {
                _game.IsUsingPremade = true;
            }
            Core.Windows.CapturableOverlay?.UpdateContentVisibility();
            GameEvents.OnGameStart.Execute();
            LiveDataManager.WatchBoardState();
        }
 public MapManager(LiveDataManager liveDataManager, SymbolsManager symbolsManager, Config config, IEventAggregator eventAggregator, IPageDialogService dialogService, GeolocationManager geolocationManager)
 {
     _vehiculesLayer = new GraphicsOverlay
     {
         MinScale = config.Map.VehiculesLayerMinScale
     };
     _liveDataManager = liveDataManager;
     _liveDataManager.DataUpdateAvailable   += OnDataUpdateAvailable;
     _liveDataManager.VehiculeLimitExceeded += OnVehiculeLimitExceeded;
     _liveDataManager.DataTimeout           += OnDataTimeout;
     _symbolsManager     = symbolsManager;
     _symbolsCache       = new Dictionary <string, PictureMarkerSymbol>();
     _config             = config;
     _eventAggregator    = eventAggregator;
     _dialogService      = dialogService;
     _geolocationManager = geolocationManager;
     Lignes = new LigneSens[0];
 }
Exemple #5
0
#pragma warning disable 4014
        public async void HandleGameEnd()
        {
            try
            {
                if (_game.CurrentGameStats == null || _handledGameEnd)
                {
                    Log.Warn("HandleGameEnd was already called.");
                    return;
                }
                _handledGameEnd = true;
                TurnTimer.Instance.Stop();
                Core.Overlay.HideTimers();
                DeckManager.ResetAutoSelectCount();
                LiveDataManager.Stop();
                Log.Info("Game ended...");
                _game.InvalidateMatchInfoCache();
                if (_game.CurrentGameMode == Spectator && _game.CurrentGameStats.Result == GameResult.None)
                {
                    Log.Info("Game was spectator mode without a game result. Probably exited spectator mode early.");
                    return;
                }
                var player   = _game.Entities.FirstOrDefault(e => e.Value?.IsPlayer ?? false).Value;
                var opponent = _game.Entities.FirstOrDefault(e => e.Value != null && e.Value.HasTag(PLAYER_ID) && !e.Value.IsPlayer).Value;
                if (player != null)
                {
                    _game.CurrentGameStats.PlayerName = player.Name;
                    _game.CurrentGameStats.Coin       = !player.HasTag(FIRST_PLAYER);
                }
                if (opponent != null && CardIds.HeroIdDict.ContainsValue(_game.CurrentGameStats.OpponentHero))
                {
                    _game.CurrentGameStats.OpponentName = opponent.Name;
                }
                else
                {
                    _game.CurrentGameStats.OpponentName = _game.CurrentGameStats.OpponentHero;
                }

                _game.CurrentGameStats.Turns = _game.GetTurnNumber();
                if (Config.Instance.DiscardZeroTurnGame && _game.CurrentGameStats.Turns < 1)
                {
                    Log.Info("Game has 0 turns, discarded. (DiscardZeroTurnGame)");
                    _assignedDeck = null;
                    GameEvents.OnGameEnd.Execute();
                    return;
                }
                _game.CurrentGameStats.GameMode = _game.CurrentGameMode;
                _game.CurrentGameStats.Format   = _game.CurrentFormat;
                Log.Info("Format: " + _game.CurrentGameStats.Format);
                if (_game.CurrentGameMode == Ranked && _game.MatchInfo != null)
                {
                    var wild = _game.CurrentFormat == Format.Wild;
                    _game.CurrentGameStats.Rank               = wild ? _game.MatchInfo.LocalPlayer.WildRank : _game.MatchInfo.LocalPlayer.StandardRank;
                    _game.CurrentGameStats.OpponentRank       = wild ? _game.MatchInfo.OpposingPlayer.WildRank : _game.MatchInfo.OpposingPlayer.StandardRank;
                    _game.CurrentGameStats.LegendRank         = wild ? _game.MatchInfo.LocalPlayer.WildLegendRank : _game.MatchInfo.LocalPlayer.StandardLegendRank;
                    _game.CurrentGameStats.OpponentLegendRank = wild ? _game.MatchInfo.OpposingPlayer.WildLegendRank : _game.MatchInfo.OpposingPlayer.StandardLegendRank;
                    _game.CurrentGameStats.Stars              = wild ? _game.MatchInfo.LocalPlayer.WildStars : _game.MatchInfo.LocalPlayer.StandardStars;
                }
                else if (_game.CurrentGameMode == Arena)
                {
                    _game.CurrentGameStats.ArenaWins   = DeckImporter.ArenaInfoCache?.Wins ?? 0;
                    _game.CurrentGameStats.ArenaLosses = DeckImporter.ArenaInfoCache?.Losses ?? 0;
                }
                else if (_game.CurrentGameMode == Brawl && _game.BrawlInfo != null)
                {
                    _game.CurrentGameStats.BrawlWins   = _game.BrawlInfo.Wins;
                    _game.CurrentGameStats.BrawlLosses = _game.BrawlInfo.Losses;
                }
                _game.CurrentGameStats.GameType           = _game.CurrentGameType;
                _game.CurrentGameStats.ServerInfo         = _game.MetaData.ServerInfo;
                _game.CurrentGameStats.PlayerCardbackId   = _game.MatchInfo?.LocalPlayer.CardBackId ?? 0;
                _game.CurrentGameStats.OpponentCardbackId = _game.MatchInfo?.OpposingPlayer.CardBackId ?? 0;
                _game.CurrentGameStats.FriendlyPlayerId   = _game.MatchInfo?.LocalPlayer.Id ?? 0;
                _game.CurrentGameStats.ScenarioId         = _game.MatchInfo?.MissionId ?? 0;
                _game.CurrentGameStats.BrawlSeasonId      = _game.MatchInfo?.BrawlSeasonId ?? 0;
                _game.CurrentGameStats.RankedSeasonId     = _game.MatchInfo?.RankedSeasonId ?? 0;
                var confirmedCards = _game.Player.RevealedCards.Where(x => x.Collectible)
                                     .Concat(_game.Player.KnownCardsInDeck.Where(x => x.Collectible && !x.IsCreated))
                                     .ToList();
                if (_game.CurrentSelectedDeck != null && _game.CurrentSelectedDeck.Id > 0)
                {
                    _game.CurrentGameStats.HsDeckId = _game.CurrentSelectedDeck.Id;
                    _game.CurrentGameStats.SetPlayerCards(_game.CurrentSelectedDeck, confirmedCards);
                }
                else
                {
                    _game.CurrentGameStats.HsDeckId = DeckList.Instance.ActiveDeckVersion?.HsId ?? 0;
                    _game.CurrentGameStats.SetPlayerCards(DeckList.Instance.ActiveDeckVersion, confirmedCards);
                }
                _game.CurrentGameStats.SetOpponentCards(_game.Opponent.OpponentCardList.Where(x => !x.IsCreated).ToList());
                _game.CurrentGameStats.GameEnd();
                GameEvents.OnGameEnd.Execute();
                _game.CurrentSelectedDeck = null;
                var selectedDeck = DeckList.Instance.ActiveDeck;
                if (selectedDeck != null)
                {
                    var revealed = _game.Player.RevealedEntities.Where(x => x != null).ToList();
                    if (Config.Instance.DiscardGameIfIncorrectDeck &&
                        !revealed.Where(x => x.IsPlayableCard && !x.Info.Created && !x.Info.Stolen && x.Card.Collectible)
                        .GroupBy(x => x.CardId).All(x => selectedDeck.GetSelectedDeckVersion().Cards.Any(c2 => x.Key == c2.Id && x.Count() <= c2.Count)))
                    {
                        if (Config.Instance.AskBeforeDiscardingGame)
                        {
                            var discardDialog = new DiscardGameDialog(_game.CurrentGameStats)
                            {
                                Topmost = true
                            };
                            discardDialog.ShowDialog();
                            if (discardDialog.Result == DiscardGameDialogResult.Discard)
                            {
                                Log.Info("Assigned current game to NO deck - selected deck does not match cards played (dialogresult: discard)");
                                _assignedDeck = null;
                                return;
                            }
                            if (discardDialog.Result == DiscardGameDialogResult.MoveToOther)
                            {
                                var moveDialog = new MoveGameDialog(DeckList.Instance.Decks.Where(d => d.Class == _game.CurrentGameStats.PlayerHero))
                                {
                                    Topmost = true
                                };
                                moveDialog.ShowDialog();
                                var targetDeck = moveDialog.SelectedDeck;
                                if (targetDeck != null)
                                {
                                    selectedDeck = targetDeck;
                                    _game.CurrentGameStats.PlayerDeckVersion = moveDialog.SelectedVersion;
                                    //...continue as normal
                                }
                                else
                                {
                                    Log.Info("No deck selected in move game dialog after discard dialog, discarding game");
                                    _assignedDeck = null;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            Log.Info("Assigned current game to NO deck - selected deck does not match cards played (no dialog)");
                            _assignedDeck = null;
                            return;
                        }
                    }
                    else
                    {
                        _game.CurrentGameStats.PlayerDeckVersion = selectedDeck.GetSelectedDeckVersion().Version;
                    }

                    _lastGame = _game.CurrentGameStats;
                    selectedDeck.DeckStats.AddGameResult(_lastGame);

                    if (Config.Instance.ArenaRewardDialog && (selectedDeck.IsArenaRunCompleted ?? false))
                    {
                        if (selectedDeck.ArenaReward.Packs[0] == ArenaRewardPacks.None)
                        {
                            selectedDeck.ArenaReward.Packs[0] = Enum.GetValues(typeof(ArenaRewardPacks)).OfType <ArenaRewardPacks>().Max();
                        }

                        _arenaRewardDialog = new ArenaRewardDialog(selectedDeck);
                    }
                    if (Config.Instance.ShowNoteDialogAfterGame && !Config.Instance.NoteDialogDelayed && !_showedNoteDialog)
                    {
                        _showedNoteDialog = true;
                        new NoteDialog(_game.CurrentGameStats);
                    }
                    Log.Info("Assigned current game to deck: " + selectedDeck.Name);
                    _assignedDeck = selectedDeck;

                    // Unarchive the active deck after we have played a game with it
                    if (_assignedDeck.Archived)
                    {
                        Log.Info("Automatically unarchiving deck " + selectedDeck.Name + " after assigning current game");
                        Core.MainWindow.ArchiveDeck(_assignedDeck, false);
                    }
                    _lastGame = null;
                }
                else
                {
                    try
                    {
                        DefaultDeckStats.Instance.GetDeckStats(_game.Player.Class).AddGameResult(_game.CurrentGameStats);
                        Log.Info($"Assigned current deck to default {_game.Player.Class} deck.");
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error saving to DefaultDeckStats: " + ex);
                    }
                    _assignedDeck = null;
                }

                if (_game.StoredGameStats != null)
                {
                    _game.CurrentGameStats.StartTime = _game.StoredGameStats.StartTime;
                }

                await SaveReplays();

                if (Config.Instance.ShowGameResultNotifications && RecordCurrentGameMode)
                {
                    var deckName = _assignedDeck == null ? "No deck - " + _game.CurrentGameStats.PlayerHero : _assignedDeck.NameAndVersion;
                    ToastManager.ShowGameResultToast(deckName, _game.CurrentGameStats);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
        private async void Window_Closing(object sender, CancelEventArgs e)
        {
            if (!ExitRequestedFromTray && Config.Instance.CloseToTray)
            {
                MinimizeToTray();
                e.Cancel = true;
                return;
            }

            try
            {
                Log.Info("Shutting down...");
                Influx.OnAppExit(Helper.GetCurrentVersion());
                LiveDataManager.Stop();
                Core.UpdateOverlay = false;
                Core.Update        = false;

                //wait for update to finish, might otherwise crash when overlay gets disposed
                for (var i = 0; i < 100; i++)
                {
                    if (Core.CanShutdown)
                    {
                        break;
                    }
                    await Task.Delay(50);
                }

                Config.Instance.SelectedTags = Config.Instance.SelectedTags.Distinct().ToList();
                //Config.Instance.ShowAllDecks = DeckPickerList.ShowAll;
                Config.Instance.SelectedDeckPickerClasses = DeckPickerList.SelectedClasses.ToArray();

                Config.Instance.WindowWidth       = (int)Width;
                Config.Instance.WindowHeight      = (int)(Height - _heightChangeDueToSearchBox);
                Config.Instance.TrackerWindowTop  = (int)Top;
                Config.Instance.TrackerWindowLeft = (int)Left;

                //position of add. windows is NaN if they were never opened.
                if (!double.IsNaN(Core.Windows.PlayerWindow.Left))
                {
                    Config.Instance.PlayerWindowLeft = (int)Core.Windows.PlayerWindow.Left;
                }
                if (!double.IsNaN(Core.Windows.PlayerWindow.Top))
                {
                    Config.Instance.PlayerWindowTop = (int)Core.Windows.PlayerWindow.Top;
                }
                Config.Instance.PlayerWindowHeight = (int)Core.Windows.PlayerWindow.Height;

                if (!double.IsNaN(Core.Windows.OpponentWindow.Left))
                {
                    Config.Instance.OpponentWindowLeft = (int)Core.Windows.OpponentWindow.Left;
                }
                if (!double.IsNaN(Core.Windows.OpponentWindow.Top))
                {
                    Config.Instance.OpponentWindowTop = (int)Core.Windows.OpponentWindow.Top;
                }
                Config.Instance.OpponentWindowHeight = (int)Core.Windows.OpponentWindow.Height;

                if (!double.IsNaN(Core.Windows.TimerWindow.Left))
                {
                    Config.Instance.TimerWindowLeft = (int)Core.Windows.TimerWindow.Left;
                }
                if (!double.IsNaN(Core.Windows.TimerWindow.Top))
                {
                    Config.Instance.TimerWindowTop = (int)Core.Windows.TimerWindow.Top;
                }
                Config.Instance.TimerWindowHeight = (int)Core.Windows.TimerWindow.Height;
                Config.Instance.TimerWindowWidth  = (int)Core.Windows.TimerWindow.Width;

                Core.TrayIcon.NotifyIcon.Visible = false;
                Core.Overlay.Close();
                await Core.StopLogWacher();

                Core.Windows.TimerWindow.Shutdown();
                Core.Windows.PlayerWindow.Shutdown();
                Core.Windows.OpponentWindow.Shutdown();
                Config.Save();
                DeckList.Save();
                DeckStatsList.Save();
                PluginManager.SavePluginsSettings();
                PluginManager.Instance.UnloadPlugins();
            }
            catch (Exception)
            {
                //doesnt matter
            }
            finally
            {
                Application.Current.Shutdown();
            }
        }