Skip to content

Commit

Permalink
fix: nullability of Game/Player/Opponent Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Aug 23, 2023
1 parent 4fbd286 commit 1b2bf0b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
18 changes: 18 additions & 0 deletions Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ private void SnapshotBoardState(int turn)
return;
}

if(_game.GameEntity == null)
{
DebugLog("GameEntity could not be found. Exiting.");
return;
}

if(_game.PlayerEntity == null)
{
DebugLog("PlayerEntity could not be found. Exiting.");
return;
}

if(_game.OpponentEntity == null)
{
DebugLog("OpponentEntity could not be found. Exiting.");
return;
}

input.availableRaces = BattlegroundsUtils.GetAvailableRaces(_currentGameId).ToList();
input.DamageCap = _game.GameEntity.GetTag(GameTag.BACON_COMBAT_DAMAGE_CAP);

Expand Down
6 changes: 3 additions & 3 deletions Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ public Format? CurrentFormat

public bool SavedReplay { get; set; }

public Entity PlayerEntity => Entities.FirstOrDefault(x => x.Value?.IsPlayer ?? false).Value;
public Entity? PlayerEntity => Entities.Values.FirstOrDefault(x => x.IsPlayer);

public Entity OpponentEntity => Entities.FirstOrDefault(x => x.Value != null && x.Value.HasTag(GameTag.PLAYER_ID) && !x.Value.IsPlayer).Value;
public Entity? OpponentEntity => Entities.Values.FirstOrDefault(x => x.HasTag(GameTag.PLAYER_ID) && !x.IsPlayer);

public Entity GameEntity => Entities.FirstOrDefault(x => x.Value?.Name == "GameEntity").Value;
public Entity? GameEntity => Entities.Values.FirstOrDefault(x => x.Name == "GameEntity");

public bool IsMulliganDone
{
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Hearthstone/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IGame
{
Player Player { get; set; }
Player Opponent { get; set; }
Entity GameEntity { get; }
Entity? GameEntity { get; }
Entity? PlayerEntity { get; }
Entity? OpponentEntity { get; }
bool IsMulliganDone { get; }
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Live/BoardStateWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private int DbfId(Entity? e)
return player.QuestRewards.FirstOrDefault(x => x.HasTag(GameTag.BACON_IS_HEROPOWER_QUESTREWARD) == heroPower)?.Card.DbfId;
}

private int? BgsAnomaly(Entity game) => BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(game);
private int? BgsAnomaly(Entity? game) => BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(game);

// Return the dbf id for an entity, but blacklisted against common hero cards we don't want want to show in the overlay.
private int HeroDbfId(Entity? entity)
Expand Down
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/Utility/WotogCounterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public static class WotogCounterHelper
public static bool? GraveHorrorInDeck => DeckContains(CardIds.Collectible.Priest.GraveHorror);

public static bool PlayerSeenJade => Core.Game.PlayerEntity?.HasTag(JADE_GOLEM) ?? false;
public static int PlayerNextJadeGolem => PlayerSeenJade ? Math.Min(Core.Game.PlayerEntity.GetTag(JADE_GOLEM) + 1, 30) : 1;
public static int PlayerNextJadeGolem => PlayerSeenJade ? Math.Min(Core.Game.PlayerEntity!.GetTag(JADE_GOLEM) + 1, 30) : 1;

public static bool OpponentSeenJade => Core.Game.OpponentEntity?.HasTag(JADE_GOLEM) ?? false;
public static int OpponentNextJadeGolem => OpponentSeenJade ? Math.Min(Core.Game.OpponentEntity.GetTag(JADE_GOLEM) + 1, 30) : 1;
public static int OpponentNextJadeGolem => OpponentSeenJade ? Math.Min(Core.Game.OpponentEntity!.GetTag(JADE_GOLEM) + 1, 30) : 1;
public static int PlayerGalakrondInvokeCounter => Core.Game.PlayerEntity?.GetTag(INVOKE_COUNTER) ?? 0;
public static int OpponentGalakrondInvokeCounter => Core.Game.OpponentEntity?.GetTag(INVOKE_COUNTER) ?? 0;

Expand Down

0 comments on commit 1b2bf0b

Please sign in to comment.