Skip to content

Commit

Permalink
feat: re-add support for WHIZBANG_DECK_ID
Browse files Browse the repository at this point in the history
Fixes #4531

This reverts commit b7657c8.
  • Loading branch information
beheh committed May 7, 2024
1 parent 743d9ca commit c704abd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker/Hearthstone/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Player(IGame game, bool isLocalPlayer)
public bool IsLocalPlayer { get; }
public int SpellsPlayedCount { get; private set; }
public List<string> CardsPlayedThisTurn { get; private set; } = new List<string>();
public bool IsPlayingWhizbang { get; set; }
public int PogoHopperPlayedCount { get; private set; }
public string? LastDiedMinionCardId { get; set; }
public string? LastDrawnCardId { get; set; }
Expand Down
33 changes: 28 additions & 5 deletions Hearthstone Deck Tracker/LogReader/Handlers/TagChangeActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ internal class TagChangeActions
case CREATOR:
case DISPLAYED_CREATOR:
return () => CreatorChanged(id, value, game);
case WHIZBANG_DECK_ID:
return () => WhizbangDeckIdChange(id, value, game);
case MULLIGAN_STATE:
return () => MulliganStateChange(id, value, game, gameState);
case COPIED_FROM_ENTITY_ID:
Expand Down Expand Up @@ -237,6 +239,22 @@ private void MulliganStateChange(int id, int value, IGame game, IHsGameState gam
gameState.GameHandler?.HandlePlayerMulliganDone();
}

private void WhizbangDeckIdChange(int id, int value, IGame game)
{
if(value == 0)
return;
if(!game.Entities.TryGetValue(id, out var entity))
return;
if(entity.IsControlledBy(game.Player.Id))
game.Player.IsPlayingWhizbang = true;
else if(entity.IsControlledBy(game.Opponent.Id))
game.Opponent.IsPlayingWhizbang = true;
if(!entity.IsPlayer)
return;
if(Config.Instance.AutoDeckDetection)
DeckManager.AutoSelectTemplateDeckById(game, value);
}

private void CreatorChanged(int id, int value, IGame game)
{
if(value == 0)
Expand Down Expand Up @@ -265,12 +283,17 @@ private void CreatorChanged(int id, int value, IGame game)
}
if(creatorId == game.GameEntity?.Id)
return;

if(game.Entities.TryGetValue(creatorId, out var creator) && creator.CardId == Collectible.Neutral.WhizbangTheWonderful) {
// The decks created by Whizbang used to have a creator tag set, but not anymore. Keep for safety.
return;
// All cards created by Whizbang have a creator tag set
if(game.Entities.TryGetValue(creatorId, out var creator))
{
if(creator.CardId == CardIds.Collectible.Neutral.WhizbangTheWonderful)
return;
var controller = creator.GetTag(CONTROLLER);
var usingWhizbang = controller == game.Player?.Id && game.Player.IsPlayingWhizbang
|| controller == game.Opponent?.Id && game.Opponent.IsPlayingWhizbang;
if(usingWhizbang && creator.IsInSetAside)
return;
}

entity.Info.Created = true;
}
}
Expand Down

0 comments on commit c704abd

Please sign in to comment.