Skip to content

Commit

Permalink
implement game mode detection (except ranked and spectator) via Loadi…
Browse files Browse the repository at this point in the history
…ngScreen log (HearthSim#1653)
  • Loading branch information
Alexander Zeier committed Nov 23, 2015
1 parent 493d930 commit f3a5975
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 21 deletions.
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<Compile Include="Exporting\HueAndBrightness.cs" />
<Compile Include="Hearthstone\GameTime.cs" />
<Compile Include="Hearthstone\HearthDbConverter.cs" />
<Compile Include="LogReader\Handlers\LoadingScreenHandler.cs" />
<Compile Include="Stats\CompiledStats\ArenaRun.cs" />
<Compile Include="Stats\CompiledStats\ChartStats.cs" />
<Compile Include="Stats\CompiledStats\ClassStats.cs" />
Expand Down
14 changes: 10 additions & 4 deletions Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ public GameMode CurrentGameMode
get { return _currentGameMode; }
set
{
_currentGameMode = value;
Logger.WriteLine("Set CurrentGameMode to " + value, "Game");
if(_currentGameMode != value)
{
_currentGameMode = value;
Logger.WriteLine("Set CurrentGameMode to " + value, "Game");
}
}
}

Expand All @@ -131,8 +134,11 @@ public void Reset(bool resetStats = true)

if(!IsInMenu && resetStats)
{
if(CurrentGameMode != GameMode.Spectator)
CurrentGameMode = GameMode.None;
if(CurrentGameMode == GameMode.Ranked)
{
Logger.WriteLine("Resetting gamemode to casual", "Game");
CurrentGameMode = GameMode.Casual;
}
CurrentGameStats = new GameStats(GameResult.None, "", "") {PlayerName = "", OpponentName = "", Region = CurrentRegion};
_gameModeDetectionComplete = false;
}
Expand Down
4 changes: 0 additions & 4 deletions Hearthstone Deck Tracker/LogReader/Handlers/AssetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public void Handle(string logLine, IHsGameState gameState, IGame game)
else
gameState.GameHandler.HandlePossibleConstructedCard(id, true);
}
else if (HsLogReaderConstants.UnloadBrawlAsset.IsMatch(logLine))
{
gameState.GameHandler.SetGameMode(GameMode.Brawl);
}
}
}
}
11 changes: 0 additions & 11 deletions Hearthstone Deck Tracker/LogReader/Handlers/BobHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,11 @@ public void Handle(string logLine, IHsGameState gameState, IGame game)
gameState.GameEnd();
}
else if(logLine.Contains("---RegisterScreenForge---"))
{
gameState.GameHandler.SetGameMode(GameMode.Arena);
game.ResetArenaCards();
}
else if(logLine.Contains("---RegisterScreenPractice---"))
gameState.GameHandler.SetGameMode(GameMode.Practice);
else if(logLine.Contains("---RegisterScreenTourneys---"))
gameState.GameHandler.SetGameMode(GameMode.Casual);
else if(logLine.Contains("---RegisterScreenFriendly---"))
gameState.GameHandler.SetGameMode(GameMode.Friendly);
else if(logLine.Contains("---RegisterProfileNotices---"))
gameState.GameLoaded = true;
else if(logLine.Contains("---RegisterFriendChallenge---"))
{
gameState.GameHandler.HandleInMenu();
}
else if(logLine.Contains("---RegisterScreenCollectionManager---"))
gameState.GameHandler.ResetConstructedImporting();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#region

using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.LogReader.Interfaces;

#endregion

namespace Hearthstone_Deck_Tracker.LogReader.Handlers
{
class LoadingScreenHandler
{
public void Handle(string logLine, IHsGameState gameState, IGame game)
{
var match = HsLogReaderConstants.GameModeRegex.Match(logLine);
if(match.Success)
{
var newMode = GetGameMode(match.Groups["curr"].Value) ?? GetGameMode(match.Groups["prev"].Value);
if(newMode.HasValue && !(game.CurrentGameMode == GameMode.Ranked && newMode.Value == GameMode.Casual))
game.CurrentGameMode = newMode.Value;
}
}

private GameMode? GetGameMode(string mode)
{
switch(mode)
{
case "ADVENTURE":
return GameMode.Practice;
case "TAVERN_BRAWL":
return GameMode.Brawl;
case "TOURNAMENT":
return GameMode.Casual;
case "DRAFT":
return GameMode.Arena;
case "FRIENDLY":
return GameMode.Friendly;
default:
return null;
}
}
}
}
8 changes: 7 additions & 1 deletion Hearthstone Deck Tracker/LogReader/HsLogReaderConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static class PowerTaskList
public static readonly Regex ExistingHeroRegex = new Regex(@"Draft Deck ID: .*, Hero Card = (?<id>(HERO_\w+))");
public static readonly Regex ExistingCardRegex = new Regex(@"Draft deck contains card (?<id>(\w+))");
public static readonly Regex NewChoiceRegex = new Regex(@"Client chooses: .* \((?<id>(.+))\)");
public static readonly Regex GameModeRegex = new Regex(@"prevMode=(?<prev>(\w+)).*currMode=(?<curr>(\w+))");

public static LogReaderInfo PowerLogReaderInfo
{
Expand All @@ -68,5 +69,10 @@ public static LogReaderInfo ArenaLogReaderInfo
{
get { return new LogReaderInfo { Name = "Arena" }; }
}
}

public static LogReaderInfo LoadingScreenLogReaderInfo
{
get { return new LogReaderInfo {Name = "LoadingScreen", StartsWithFilters = new[] {"LoadingScreen.OnSceneLoaded"}}; }
}
}
}
5 changes: 5 additions & 0 deletions Hearthstone Deck Tracker/LogReader/LogReaderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class LogReaderManager
private static readonly ZoneHandler ZoneHandler = new ZoneHandler();
private static readonly BobHandler BobHandler = new BobHandler();
private static readonly ArenaHandler ArenaHandler = new ArenaHandler();
private static readonly LoadingScreenHandler LoadingScreenHandler = new LoadingScreenHandler();
private static LogReader _powerLogReader;
private static LogReader _bobLogReader;
private static HsGameState _gameState;
Expand All @@ -39,6 +40,7 @@ private static void InitializeLogReaders()
LogReaders.Add(new LogReader(HsLogReaderConstants.RachelleLogReaderInfo));
LogReaders.Add(new LogReader(HsLogReaderConstants.AssetLogReaderInfo));
LogReaders.Add(new LogReader(HsLogReaderConstants.ArenaLogReaderInfo));
LogReaders.Add(new LogReader(HsLogReaderConstants.LoadingScreenLogReaderInfo));
}

public static void Start(GameV2 game)
Expand Down Expand Up @@ -182,6 +184,9 @@ private static void ProcessNewLines()
ArenaHandler.Handle(line.Line, _gameState, _game);
API.LogEvents.OnArenaLogLine.Execute(line.Line);
break;
case "LoadingScreen":
LoadingScreenHandler.Handle(line.Line, _gameState, _game);
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Utility/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private static bool UpdateLogConfigFile()
//check for log config and create if not existing
try
{
var requiredLogs = new[] { "Zone", "Bob", "Power", "Asset", "Rachelle", "Arena", "Achievements" };
var requiredLogs = new[] { "Zone", "Bob", "Power", "Asset", "Rachelle", "Arena", "Achievements", "LoadingScreen" };

var logConfig = new LogConfig();
if (File.Exists(LogConfigPath))
Expand Down

0 comments on commit f3a5975

Please sign in to comment.