Skip to content

Commit

Permalink
feat(Duos): last known board state
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed May 17, 2024
1 parent 016041c commit 26a0319
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 16 deletions.
15 changes: 15 additions & 0 deletions HDTTests/Hearthstone/Secrets/MockGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public MockGame()
public bool IsMulliganDone { get; set; }
public bool IsInMenu { get; set; }
public bool IsUsingPremade { get; set; }
public bool IsBattlegroundsMatch => IsBattlegroundsSoloMatch || IsBattlegroundsDuosMatch;
public bool IsBattlegroundsSoloMatch { get; set; }
public bool IsBattlegroundsDuosMatch { get; set; }
public bool IsRunning { get; set; }
public Region CurrentRegion { get; set; }
public GameMode CurrentGameMode { get; set; }
Expand Down Expand Up @@ -62,6 +65,18 @@ public void SnapshotBattlegroundsBoardState()
throw new NotImplementedException();
}


public bool DuosWasPlayerHeroModified { get; set; }
public bool DuosWasOpponentHeroModified { get; set; }

public void DuosSetHeroModified(bool isPlayer) => throw new NotImplementedException();

public void DuosResetHeroTracking()
{
DuosWasPlayerHeroModified = false;
DuosWasOpponentHeroModified = false;
}

public BoardSnapshot GetBattlegroundsBoardStateFor(int entityId)
{
throw new NotImplementedException();
Expand Down
21 changes: 21 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,5 +582,26 @@ BattlegroundsHeroPickState.PickedHeroDbfId is int heroDbfId &&

return null;
}

public bool DuosWasPlayerHeroModified { get; private set; }
public bool DuosWasOpponentHeroModified { get; private set; }

public void DuosSetHeroModified(bool isPlayer)
{
if(isPlayer)
{
DuosWasPlayerHeroModified = true;
}
else
{
DuosWasOpponentHeroModified = true;
}
}

public void DuosResetHeroTracking()
{
DuosWasPlayerHeroModified = false;
DuosWasOpponentHeroModified = false;
}
}
}
9 changes: 9 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public interface IGame
bool IsMulliganDone { get; }
bool IsInMenu { get; set; }
bool IsUsingPremade { get; set; }
bool IsBattlegroundsMatch { get; }
bool IsBattlegroundsSoloMatch { get; }
bool IsBattlegroundsDuosMatch { get; }
bool IsRunning { get; set; }
Region CurrentRegion { get; set; }
GameMode CurrentGameMode { get; }
Expand Down Expand Up @@ -57,6 +60,12 @@ public interface IGame
bool PlayerChallengeable { get; }
bool SetupDone { get; set; }
void SnapshotBattlegroundsBoardState();

void DuosSetHeroModified(bool isPlayer);
void DuosResetHeroTracking();
bool DuosWasPlayerHeroModified { get; }
bool DuosWasOpponentHeroModified { get; }

