Skip to content

Commit

Permalink
feat: preparations for Battlegrounds Duos
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Apr 16, 2024
1 parent 12abf7f commit 6223d77
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 27 deletions.
4 changes: 3 additions & 1 deletion HearthWatcher/BaconWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HearthWatcher.Providers;
using System;
using System.Threading.Tasks;
using HearthMirror.Objects;

namespace HearthWatcher
{
Expand Down Expand Up @@ -45,7 +46,8 @@ private async void Update()
_provider.IsJournalOpen ?? false,
_provider.IsPopupShowing ?? false,
_provider.IsFriendslistOpen ?? false,
_provider.IsBlurActive ?? false
_provider.IsBlurActive ?? false,
_provider.SelectedBattlegroundsGameMode ?? SelectedBattlegroundsGameMode.UNKNOWN
);
if(curr.Equals(_prev))
continue;
Expand Down
14 changes: 11 additions & 3 deletions HearthWatcher/EventArgs/BaconEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace HearthWatcher.EventArgs
using HearthMirror.Objects;

namespace HearthWatcher.EventArgs
{
public class BaconEventArgs : System.EventArgs
{
Expand All @@ -7,14 +9,18 @@ public class BaconEventArgs : System.EventArgs
public bool IsPopupShowing { get; }
public bool IsFriendslistOpen { get; }
public bool IsBlurActive { get; }
public SelectedBattlegroundsGameMode SelectedBattlegroundsGameMode { get; }

public BaconEventArgs(bool isShopOpen, bool isJournalOpen, bool isPopupShowing, bool isFriendslistOpen, bool isBlurActive)
public BaconEventArgs(
bool isShopOpen, bool isJournalOpen, bool isPopupShowing, bool isFriendslistOpen, bool isBlurActive, SelectedBattlegroundsGameMode selectedBattlegroundsGameMode
)
{
IsShopOpen = isShopOpen;
IsJournalOpen = isJournalOpen;
IsPopupShowing = isPopupShowing;
IsFriendslistOpen = isFriendslistOpen;
IsBlurActive = isBlurActive;
SelectedBattlegroundsGameMode = selectedBattlegroundsGameMode;
}

public bool IsAnyOpen => IsShopOpen || IsJournalOpen || IsPopupShowing || IsFriendslistOpen || IsBlurActive;
Expand All @@ -24,7 +30,8 @@ public override bool Equals(object obj) => obj is BaconEventArgs args
&& IsJournalOpen == args.IsJournalOpen
&& IsPopupShowing == args.IsPopupShowing
&& IsFriendslistOpen == args.IsFriendslistOpen
&& IsBlurActive == args.IsBlurActive;
&& IsBlurActive == args.IsBlurActive
&& SelectedBattlegroundsGameMode == args.SelectedBattlegroundsGameMode;

public override int GetHashCode()
{
Expand All @@ -34,6 +41,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + IsPopupShowing.GetHashCode();
hashCode = hashCode * -1521134295 + IsFriendslistOpen.GetHashCode();
hashCode = hashCode * -1521134295 + IsBlurActive.GetHashCode();
hashCode = hashCode * -1521134295 + SelectedBattlegroundsGameMode.GetHashCode();
return hashCode;
}
}
Expand Down
5 changes: 4 additions & 1 deletion HearthWatcher/Providers/IBaconProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace HearthWatcher.Providers
using HearthMirror.Objects;

namespace HearthWatcher.Providers
{
public interface IBaconProvider
{
Expand All @@ -7,5 +9,6 @@ public interface IBaconProvider
bool? IsPopupShowing { get; }
bool? IsFriendslistOpen { get; }
bool? IsBlurActive { get; }
SelectedBattlegroundsGameMode? SelectedBattlegroundsGameMode { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public void SetPlacementVisible(bool isVisible)
BattlegroundsRaces = availableRaces.Cast<int>().ToArray(),
AnomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(Core.Game.GameEntity),
LanguageCode = Config.Instance.SelectedLanguage,
BattlegroundsRating = Core.Game.BattlegroundsRatingInfo?.Rating
BattlegroundsRating = Core.Game.CurrentBattlegroundsRating,
IsDuos = Core.Game.IsBattlegroundsDuosMatch
};

game.BattlegroundsHeroPickStatsParams = parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private async Task Update()
AnomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(Core.Game.GameEntity),
OfferedRewards = rewards,
LanguageCode = Config.Instance.SelectedLanguage,
BattlegroundsRating = Core.Game.BattlegroundsRatingInfo?.Rating
BattlegroundsRating = Core.Game.CurrentBattlegroundsRating
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System.Windows;
using HearthDb.Enums;
using HearthMirror.Objects;
using Hearthstone_Deck_Tracker.Enums.Hearthstone;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.Utility;
Expand Down Expand Up @@ -53,19 +54,23 @@ public async void Update()

public void UpdateSectionsVisibilities()
{
AvailableMinionTypesSectionVisibility = Config.Instance.ShowSessionRecapMinionsAvailable
var isDuos = Core.Game.IsInMenu
? BattlegroundsGameMode == SelectedBattlegroundsGameMode.DUOS
: Core.Game.IsBattlegroundsDuosMatch;

AvailableMinionTypesSectionVisibility = Config.Instance.ShowSessionRecapMinionsAvailable
? Visibility.Visible
: Visibility.Collapsed;

BannedMinionTypesSectionVisibility = Config.Instance.ShowSessionRecapMinionsBanned
? Visibility.Visible
: Visibility.Collapsed;

BgStartCurrentMMRSectionVisibility = Config.Instance.ShowSessionRecapStartCurrentMMR
BgStartCurrentMMRSectionVisibility = Config.Instance.ShowSessionRecapStartCurrentMMR && !isDuos
? Visibility.Visible
: Visibility.Collapsed;

BgLatestGamesSectionVisibility = Config.Instance.ShowSessionRecapLatestGames
BgLatestGamesSectionVisibility = Config.Instance.ShowSessionRecapLatestGames && !isDuos
? Visibility.Visible
: Visibility.Collapsed;

Expand Down Expand Up @@ -342,4 +347,19 @@ public Visibility BgLatestGamesSectionVisibility
OnPropertyChanged();
}
}

#region Mode
public SelectedBattlegroundsGameMode BattlegroundsGameMode
{
get
{
return GetProp(SelectedBattlegroundsGameMode.UNKNOWN);
}
set
{
SetProp(value);
UpdateSectionsVisibilities();
}
}
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Input;
using System.Windows.Media;
using HearthMirror;
using HearthMirror.Objects;
using Hearthstone_Deck_Tracker.Enums.Hearthstone;
using Hearthstone_Deck_Tracker.HsReplay;
using Hearthstone_Deck_Tracker.Utility;
Expand Down Expand Up @@ -36,6 +37,20 @@ public Tier7PreLobbyViewModel()
};
}

