Skip to content

Commit

Permalink
feat: pass Battlegrounds anomaly to Tier7
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Aug 23, 2023
1 parent 4dd024b commit b8068cf
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/BobsBuddy/BobsBuddyInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void SnapshotBoardState(int turn)
var opponentTechLevel = opponentHero.GetTag(GameTag.PLAYER_TECH_LEVEL);
input.SetTiers(playerTechLevel, opponentTechLevel);

var anomalyDbfId = _game.GameEntity?.GetTag(GameTag.BACON_GLOBAL_ANOMALY_DBID);
var anomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(_game.GameEntity);
var anomalyCardId = anomalyDbfId.HasValue ? Database.GetCardFromDbfId(anomalyDbfId.Value, false)?.Id : null;
if(anomalyCardId != null)
input.Anomaly = simulator.AnomalyFactory.Create(anomalyCardId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public void SetPlacementVisible(bool isVisible)
{
HeroDbfIds = heroIds,
BattlegroundsRaces = availableRaces.Cast<int>().ToArray(),
AnomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(Core.Game.GameEntity),
LanguageCode = Config.Instance.SelectedLanguage
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public BattlegroundsHeroPanel()

public int[]? HeroIds { get; internal set; }
public int? MMR { get; internal set; }
public int? AnomalyDbfId { get; internal set; }

private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
Expand All @@ -28,7 +29,7 @@ private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e
{
Core.Overlay.HideBattlegroundsHeroPanel();
if(HeroIds != null)
Helper.OpenBattlegroundsHeroPicker(HeroIds, MMR);
Helper.OpenBattlegroundsHeroPicker(HeroIds, MMR, AnomalyDbfId);
}
}
}
3 changes: 2 additions & 1 deletion Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,8 @@ private async void HandleBattlegroundsStart()
if(Config.Instance.HideOverlay)
{
var mmr = Core.Game.BattlegroundsRatingInfo?.Rating;
ToastManager.ShowBattlegroundsToast(heroIds, mmr);
var anomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(Core.Game.GameEntity);
ToastManager.ShowBattlegroundsToast(heroIds, mmr, anomalyDbfId);
Core.Overlay.ShowBgsTopBar();
}
else
Expand Down
9 changes: 9 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/BattlegroundsUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HearthDb.Enums;
using HearthMirror;
using Hearthstone_Deck_Tracker.Hearthstone.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -57,5 +58,13 @@ private static HashSet<Race>? AvailableRaces
NonCollectible.Invalid.SecretsOfNorgannon => new HashSet<int> { 1, 2, 3, 4, 5, 6, 7 },
_ => new HashSet<int> { 1, 2, 3, 4, 5, 6 },
};

public static int? GetBattlegroundsAnomalyDbfId(Entity game)
{
var anomalyDbfId = game.GetTag(GameTag.BACON_GLOBAL_ANOMALY_DBID);
if (anomalyDbfId > 0)
return anomalyDbfId;
return null;
}
}
}
10 changes: 1 addition & 9 deletions Hearthstone Deck Tracker/Live/BoardStateWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,7 @@ private int DbfId(Entity? e)
return player.QuestRewards.FirstOrDefault(x => x.HasTag(GameTag.BACON_IS_HEROPOWER_QUESTREWARD) == heroPower)?.Card.DbfId;
}

private int? BgsAnomaly(Entity game)
{
var anomaly = game.GetTag(GameTag.BACON_GLOBAL_ANOMALY_DBID);
if (anomaly != 0)
{
return anomaly;
}
return null;
}
private int? BgsAnomaly(Entity game) => BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(game);

// Return the dbf id for an entity, but blacklisted against common hero cards we don't want want to show in the overlay.
private int HeroDbfId(Entity? entity)
Expand Down
6 changes: 5 additions & 1 deletion Hearthstone Deck Tracker/Utility/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ internal static string GetUserAgent()
return name + "/" + GetCurrentVersion();
}

