Skip to content

Commit

Permalink
should fix issues regarding ranked/brawl matches not being recorded/a…
Browse files Browse the repository at this point in the history
…utomatically deleted shortly after (HearthSim#1631, HearthSim#1627)
  • Loading branch information
Epix37 committed Oct 26, 2015
1 parent f569c44 commit adf83c7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
23 changes: 17 additions & 6 deletions Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void HandlePossibleArenaCard(string id)
_game.PossibleArenaCards.Add(card);
}

public void HandleInMenu()
public async void HandleInMenu()
{
if (_game.IsInMenu)
return;
Expand All @@ -128,6 +128,19 @@ public void HandleInMenu()
Core.Overlay.HideTimers();
Core.Overlay.HideSecrets();

if(_game.CurrentGameMode == GameMode.None)
{
Logger.WriteLine("Waiting for game mode detection...", "HandleInMenu");
await _game.GameModeDetection();
Logger.WriteLine("Detected game mode, continuing.", "HandleInMenu");
}
if(_game.CurrentGameMode == GameMode.Casual)
{
Logger.WriteLine("CurrentGameMode=Casual, Waiting for ranked detection...", "HandleInMenu");
await LogReaderManager.RankedDetection();
Logger.WriteLine("Done waiting for ranked detection, continuing.", "HandleInMenu");
}

if (Config.Instance.RecordReplays && _game.Entities.Count > 0 && !_game.SavedReplay && _game.CurrentGameStats != null
&& _game.CurrentGameStats.ReplayFile == null && RecordCurrentGameMode)
_game.CurrentGameStats.ReplayFile = ReplayMaker.SaveToDisk();
Expand Down Expand Up @@ -515,12 +528,12 @@ public async void HandleGameEnd()
if (_game.CurrentGameMode == GameMode.None)
{
Logger.WriteLine("Waiting for game mode detection...", "HandleGameEnd");
await _game.GameModeDetection(300); //give the user 5 minutes to get out of the victory/defeat screen
await _game.GameModeDetection();
Logger.WriteLine("Detected game mode, continuing.", "HandleGameEnd");
}
if(_game.CurrentGameMode == GameMode.Casual)
{
Logger.WriteLine("CurrentGameMode=None, Waiting for ranked detection...", "HandleGameEnd");
Logger.WriteLine("CurrentGameMode=Casual, Waiting for ranked detection...", "HandleGameEnd");
await LogReaderManager.RankedDetection();
Logger.WriteLine("Done waiting for ranked detection, continuing.", "HandleGameEnd");
}
Expand All @@ -535,9 +548,7 @@ public async void HandleGameEnd()
Logger.WriteLine("Game mode was saved, continuing.", "HandleGameEnd");
if (_game.CurrentGameMode == GameMode.Arena)
HearthStatsManager.UploadArenaMatchAsync(_lastGame, selectedDeck, background: true);
else if (_game.CurrentGameMode == GameMode.Brawl)
{ /* do nothing */ }
else
else if (_game.CurrentGameMode != GameMode.Brawl)
HearthStatsManager.UploadMatchAsync(_lastGame, selectedDeck, background: true);
}
_lastGame = null;
Expand Down
14 changes: 13 additions & 1 deletion Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void Reset(bool resetStats = true)
if(CurrentGameMode != GameMode.Spectator)
CurrentGameMode = GameMode.None;
CurrentGameStats = new GameStats(GameResult.None, "", "") {PlayerName = "", OpponentName = "", Region = CurrentRegion};
_gameModeDetectionComplete = false;
}
_hsLogLines = new List<string>();

Expand Down Expand Up @@ -153,12 +154,23 @@ public void ResetConstructedCards()
PossibleConstructedCards.Clear();
}

public async Task GameModeDetection(int timeoutInSeconds)
private bool _gameModeDetectionRunning;
private bool _gameModeDetectionComplete;
public async Task GameModeDetection(int timeoutInSeconds = 300)
{
if(_gameModeDetectionRunning || _gameModeDetectionComplete)
{
while(!_gameModeDetectionComplete)
await Task.Delay(100);
return;
}
_gameModeDetectionRunning = true;
var startTime = DateTime.Now;
var timeout = TimeSpan.FromSeconds(timeoutInSeconds);
while(CurrentGameMode == GameMode.None && (DateTime.Now - startTime) < timeout)
await Task.Delay(100);
_gameModeDetectionComplete = true;
_gameModeDetectionRunning = false;
}

public void NewArenaDeck(string heroId)
Expand Down
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker/LogReader/HsGameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class HsGameState : IHsGameState
public bool FoundSpectatorStart { get; set; }
public int JoustReveals { get; set; }
public Dictionary<int, string> KnownCardIds { get; set; }
public bool RankedDetectionComplete { get; set; }

public HsGameState(GameV2 game)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IHsGameState
{
int AddToTurn { get; set; }
bool AwaitingRankedDetection { get; set; }
bool RankedDetectionComplete { get; set; }
bool CurrentEntityHasCardId { get; set; }
int CurrentEntityId { get; set; }
long CurrentOffset { get; set; }
Expand Down
12 changes: 12 additions & 0 deletions Hearthstone Deck Tracker/LogReader/LogReaderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,18 @@ public static int GetTurnNumber()
return _gameState.GetTurnNumber();
}

public static void ResetRankedDetection()
{
_gameState.RankedDetectionComplete = false;
}
public static async Task<bool> RankedDetection(int timeoutInSeconds = 3)
{
if(_gameState.AwaitingRankedDetection || _gameState.RankedDetectionComplete)
{
while(!_gameState.RankedDetectionComplete)
await Task.Delay(100);
return _gameState.FoundRanked;
}
_gameState.AwaitingRankedDetection = true;
_gameState.WaitingForFirstAssetUnload = true;
_gameState.FoundRanked = false;
Expand All @@ -104,6 +114,8 @@ public static async Task<bool> RankedDetection(int timeoutInSeconds = 3)
if(_gameState.FoundRanked)
break;
}
_gameState.RankedDetectionComplete = true;
_gameState.AwaitingRankedDetection = false;
return _gameState.FoundRanked;
}

Expand Down

0 comments on commit adf83c7

Please sign in to comment.