#region Mode
public SelectedBattlegroundsGameMode BattlegroundsGameMode
{
get
{
return GetProp(SelectedBattlegroundsGameMode.UNKNOWN);
}
set
{
SetProp(value);
}
}
#endregion

#region Visibiliy
public bool IsModalOpen
{
Expand Down
26 changes: 17 additions & 9 deletions Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,19 +681,26 @@ public async void HandleGameEnd(bool stateComplete)
_game.CurrentGameStats.ArenaWins = DeckImporter.ArenaInfoCache?.Wins ?? 0;
_game.CurrentGameStats.ArenaLosses = DeckImporter.ArenaInfoCache?.Losses ?? 0;
}
else if(_game.CurrentGameMode == Brawl && _game.BrawlInfo != null)
else if(_game.CurrentGameMode == Brawl)
{
_game.CurrentGameStats.BrawlWins = _game.BrawlInfo.Wins;
_game.CurrentGameStats.BrawlLosses = _game.BrawlInfo.Losses;
var brawlInfo = _game.BrawlInfo;
if(brawlInfo != null)
{
_game.CurrentGameStats.BrawlWins = brawlInfo.Wins;
_game.CurrentGameStats.BrawlLosses = brawlInfo.Losses;
}
}
else if (_game.IsBattlegroundsMatch && _game.BattlegroundsRatingInfo != null)
else if (_game.IsBattlegroundsMatch)
{
_game.CurrentGameStats.BattlegroundsRating = _game.BattlegroundsRatingInfo.Rating;
var rating = _game.CurrentBattlegroundsRating;
if(rating.HasValue)
_game.CurrentGameStats.BattlegroundsRating = rating.Value;
}
else if (_game.IsMercenariesMatch)
{
if(_game.IsMercenariesPvpMatch && _game.MercenariesRatingInfo != null)
_game.CurrentGameStats.MercenariesRating = _game.MercenariesRatingInfo.Rating;
var ratingInfo = _game.MercenariesRatingInfo;
if(_game.IsMercenariesPvpMatch && ratingInfo != null)
_game.CurrentGameStats.MercenariesRating = ratingInfo.Rating;
if(_game.IsMercenariesPveMatch)
{
_game.CurrentGameStats.MercenariesBountyRunId = _game.MercenariesMapInfo?.Seed.ToString();
Expand Down Expand Up @@ -855,7 +862,8 @@ public async void HandleGameEnd(bool stateComplete)
Sentry.SendQueuedBobsBuddyEvents(_game.CurrentGameStats.HsReplay.UploadId);
else
Sentry.ClearBobsBuddyEvents();
RecordBattlegroundsGame();
if(!_game.IsBattlegroundsDuosMatch)
RecordBattlegroundsGame();
Tier7Trial.Clear();
Core.Game.BattlegroundsSessionViewModel.OnGameEnd();
Core.Windows.BattlegroundsSessionWindow.OnGameEnd();
Expand Down Expand Up @@ -1317,7 +1325,7 @@ private void CaptureMulliganGuideFeedback()

private async void HandleBattlegroundsStart()
{
if(Config.Instance.ShowBattlegroundsToast)
if(Config.Instance.ShowBattlegroundsToast && _game.IsBattlegroundsSoloMatch)
{
for(var i = 0; i < 10; i++)
{
Expand Down
24 changes: 20 additions & 4 deletions Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,19 @@ public GameV2()
public bool? IsDungeonMatch => string.IsNullOrEmpty(CurrentGameStats?.OpponentHeroCardId) || CurrentGameType == GameType.GT_UNKNOWN ? (bool?)null
: CurrentGameType == GameType.GT_VS_AI && DungeonRun.IsDungeonBoss(CurrentGameStats?.OpponentHeroCardId);

public bool IsBattlegroundsMatch => CurrentGameType == GameType.GT_BATTLEGROUNDS || CurrentGameType == GameType.GT_BATTLEGROUNDS_FRIENDLY;
public bool IsBattlegroundsMatch => IsBattlegroundsSoloMatch || IsBattlegroundsDuosMatch;
public bool IsBattlegroundsSoloMatch =>
CurrentGameType is
GameType.GT_BATTLEGROUNDS or
GameType.GT_BATTLEGROUNDS_FRIENDLY or
GameType.GT_BATTLEGROUNDS_AI_VS_AI or
GameType.GT_BATTLEGROUNDS_PLAYER_VS_AI;
public bool IsBattlegroundsDuosMatch =>
CurrentGameType is
GameType.GT_BATTLEGROUNDS_DUO or
GameType.GT_BATTLEGROUNDS_DUO_VS_AI or
GameType.GT_BATTLEGROUNDS_DUO_FRIENDLY;

public bool IsMercenariesMatch => CurrentGameType == GameType.GT_MERCENARIES_AI_VS_AI || CurrentGameType == GameType.GT_MERCENARIES_FRIENDLY
|| CurrentGameType == GameType.GT_MERCENARIES_PVE || CurrentGameType == GameType.GT_MERCENARIES_PVP
|| CurrentGameType == GameType.GT_MERCENARIES_PVE_COOP;
Expand Down Expand Up @@ -235,11 +247,15 @@ public MatchInfo.MedalInfo? PlayerMedalInfo
}
}

public BrawlInfo BrawlInfo => _brawlInfo ?? (_brawlInfo = HearthMirror.Reflection.Client.GetBrawlInfo());
public BrawlInfo? BrawlInfo => _brawlInfo ?? (_brawlInfo = HearthMirror.Reflection.Client.GetBrawlInfo());

public BattlegroundRatingInfo? BattlegroundsRatingInfo => _battlegroundsRatingInfo ?? (_battlegroundsRatingInfo = HearthMirror.Reflection.Client.GetBattlegroundRatingInfo());

public BattlegroundRatingInfo BattlegroundsRatingInfo => _battlegroundsRatingInfo ?? (_battlegroundsRatingInfo = HearthMirror.Reflection.Client.GetBattlegroundRatingInfo());
public int? CurrentBattlegroundsRating => IsBattlegroundsMatch
? (IsBattlegroundsDuosMatch ? BattlegroundsRatingInfo?.DuosRating : BattlegroundsRatingInfo?.Rating)
: null;

public MercenariesRatingInfo MercenariesRatingInfo => _mercenariesRatingInfo ?? (_mercenariesRatingInfo = HearthMirror.Reflection.Client.GetMercenariesRatingInfo());
public MercenariesRatingInfo? MercenariesRatingInfo => _mercenariesRatingInfo ?? (_mercenariesRatingInfo = HearthMirror.Reflection.Client.GetMercenariesRatingInfo());

public MercenariesMapInfo MercenariesMapInfo => HearthMirror.Reflection.Client.GetMercenariesMapInfo();

Expand Down
3 changes: 2 additions & 1 deletion Hearthstone Deck Tracker/Hearthstone/Watchers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static void Stop()

internal static void OnBaconChange(object sender, HearthWatcher.EventArgs.BaconEventArgs args)
{
Core.Overlay.SetBaconState(args.IsAnyOpen);
Core.Overlay.SetBaconState(args.SelectedBattlegroundsGameMode, args.IsAnyOpen);
}

internal static void OnDeckPickerChange(object sender, HearthWatcher.EventArgs.DeckPickerEventArgs args)
Expand Down Expand Up @@ -142,6 +142,7 @@ public class HearthMirrorBaconProvider : IBaconProvider
public bool? IsPopupShowing => Reflection.Client.IsPopupShowing();
public bool? IsFriendslistOpen => Reflection.Client.IsFriendsListVisible();
public bool? IsBlurActive => Reflection.Client.GetIsBlurActive();
public SelectedBattlegroundsGameMode? SelectedBattlegroundsGameMode => Reflection.Client.GetSelectedBattlegroundsGameMode();
}

public class HearthMirrorDeckPickerProvider : IDeckPickerProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private void UpdateBattlegroundsOverlay()
var turn = _game.GetTurnNumber();
_leaderboardDeadForText.ForEach(x => x.Visibility = Visibility.Collapsed);
_leaderboardDeadForTurnText.ForEach(x => x.Visibility = Visibility.Collapsed);
if(turn == 0)
if(turn == 0 || _game.IsBattlegroundsDuosMatch)
return;
for(var i = 0; i < _leaderboardIcons.Count; i++)
{
Expand Down
4 changes: 3 additions & 1 deletion Hearthstone Deck Tracker/Windows/OverlayWindow.Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using static HearthDb.Enums.GameTag;
using static Hearthstone_Deck_Tracker.Controls.Overlay.WotogCounterStyle;
using HearthDb.Enums;
using HearthMirror.Objects;
using Hearthstone_Deck_Tracker.Utility.Extensions;
using Hearthstone_Deck_Tracker.HsReplay;
using Hearthstone_Deck_Tracker.Utility.Animations;
Expand Down Expand Up @@ -632,7 +633,8 @@ public void UpdateTier7PreLobbyVisibility()
!_game.QueueEvents.IsInQueue &&
SceneHandler.Scene == Mode.BACON &&
Config.Instance.EnableBattlegroundsTier7Overlay &&
Config.Instance.ShowBattlegroundsTier7PreLobby
Config.Instance.ShowBattlegroundsTier7PreLobby &&
Tier7PreLobbyViewModel.BattlegroundsGameMode != SelectedBattlegroundsGameMode.DUOS
);

if(show)
Expand Down
7 changes: 6 additions & 1 deletion Hearthstone Deck Tracker/Windows/OverlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ internal void ShowBobsBuddyPanel()
return;
if(Remote.Config.Data?.BobsBuddy?.Disabled ?? false)
return;
if(_game.IsBattlegroundsDuosMatch)
return; // disable in Duos for now
_bgsBobsBuddyBehavior.Show();
}

Expand Down Expand Up @@ -804,9 +806,12 @@ internal void SetDeckPickerState(VisualsFormatType vft, IEnumerable<CollectionDe
ConstructedMulliganGuidePreLobbyViewModel.IsModalOpen = isModalOpen;
}

internal void SetBaconState(bool isAnyOpen)
internal void SetBaconState(SelectedBattlegroundsGameMode mode, bool isAnyOpen)
{
Tier7PreLobbyViewModel.BattlegroundsGameMode = mode;
Tier7PreLobbyViewModel.IsModalOpen = !_game.QueueEvents.IsInQueue && isAnyOpen;
BattlegroundsSessionViewModelVM.BattlegroundsGameMode = mode;
UpdateTier7PreLobbyVisibility();
}

internal void SetConstructedQueue(bool inQueue)
Expand Down

0 comments on commit 6223d77

Please sign in to comment.