Skip to content

Commit

Permalink
Rework lich king check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonysegal committed Jul 15, 2021
1 parent ce8ff23 commit 14bc87c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
67 changes: 32 additions & 35 deletions Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ internal class BobsBuddyInvoker
private static Dictionary<int, Minion> _currentOpponentMinions = new Dictionary<int, Minion>();
private static List<Entity> _currentOpponentSecrets = new List<Entity>();

private MinionHeroPowerTrigger _minionHeroPowerTrigger;
private static Guid _currentGameId;
private static readonly Dictionary<string, BobsBuddyInvoker> _instances = new Dictionary<string, BobsBuddyInvoker>();
private static readonly Regex _debuglineToIgnore = new Regex(@"\|(Player|Opponent|TagChangeActions)\.");
Expand Down Expand Up @@ -146,24 +145,6 @@ public bool ShouldRun()
return true;
}

internal void HeroPowerTriggered(string heroPowerId)
{
if(_minionHeroPowerTrigger != null && _minionHeroPowerTrigger.HeroPowerId == heroPowerId)
_minionHeroPowerTrigger.Tsc.SetResult(null);
}

internal void SetMinionReborn(int entityId)
{
if(_currentOpponentMinions.TryGetValue(entityId, out var rebornMinion) && rebornMinion != null)
{
if(rebornMinion.receivesLichKingPower)
DebugLog($"Giving receivesLichKingHeroPower to {rebornMinion.minionName} which already had it.");
else
DebugLog($"Giving Giving receivesLichKingHeroPower to {rebornMinion.minionName} which already did not already have it.");
rebornMinion.receivesLichKingPower = true;
}
}

public async void StartCombat()
{
try
Expand Down Expand Up @@ -201,28 +182,46 @@ public async void StartCombat()
BobsBuddyDisplay.ResetText();

_removedLichKingHeroPowerFromMinion = false;
if(_minionHeroPowerTrigger != null && CanRemoveLichKing)

if(CanRemoveLichKing)
{
var minion = _minionHeroPowerTrigger.Minion;
var start = DateTime.Now;
DebugLog($"Waiting for hero power ({_minionHeroPowerTrigger.HeroPowerId}) trigger for {minion.minionName}...");
var completedTask = await Task.WhenAny(_minionHeroPowerTrigger.Tsc.Task, Task.Delay(HeroPowerTriggerTimeout));
var duration = (DateTime.Now - start).TotalMilliseconds;
if(completedTask != _minionHeroPowerTrigger.Tsc.Task)
var lichKingMinions = new List<Minion>();
var playerLichMinions = _input.opponentSide.Where(x => x.receivesLichKingPower).ToList();
var opponentLichMinions = _input.playerSide.Where(x => x.receivesLichKingPower).ToList();
lichKingMinions.AddRange(playerLichMinions);
lichKingMinions.AddRange(opponentLichMinions);
if(lichKingMinions.Any())
{

await Task.Delay(LichKingDelay);
foreach(var minion in lichKingMinions)
{
if(_game.Entities.TryGetValue(minion.game_id, out var entity) && entity != null)
{
var attatchedEntities = GetAttachedEntities(minion.game_id);
if(!attatchedEntities.Any(x => x.CardId == RebornRiteEnchmantment))
{
minion.receivesLichKingPower = false;
_removedLichKingHeroPowerFromMinion = true;
}

}
}
}
if(playerLichMinions.Any() && _input.heroPowerInfo?.PlayerActivatedPower == HeroPower.None)
{
DebugLog($"Found no hero power trigger after {duration}ms. Resetting receivedHeroPower on {minion.minionName}");
minion.receivesLichKingPower = false;
_removedLichKingHeroPowerFromMinion = true;
foreach(var minion in playerLichMinions)
minion.receivesLichKingPower = false;
}
else
if(opponentLichMinions.Any() && _input.heroPowerInfo?.OpponentActivatedPower == HeroPower.None)
{
DebugLog($"Found hero power trigger for {minion.minionName} after {duration}ms");
_removedLichKingHeroPowerFromMinion = true;
foreach(var minion in opponentLichMinions)
minion.receivesLichKingPower = false;
}
}

if(_game.Opponent.Board.Any(x => x.CardId == LichKingHeroPowerId || x.CardId == LichKingHeroPowerEnchantmentId))
await Task.Delay(LichKingDelay);

if(!RunSimulationAfterCombat)
RunAndDisplaySimulationAsync();
}
Expand Down Expand Up @@ -386,8 +385,6 @@ private void SnapshotBoardState(int turn)
{
m.AddToBackOfList(input.opponentSide, simulator);

if(m.receivesLichKingPower)
_minionHeroPowerTrigger = new MinionHeroPowerTrigger(m, RebornRite);
_currentOpponentMinions[m.game_id] = m;
}

Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/BobsBuddy/BobsBuddyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class BobsBuddyUtils
private const string ReplicatingMenace = NonCollectible.Neutral.ReplicatingMenace_ReplicatingMenaceEnchantment;
private const string ReplicatingMenace_Golden = NonCollectible.Neutral.ReplicatingMenace_ReplicatingMenaceEnchantmentTavernBrawl;
private const string LivingSpores = NonCollectible.Neutral.LivingSporesToken2;
private const string RebornRiteEnchmantment = NonCollectible.Neutral.RebornRites_RebornRiteEnchantmentTavernBrawl;
public const string RebornRiteEnchmantment = NonCollectible.Neutral.RebornRites_RebornRiteEnchantmentTavernBrawl;
internal const string RebornRite = NonCollectible.Neutral.RebornRitesTavernBrawl;

internal static Minion GetMinionFromEntity(Entity entity, IEnumerable<Entity> attachedEntities)
Expand Down

0 comments on commit 14bc87c

Please sign in to comment.