BoardSnapshot? GetBattlegroundsBoardStateFor(int entityId);
int GetTurnNumber();
}
Expand Down
38 changes: 37 additions & 1 deletion Hearthstone Deck Tracker/LogReader/Handlers/TagChangeActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ internal class TagChangeActions
return () => gameState.GameHandler?.HandleQuestRewardDatabaseId(id, value);
case (GameTag)2022:
return () => OnBattlegroundsSetupChange(value, prevValue, game, gameState);
case (GameTag)3533:
return () => OnBattlegroundsCombatSetupChange(value, prevValue, game);
case HERO_ENTITY:
return () => OnHeroEntityChange(id, value, game);
}
return null;
}
Expand All @@ -100,7 +104,6 @@ private void OnBattlegroundsSetupChange(int value, int prevValue, IGame game, IH
{
if(prevValue == 1 && value == 0)
{
game.SnapshotBattlegroundsBoardState();
if(game.CurrentGameStats != null)
{
BobsBuddyInvoker.GetInstance(game.CurrentGameStats.GameId, gameState.GetTurnNumber())?
Expand All @@ -109,6 +112,39 @@ private void OnBattlegroundsSetupChange(int value, int prevValue, IGame game, IH
}
}

private void OnBattlegroundsCombatSetupChange(int value, int prevValue, IGame game)
{
if(prevValue == 0 && value == 1)
game.DuosResetHeroTracking();

if(prevValue == 1 && value == 0)
{
if(game.IsBattlegroundsSoloMatch)
{
game.SnapshotBattlegroundsBoardState();
}
else if(game.DuosWasOpponentHeroModified)
{
game.SnapshotBattlegroundsBoardState();
}
}
}

private void OnHeroEntityChange(int playerEntityId, int heroEntityId, IGame game)
{
if(game.IsBattlegroundsDuosMatch)
{
if(playerEntityId == game.PlayerEntity?.Id)
{
game.DuosSetHeroModified(true);
}
else if(playerEntityId == game.OpponentEntity?.Id)
{
game.DuosSetHeroModified(false);
}
}
}

private void OnResourcesUsedChange(int id, int value, IGame game)
{
if(game.PlayerEntity == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public partial class OverlayWindow
public double CardHeight => Height * 0.189;
public double MercAbilityHeight => Height * 0.3;
//Adjusts OpponentDeadFor textblocks left by this amount depending on what position they represent on the leaderboard.
const double LeftAdjust = .00075;
const double LeftAdjust = .0017;
//Adjusts the OpponentDeadFor textblock of the next oponent by this to the right so it aligns correctly with the hero portrait.
const double NextOpponentRightAdjust = .025;
const double NextOpponentRightAdjust = .023;
const double DuosNextOpponentRightAdjust = .015;
private double LeaderboardTop => Height * 0.15;
private const int MaxHandSize = 10;
private const int MaxBoardSize = 7;
Expand Down Expand Up @@ -108,8 +109,6 @@ private void UpdateMouseOverDetectionRegions(List<Entity> oppBoard, List<Entity>
Canvas.SetTop(_leaderboardIcons[i], LeaderboardTop + BattlegroundsTileHeight * i);
Canvas.SetLeft(_leaderboardIcons[i], Helper.GetScaledXPos(0.001 * (_leaderboardIcons.Count - i - 1), (int)Width, ScreenRatio));
}

PositionDeadForText();
}

internal void ResetNextOpponentLeaderboardPosition() => _nextOpponentLeaderboardPosition = -1;
Expand All @@ -119,18 +118,34 @@ internal void PositionDeadForText(int nextOpponentLeaderboardPosition = 0)
if(nextOpponentLeaderboardPosition > 0)
_nextOpponentLeaderboardPosition = nextOpponentLeaderboardPosition;

for(int i = 0; i < _leaderboardDeadForText.Count; i++)
if(Core.Game.IsBattlegroundsDuosMatch)
{
Canvas.SetTop(_leaderboardDeadForText[i], LeaderboardTop + BattlegroundsTileHeight * i);
Canvas.SetLeft(_leaderboardDeadForText[i], Helper.GetScaledXPos(LeftAdjust * (_leaderboardDeadForText.Count - i - 1), (int)Width, ScreenRatio));
Canvas.SetTop(_leaderboardDeadForTurnText[i], LeaderboardTop + BattlegroundsTileHeight * i);
Canvas.SetLeft(_leaderboardDeadForTurnText[i], Helper.GetScaledXPos(LeftAdjust * (_leaderboardDeadForTurnText.Count - i - 1), (int)Width, ScreenRatio));
for(int i = 0; i < _leaderboardDeadForText.Count; i++)
{
int j = i / 2;
var top = LeaderboardTop + BattlegroundsDuosTileHeight * i + BattlegroundsDuosSpacingHeight * j;
var left = ((_leaderboardDeadForText.Count / 2) - i) * LeftAdjust;
if(j == nextOpponentLeaderboardPosition - 1)
left += DuosNextOpponentRightAdjust;
Canvas.SetTop(_leaderboardDeadForText[i], top);
Canvas.SetLeft(_leaderboardDeadForText[i], Helper.GetScaledXPos(left, (int)Width, ScreenRatio));
Canvas.SetTop(_leaderboardDeadForTurnText[i], top);
Canvas.SetLeft(_leaderboardDeadForTurnText[i], Helper.GetScaledXPos(left, (int)Width, ScreenRatio));
}
}

if(_nextOpponentLeaderboardPosition > 0)
else
{
Canvas.SetLeft(_leaderboardDeadForText[_nextOpponentLeaderboardPosition - 1], Helper.GetScaledXPos(LeftAdjust * (_leaderboardDeadForText.Count - _nextOpponentLeaderboardPosition - 2) + NextOpponentRightAdjust, (int)Width, ScreenRatio));
Canvas.SetLeft(_leaderboardDeadForTurnText[_nextOpponentLeaderboardPosition - 1], Helper.GetScaledXPos(LeftAdjust * (_leaderboardDeadForTurnText.Count - _nextOpponentLeaderboardPosition - 2) + NextOpponentRightAdjust, (int)Width, ScreenRatio));
for(int i = 0; i < _leaderboardDeadForText.Count; i++)
{
var top = LeaderboardTop + BattlegroundsTileHeight * i;
var left = ((_leaderboardDeadForText.Count / 2) - i) * LeftAdjust;
if(i == nextOpponentLeaderboardPosition - 1)
left += NextOpponentRightAdjust;
Canvas.SetTop(_leaderboardDeadForText[i], top);
Canvas.SetLeft(_leaderboardDeadForText[i], Helper.GetScaledXPos(left, (int)Width, ScreenRatio));
Canvas.SetTop(_leaderboardDeadForTurnText[i], top);
Canvas.SetLeft(_leaderboardDeadForTurnText[i], Helper.GetScaledXPos(left, (int)Width, ScreenRatio));
}
}
}

Expand Down Expand Up @@ -373,17 +388,26 @@ private void UpdateBattlegroundsOverlay()
var turn = _game.GetTurnNumber();
_leaderboardDeadForText.ForEach(x => x.Visibility = Visibility.Collapsed);
_leaderboardDeadForTurnText.ForEach(x => x.Visibility = Visibility.Collapsed);
if(turn == 0 || _game.IsBattlegroundsDuosMatch)
if(turn == 0)
return;
var shouldShowOpponentInfo = false;
if(_leaderboardHoveredEntityId is int heroEntityId)
{
fadeBgsMinionsList = true;
_leaderboardDeadForText.ForEach(x => x.Visibility = Visibility.Visible);
_leaderboardDeadForTurnText.ForEach(x => x.Visibility = Visibility.Visible);

// check if it's the team mate
Core.Game.Entities.TryGetValue(heroEntityId, out var entity);
var state = _game.GetBattlegroundsBoardStateFor(heroEntityId);
BgsOpponentInfo.Update(heroEntityId, state, turn);
shouldShowOpponentInfo = !(_game.Entities.TryGetValue(heroEntityId, out var entity) && entity.IsControlledBy(_game.Player.Id));
shouldShowOpponentInfo = !(entity != null && (
entity.IsControlledBy(_game.Player.Id) ||
(
Core.Game.IsBattlegroundsDuosMatch &&
entity.GetTag(GameTag.BACON_DUO_TEAM_ID) == Core.Game.PlayerEntity?.GetTag(GameTag.BACON_DUO_TEAM_ID)
)
));
}
if(shouldShowOpponentInfo)
{
Expand Down
3 changes: 3 additions & 0 deletions Hearthstone Deck Tracker/Windows/OverlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ public VerticalAlignment OpponentStackPanelAlignment
=> Config.Instance.OverlayCenterOpponentStackPanel ? VerticalAlignment.Center : VerticalAlignment.Top;

public double BattlegroundsTileHeight => Height * 0.69 / 8;
public double BattlegroundsDuosTileToSpacingRatio = 0.137;
public double BattlegroundsDuosTileHeight => Height * 0.69 * (1 - BattlegroundsDuosTileToSpacingRatio) / 8;
public double BattlegroundsDuosSpacingHeight => Height * 0.69 * BattlegroundsDuosTileToSpacingRatio / 3;
public double BattlegroundsTileWidth => BattlegroundsTileHeight;

private double MercenariesButtonOffset
Expand Down

0 comments on commit 26a0319

Please sign in to comment.