internal static void OpenBattlegroundsHeroPicker(int[] heroIds, int? mmr)
internal static void OpenBattlegroundsHeroPicker(int[] heroIds, int? mmr, int? anomalyDbfId)
{
var encodedHeroIds = HttpUtility.UrlEncode(string.Join(",", heroIds));
var url = $"{BuildHsReplayNetUrl("battlegrounds/heroes", "bgs_toast")}#heroes={encodedHeroIds}";
Expand All @@ -854,6 +854,10 @@ internal static void OpenBattlegroundsHeroPicker(int[] heroIds, int? mmr)
url += $"&minionTypes={HttpUtility.UrlEncode(string.Join(",", availableRacesAsList.Select(type => type.ToString())))}";

}

if(anomalyDbfId.HasValue && anomalyDbfId.Value > 0)
url += $"&anomalyDbfId={anomalyDbfId.Value}";

TryOpenUrl(url);
HSReplayNetClientAnalytics.TryTrackToastClick(Franchise.Battlegrounds, ToastAction.Toast.BattlegroundsHeroPicker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ public partial class BattlegroundsToast : System.Windows.Controls.UserControl
{
private int[] _heroDbfIds;
private int? _mmr;
private int? _anomalyDbfId;

public BattlegroundsToast(int[] heroDbfIds, int? mmr)
public BattlegroundsToast(int[] heroDbfIds, int? mmr, int? anomalyDbfId)
{
InitializeComponent();
_heroDbfIds = heroDbfIds;
_mmr = mmr;
_anomalyDbfId = anomalyDbfId;
}

private void UserControl_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
Expand All @@ -26,7 +28,7 @@ private void UserControl_MouseLeave(object sender, System.Windows.Input.MouseEve

private void UserControl_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
Helper.OpenBattlegroundsHeroPicker(_heroDbfIds, _mmr);
Helper.OpenBattlegroundsHeroPicker(_heroDbfIds, _mmr, _anomalyDbfId);
}
}
}
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/Utility/Toasts/ToastManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static class ToastManager
private static readonly List<ToastHelper> Toasts = new List<ToastHelper>();
private static readonly Dictionary<ToastHelper, ToastHelper> GameResultToasts = new Dictionary<ToastHelper, ToastHelper>();

internal static void ShowBattlegroundsToast(int[] heroDbfIds, int? mmr)
internal static void ShowBattlegroundsToast(int[] heroDbfIds, int? mmr, int? anomalyDbfId)
{
var th = new ToastHelper(new BattlegroundsToast(heroDbfIds, mmr));
var th = new ToastHelper(new BattlegroundsToast(heroDbfIds, mmr, anomalyDbfId));
ShowToast(th, 6);
}

Expand Down
3 changes: 2 additions & 1 deletion Hearthstone Deck Tracker/Windows/OverlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ internal void ShowBattlegroundsHeroPanel(int[] heroIds)
{
HeroNotificationPanel.HeroIds = heroIds;
HeroNotificationPanel.MMR = _game.BattlegroundsRatingInfo?.Rating;
HeroNotificationPanel.AnomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(_game.GameEntity);
_heroNotificationBehavior.Show();
}

Expand All @@ -453,7 +454,7 @@ internal void ShowBgsTopBar()
{
TurnCounter.Visibility = Config.Instance.ShowBattlegroundsTurnCounter ? Visible : Collapsed;

var anomalyDbfId = _game.GameEntity?.GetTag(GameTag.BACON_GLOBAL_ANOMALY_DBID);
var anomalyDbfId = BattlegroundsUtils.GetBattlegroundsAnomalyDbfId(_game.GameEntity);
var anomalyCardId = anomalyDbfId.HasValue ? Database.GetCardFromDbfId(anomalyDbfId.Value, false)?.Id : null;
BattlegroundsMinionsPanel.SetAvailableTiers(BattlegroundsUtils.GetAvailableTiers(anomalyCardId));

Expand Down

0 comments on commit b8068cf

Please sign in to comment.