Skip to content

Commit 5cd4415

Browse files
committed
feat(BGs): handle opponet's hand related enchantments
1 parent c6dc60c commit 5cd4415

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

Hearthstone Deck Tracker/LogReader/Handlers/PowerHandler.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,25 +1498,32 @@ public void Handle(string logLine, DateTime logLineTime, IHsGameState gameState,
14981498
gameState.GameHandler?.HandlePlayerAbyssalCurse(nextDamage);
14991499
}
15001500

1501-
// Handle Choral Mrrrglr enchantment in Battlegrounds
1501+
// Handle Hand related enchantments in Battlegrounds
15021502
// Check at BLOCK_END because the enchantment is updated DURING the block, not at BLOCK_START
1503-
if(game.CurrentGameMode == GameMode.Battlegrounds && game.CurrentGameStats != null &&
1504-
gameState.CurrentBlock?.Type == "TRIGGER")
1503+
if(game.CurrentGameMode == GameMode.Battlegrounds && game.CurrentGameStats != null && gameState.CurrentBlock?.Type == "TRIGGER")
15051504
{
1506-
if(gameState.CurrentBlock?.CardId == NonCollectible.Neutral.ChoralMrrrglr)
1505+
// Handle hand related minions that trigger enchantments on opponent's board
1506+
var enchantmentMapping = new Dictionary<string, string>
15071507
{
1508-
var choralEntity = game.Entities.TryGetValue(gameState.CurrentBlock.SourceEntityId, out var entity) ? entity : null;
1509-
if(choralEntity != null && choralEntity.IsControlledBy(game.Opponent.Id))
1508+
{ NonCollectible.Neutral.ChoralMrrrglr, NonCollectible.Neutral.ChoralMrrrglr_ChorusEnchantment },
1509+
{ NonCollectible.Neutral.TimewarpedMrrrglr, NonCollectible.Neutral.ChoralMrrrglr_ChorusEnchantment },
1510+
{ NonCollectible.Neutral.CostumeEnthusiast, NonCollectible.Neutral.CostumeEnthusiast_EnthusiasticEnchantment },
1511+
{ NonCollectible.Neutral.Dramaloc, NonCollectible.Neutral.Dramaloc_DramaticEnchantment }
1512+
};
1513+
1514+
if(gameState.CurrentBlock?.CardId != null && enchantmentMapping.TryGetValue(gameState.CurrentBlock.CardId, out var enchantmentCardId))
1515+
{
1516+
var sourceEntity = game.Entities.TryGetValue(gameState.CurrentBlock.SourceEntityId, out var entity) ? entity : null;
1517+
if(sourceEntity != null && sourceEntity.IsControlledBy(game.Opponent.Id))
15101518
{
1511-
// Find the Chorus enchantment that was CHANGED in this block and attached to Choral
1512-
// The enchantment is created inside the TRIGGER block, so it exists in game.Entities by BLOCK_END
1513-
var chorusEnchantment = game.Entities.Values
1514-
.FirstOrDefault(e => e.CardId == NonCollectible.Neutral.ChoralMrrrglr_ChorusEnchantment &&
1515-
e.GetTag(GameTag.ATTACHED) == choralEntity.Id &&
1516-
e.GetTag(GameTag.CREATOR) == choralEntity.Id);
1519+
// Find the enchantment that was created in this TRIGGER block and attached to the source minion
1520+
var enchantment = game.Entities.Values
1521+
.FirstOrDefault(e => e.CardId == enchantmentCardId &&
1522+
e.GetTag(GameTag.ATTACHED) == sourceEntity.Id &&
1523+
e.GetTag(GameTag.CREATOR) == sourceEntity.Id);
15171524

1518-
if(chorusEnchantment != null)
1519-
BobsBuddyInvoker.GetInstance(game.CurrentGameStats.GameId, game.GetTurnNumber()).UpdateMinionEnchantment(chorusEnchantment, choralEntity.Id, false);
1525+
if(enchantment != null)
1526+
BobsBuddyInvoker.GetInstance(game.CurrentGameStats.GameId, game.GetTurnNumber()).UpdateMinionEnchantment(enchantment, sourceEntity.Id, false);
15201527
}
15211528
}
15221529
if(gameState.CurrentBlock is { CardId: NonCollectible.Neutral.TimewarpedNelliesShipToken1, TriggerKeyword: "DEATHRATTLE" })
@@ -1536,9 +1543,7 @@ public void Handle(string logLine, DateTime logLineTime, IHsGameState gameState,
15361543
.UpdateNelliesShipEnchantment(summonedEntities, nelliesEntity.Id, nelliesEntity.IsControlledBy(game.Player.Id));
15371544
}
15381545
}
1539-
15401546
}
1541-
15421547
gameState.BlockEnd();
15431548
}
15441549

0 commit comments

Comments
 (0)