diff --git a/Hearthstone Deck Tracker/Hearthstone/Entities/Entity.cs b/Hearthstone Deck Tracker/Hearthstone/Entities/Entity.cs index 050c42959..401e9622f 100644 --- a/Hearthstone Deck Tracker/Hearthstone/Entities/Entity.cs +++ b/Hearthstone Deck Tracker/Hearthstone/Entities/Entity.cs @@ -57,7 +57,20 @@ public void ClearCardId() public Dictionary Tags { get; set; } public string? Name { get; set; } public int Id { get; set; } - public string? CardId { get; set; } + + private string? _cardId; + public string? CardId + { + get => _cardId; + set + { + if (_cardId != value) + { + _cardId = value; + _cachedCard = null; + } + } + } /// /// This is player entity, NOT the player hero. diff --git a/Hearthstone Deck Tracker/Live/BoardStateWatcher.cs b/Hearthstone Deck Tracker/Live/BoardStateWatcher.cs index f7f3fb6bd..69cc0096a 100644 --- a/Hearthstone Deck Tracker/Live/BoardStateWatcher.cs +++ b/Hearthstone Deck Tracker/Live/BoardStateWatcher.cs @@ -146,6 +146,32 @@ private int[] SortedDbfIds(IEnumerable en return player.QuestRewards.FirstOrDefault(x => x.HasTag(GameTag.BACON_IS_HEROPOWER_QUESTREWARD) == heroPower)?.Card.DbfId; } + private const int TrinketFirstSlot = 1; + private const int TrinketSecondSlot = 2; + private const int TrinketHeroPowerSlot = 3; + + private int? BgsTrinket(Player player, bool heroPowerSlot) + { + var trinketEntity = player.Trinkets.FirstOrDefault(x => + x.HasTag(GameTag.TAG_SCRIPT_DATA_NUM_6) && + (heroPowerSlot ? + x.GetTag(GameTag.TAG_SCRIPT_DATA_NUM_6) == TrinketHeroPowerSlot : + x.GetTag(GameTag.TAG_SCRIPT_DATA_NUM_6) == TrinketFirstSlot) + ); + + return DbfId(trinketEntity); + } + + private int? BgsTrinket(Player player, int trinketSlot) + { + var trinketEntity = player.Trinkets.FirstOrDefault(x => + x.HasTag(GameTag.TAG_SCRIPT_DATA_NUM_6) && + x.GetTag(GameTag.TAG_SCRIPT_DATA_NUM_6) == trinketSlot + ); + + return DbfId(trinketEntity); + } + 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. @@ -302,8 +328,10 @@ private Tuple GetBattlegroundsSoloPlayerBoar { Board = SortedDbfIds(player.Board.Where(x => x.TakesBoardSlot)), Hero = HeroDbfId(playerEntity != null ? Find(player, HeroId(playerEntity)) : null), - HeroPower = BgsQuestReward(player, true) ?? DbfId(FindHeroPower(player)), - Weapon = playerWeapon != 0 ? playerWeapon : (BgsQuestReward(player, false) ?? BuddyDbfId(player) ?? 0), + HeroPower = BgsQuestReward(player, true) ?? BgsTrinket(player, true) ?? DbfId(FindHeroPower(player)), + Weapon = playerWeapon != 0 ? playerWeapon : (BgsQuestReward(player, false) ?? BgsTrinket(player, false) ?? BuddyDbfId(player) ?? 0), + LesserTrinket = BgsTrinket(player, TrinketFirstSlot), + GreaterTrinket = BgsTrinket(player, TrinketSecondSlot), Hand = new BoardStateHand { Cards = SortedDbfIds(player.Hand), @@ -315,9 +343,11 @@ private Tuple GetBattlegroundsSoloPlayerBoar { Board = SortedDbfIds(opponent.Board.Where(x => x.TakesBoardSlot)), Hero = HeroDbfId(opponentEntity != null ? Find(opponent, HeroId(opponentEntity)) : null), - HeroPower = BgsQuestReward(opponent, true) ?? DbfId(FindHeroPower(opponent)), + HeroPower = BgsQuestReward(opponent, true) ?? BgsTrinket(opponent, true) ?? DbfId(FindHeroPower(opponent)), Weapon = opponentWeapon != 0 ? opponentWeapon - : (BgsQuestReward(opponent, false) ?? BuddyDbfId(opponent) ?? 0), + : (BgsQuestReward(opponent, false) ?? BgsTrinket(opponent, false) ?? BuddyDbfId(opponent) ?? 0), + LesserTrinket = BgsTrinket(opponent, TrinketFirstSlot), + GreaterTrinket = BgsTrinket(opponent, TrinketSecondSlot), Hand = new BoardStateHand { Size = opponent.HandCount @@ -348,11 +378,18 @@ int controller entity => GetTag(entity, GameTag.ZONE) == (int)Zone.PLAY ).ToList(); + var lesserTrinket = inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.BATTLEGROUND_TRINKET && GetTag(entity, GameTag.TAG_SCRIPT_DATA_NUM_6) == TrinketFirstSlot); + var greaterTrinket = inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.BATTLEGROUND_TRINKET && GetTag(entity, GameTag.TAG_SCRIPT_DATA_NUM_6) == TrinketSecondSlot); + var hero = inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.HERO); - var heroPower = inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.HERO_POWER); + var heroPower = + inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.HERO_POWER) + ?? inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.BATTLEGROUND_TRINKET && GetTag(entity, GameTag.TAG_SCRIPT_DATA_NUM_6) == TrinketHeroPowerSlot); var weapon = inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.WEAPON) - ?? inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.BATTLEGROUND_QUEST_REWARD); + ?? inPlay.FirstOrDefault(entity => GetTag(entity, GameTag.CARDTYPE) == (int)CardType.BATTLEGROUND_QUEST_REWARD) + ?? lesserTrinket; + var buddyDbfId = 0; if(Core.Game.BattlegroundsBuddiesEnabled) { @@ -379,6 +416,8 @@ int controller Hero = DbfId(hero), HeroPower = DbfId(heroPower), Weapon = weapon != null ? DbfId(weapon) : buddyDbfId, + LesserTrinket = DbfId(lesserTrinket), + GreaterTrinket = DbfId(greaterTrinket), Hand = new BoardStateHand { Cards = SortedDbfIds(hand), diff --git a/Hearthstone Deck Tracker/Live/Data/BoardState.cs b/Hearthstone Deck Tracker/Live/Data/BoardState.cs index 8d5f4ba96..5b253669c 100644 --- a/Hearthstone Deck Tracker/Live/Data/BoardState.cs +++ b/Hearthstone Deck Tracker/Live/Data/BoardState.cs @@ -75,6 +75,12 @@ public class BoardStatePlayer [JsonProperty("weapon", DefaultValueHandling = DefaultValueHandling.Ignore)] public int Weapon { get; set; } + [JsonProperty("lesser-trinket", DefaultValueHandling = DefaultValueHandling.Ignore)] + public int? LesserTrinket { get; set; } + + [JsonProperty("greater-trinket", DefaultValueHandling = DefaultValueHandling.Ignore)] + public int? GreaterTrinket { get; set; } + [JsonProperty("fatigue", DefaultValueHandling = DefaultValueHandling.Ignore)] public int Fatigue { get; set; } @@ -92,6 +98,10 @@ public bool Equals(BoardStatePlayer? other) return false; if(Weapon != other.Weapon) return false; + if(LesserTrinket != other.LesserTrinket) + return false; + if(GreaterTrinket != other.GreaterTrinket) + return false; if(!Board?.SequenceEqual(other.Board) ?? false) return false; if(!Secrets?.SequenceEqual(other.Secrets) ?? false)