@@ -9,7 +9,7 @@ namespace OpponentMemory
99{
1010 public sealed class OpponentMemoryPlugin : IPlugin
1111 {
12- public const string DisplayVersion = "1.1 " ;
12+ public const string DisplayVersion = "1.2 " ;
1313 private readonly EncounterTracker _tracker = new EncounterTracker ( ) ;
1414 private readonly BattlegroundsPlayerResolver _resolver = new BattlegroundsPlayerResolver ( ) ;
1515 private readonly OpponentMemoryOverlay _overlay = new OpponentMemoryOverlay ( ) ;
@@ -28,12 +28,16 @@ public sealed class OpponentMemoryPlugin : IPlugin
2828 private const int OverlayRefreshIntervalMs = 300 ;
2929 private readonly Stopwatch _overlayRefresh = Stopwatch . StartNew ( ) ;
3030 private bool _forceOverlayRefresh = true ;
31+ private int ? _ghostStatusRound ;
32+ private int ? _ghostStatusPlayerId ;
33+ private bool _cachedScheduledIsGhost ;
34+ private bool _overlayHiddenForBackground ;
3135
3236 public string Name => "Opponent Memory" ;
3337 public string Description => "Tracks how many times you have faced each opponent in Hearthstone Battlegrounds." ;
3438 public string ButtonText => "Settings" ;
3539 public string Author => "" ;
36- public Version Version => new Version ( 1 , 1 , 0 , 0 ) ;
40+ public Version Version => new Version ( 1 , 2 ) ;
3741 public MenuItem MenuItem => _menuItem ??= BuildMenu ( ) ;
3842
3943 public void OnLoad ( )
@@ -88,7 +92,6 @@ public void OnUpdate()
8892 }
8993 var combat = Core . Game . IsBattlegroundsCombatPhase ;
9094 var scheduled = _resolver . GetScheduledOpponentPlayerId ( ) ;
91- var scheduledIsGhost = scheduled is > 0 && _resolver . IsGhostOpponent ( scheduled . Value ) ;
9295 if ( ! _wasSupported )
9396 {
9497 _wasSupported = true ;
@@ -101,13 +104,26 @@ public void OnUpdate()
101104 {
102105 if ( _tracker . ActiveCombatOpponentPlayerId == null )
103106 {
107+ var scheduledIsGhost = GetScheduledGhostStatus ( round , scheduled , true ) ;
104108 _tracker . Schedule ( round , scheduled , scheduledIsGhost ) ;
105109 _tracker . StartCombat ( round ) ;
106110 }
107111 }
108112 else
109- _tracker . Schedule ( round , scheduled , scheduledIsGhost ) ;
113+ _tracker . Schedule ( round , scheduled , GetScheduledGhostStatus ( round , scheduled , false ) ) ;
110114 _wasCombat = combat ;
115+ if ( ! User32 . IsHearthstoneInForeground ( ) )
116+ {
117+ if ( ! _overlayHiddenForBackground )
118+ InvokeUi ( _overlay . Hide ) ;
119+ _overlayHiddenForBackground = true ;
120+ return ;
121+ }
122+ if ( _overlayHiddenForBackground )
123+ {
124+ _overlayHiddenForBackground = false ;
125+ _forceOverlayRefresh = true ;
126+ }
111127 if ( _forceOverlayRefresh || _overlayRefresh . ElapsedMilliseconds >= OverlayRefreshIntervalMs )
112128 {
113129 _forceOverlayRefresh = false ;
@@ -139,6 +155,28 @@ private void CompleteActiveCombat()
139155 _forceOverlayRefresh = true ;
140156 }
141157
158+ private bool GetScheduledGhostStatus ( int round , int ? playerId , bool forceRefresh )
159+ {
160+ if ( playerId is not > 0 )
161+ return false ;
162+ if ( forceRefresh || _ghostStatusRound != round || _ghostStatusPlayerId != playerId )
163+ {
164+ var isGhost = _resolver . IsGhostOpponent ( playerId . Value ) ;
165+ _ghostStatusRound = round ;
166+ _ghostStatusPlayerId = playerId ;
167+ _cachedScheduledIsGhost = isGhost ;
168+ }
169+ return _cachedScheduledIsGhost ;
170+ }
171+
172+ private void ResetGhostStatusCache ( )
173+ {
174+ _ghostStatusRound = null ;
175+ _ghostStatusPlayerId = null ;
176+ _cachedScheduledIsGhost = false ;
177+ _overlayHiddenForBackground = false ;
178+ }
179+
142180 private bool PrepareMatchState ( GameHandleSnapshot gameHandles )
143181 {
144182 if ( ! _hasMatchState )
@@ -173,6 +211,7 @@ private void InitializeNewMatch(uint? gameHandle)
173211 _wasCombat = null ;
174212 _wasSupported = false ;
175213 _leaderboardReadiness . Reset ( ) ;
214+ ResetGhostStatusCache ( ) ;
176215 _forceOverlayRefresh = true ;
177216 PluginLogger . Info ( "New match state initialized." ) ;
178217 }
@@ -186,6 +225,7 @@ private void ResetMatchState()
186225 _sawMenu = false ;
187226 _gameHandle = null ;
188227 _leaderboardReadiness . Reset ( ) ;
228+ ResetGhostStatusCache ( ) ;
189229 }
190230
191231 private MenuItem BuildMenu ( )
0 commit comments