From 01d13bcb6f41cacf54bed489b69ce2bc564b2f2d Mon Sep 17 00:00:00 2001 From: Benedict Etzel Date: Wed, 23 Aug 2023 22:56:56 +0200 Subject: [PATCH] fix: terminal case winner detection --- .../BobsBuddy/BobsBuddyInvoker.cs | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs b/Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs index 5facc760e..32d170cee 100644 --- a/Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs +++ b/Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs @@ -40,8 +40,6 @@ internal class BobsBuddyInvoker private Input? _input; private int _turn; static int LogLinesKept = Remote.Config.Data?.BobsBuddy?.LogLinesKept ?? 100; - public string OpponentCardId = ""; - public string PlayerCardId = ""; private Entity? _attackingHero; private Entity? _defendingHero; public Entity? LastAttackingHero = null; @@ -353,10 +351,6 @@ private void SnapshotBoardState(int turn) DebugLog("Hero(es) could not be found. Exiting."); return; } - - //We set OpponentCardId and PlayerCardId here so that later we can do lookups for these entites without using _game.Opponent/Player, which might be innacurate or null depending on when they're accessed. - OpponentCardId = opponentHero.CardId ?? ""; - PlayerCardId = playerHero.CardId ?? ""; input.SetHealths(playerHero.Health + playerHero.GetTag(GameTag.ARMOR), opponentHero.Health + opponentHero.GetTag(GameTag.ARMOR)); @@ -699,16 +693,10 @@ private CombatResult GetLastCombatResult() { if(LastAttackingHero == null) return CombatResult.Tie; - var playerHero = _game.Entities.Values.FirstOrDefault(x => x.CardId == PlayerCardId); - var opponentHero = _game.Entities.Values.FirstOrDefault(x => x.CardId == OpponentCardId); - if(playerHero != null && opponentHero != null) - { - if(LastAttackingHero.CardId == playerHero.CardId) - return CombatResult.Win; - if(LastAttackingHero.CardId == opponentHero.CardId) - return CombatResult.Loss; - } - return CombatResult.Invalid; + if(LastAttackingHero.IsControlledBy(_game.Player.Id)) + return CombatResult.Win; + else + return CombatResult.Loss; } private LethalResult GetLastLethalResult()