Skip to content

Commit

Permalink
fix: refresh hero picking stats after a reroll
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoraes74 committed Dec 4, 2024
1 parent 87ae7b8 commit 0626416
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
51 changes: 51 additions & 0 deletions HSTracker/Logging/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,57 @@ class Game: NSObject, PowerEventHandler {
return stats
}

private var battlegroundsHeroPickingLatch = 0

@available(macOS 10.15.0, *)
private func refreshBattlegroundsHeroPickStats() async {
let heroes = player.playerEntities.filter { x in x.isHero && (x.has(tag: .bacon_hero_can_be_drafted) || x.has(tag: .bacon_skin)) }

// refresh the offered heroes
snapshotBattlegroundsOfferedHeroes(heroes)
cacheBattlegroundsHeroPickParams()

guard getBattlegroundsHeroPickParams() != nil else {
return
}

defer {
battlegroundsHeroPickingLatch -= 1
}

battlegroundsHeroPickingLatch += 1
let latchOut = battlegroundsHeroPickingLatch
var battlegroundsHeroPickStats: BattlegroundsHeroPickStats?
battlegroundsHeroPickStats = await getBattlegroundsHeroPickStats()

// another task has updated them since (fast reroll)
if latchOut != battlegroundsHeroPickingLatch {
return
}

// the stats are no longer relevant
if gameEntity?[.step] ?? 0 > Step.begin_mulligan.rawValue || isInMenu || windowManager.battlegroundsHeroPicking.viewModel.heroStats == nil {
return
}

if let stats = battlegroundsHeroPickStats {
let heroIds = heroes.sorted(by: { (a, b) -> Bool in return a.zonePosition < b.zonePosition }).compactMap { x in x.card.dbfId }
DispatchQueue.main.async {
self.showBattlegroundsHeroPickingStats(heroIds.compactMap({ dbfId in stats.data.first { x in x.hero_dbf_id == dbfId }}), stats.toast.parameters, stats.toast.min_mmr, stats.toast.anomaly_adjusted ?? false)
}
}
}

public func handleBattlegroundsHeroReroll(id: Int, cardId: String) {
if isBattlegroundsMatch() {
if #available(macOS 10.15, *) {
Task.detached {
await self.refreshBattlegroundsHeroPickStats()
}
}
}
}

private var _battlegroundsHeroPickStatsParams: BattlegroundsHeroPickStatsParams?

func cacheBattlegroundsHeroPickParams() {
Expand Down
2 changes: 2 additions & 0 deletions HSTracker/Logging/Handlers/LogEventHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,6 @@ protocol PowerEventHandler: AnyObject {
var duosWasOpponentHeroModified: Bool { get }

var triangulatePlayed: Bool { get set }

func handleBattlegroundsHeroReroll(id: Int, cardId: String)
}
8 changes: 7 additions & 1 deletion HSTracker/Logging/Parsers/PowerGameStateParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ class PowerGameStateParser: LogEventParser {
// placeholders and Fantastic Treasure (Marin's hero power)
entity.has(tag: .bacon_is_magic_item_discover) ||
// Souvenir Stand
entity.has(tag: .bacon_trinket) {
entity.has(tag: .bacon_trinket) ||
// Heroes during Battlegrounds reroll
entity.has(tag: .bacon_hero_can_be_drafted) {
entity.cardId = cardId
}
entity.info.latestCardId = cardId
Expand Down Expand Up @@ -378,6 +380,10 @@ class PowerGameStateParser: LogEventParser {
if entity[.transformed_from_card] == 46706 {
eventHandler.chameleosReveal = (entityId, cardId)
}
// Battlegrounds hero reroll
if entity.has(tag: .bacon_hero_can_be_drafted) && (eventHandler.gameEntity?[.step] ?? Step.invalid.rawValue) <= Step.begin_mulligan.rawValue {
eventHandler.handleBattlegroundsHeroReroll(id: entity.id, cardId: cardId)
}
}

set(currentEntity: entityId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Foundation
return
}
let cnt = heroes.count
let bounds = NSRect(x: 0, y: 0, width: (266 + 37) * cnt + 37 * (cnt - 1) - 28, height: 480)
let bounds = NSRect(x: 0, y: 0, width: (266 + 37) * cnt + 37 * (cnt - 1) - 28, height: 568)
logger.debug("bounds: \(bounds)")
let scale = SizeHelper.hearthstoneWindow.height / 1080
let sw = bounds.width * scale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class BattlegroundsSingleHeroStats: NSView {
var setSelectedHeroDbfIdCommand: ((_ heroId: Int) -> Void)?

@objc dynamic var compositionsVisibility: Bool {
return viewModel.compositionsVisibility
return false //viewModel.compositionsVisibility
}

override var intrinsicContentSize: NSSize {
return NSSize(width: 266, height: 480)
return NSSize(width: 266, height: 568)
}

required init?(coder: NSCoder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22689"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -18,23 +18,23 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe" userLabel="BattlegroundsSingleHero">
<rect key="frame" x="0.0" y="0.0" width="266" height="480"/>
<rect key="frame" x="0.0" y="0.0" width="266" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="dJn-dd-3p5" customClass="BattlegroundsHeroHeader" customModule="HSTracker" customModuleProvider="target">
<rect key="frame" x="15" y="408" width="236" height="72"/>
<rect key="frame" x="15" y="496" width="236" height="72"/>
<constraints>
<constraint firstAttribute="width" constant="236" id="6EJ-DD-qF4"/>
<constraint firstAttribute="height" constant="72" id="V4j-aR-g3F"/>
</constraints>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="u1e-O1-gPf" userLabel="HeroPortraitContainer">
<rect key="frame" x="15" y="132" width="236" height="276"/>
<rect key="frame" x="15" y="132" width="236" height="364"/>
<constraints>
<constraint firstAttribute="width" constant="236" id="Evg-vn-ueL"/>
</constraints>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="5q0-Cd-eRk" userLabel="Compositions" customClass="BattlegroundsCompositionPopularity" customModule="HSTracker" customModuleProvider="target">
<customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5q0-Cd-eRk" userLabel="Compositions" customClass="BattlegroundsCompositionPopularity" customModule="HSTracker" customModuleProvider="target">
<rect key="frame" x="15" y="0.0" width="236" height="72"/>
<constraints>
<constraint firstAttribute="width" constant="236" id="3TF-VP-H0t"/>
Expand Down Expand Up @@ -70,7 +70,7 @@
<customView translatesAutoresizingMaskIntoConstraints="NO" id="5OH-eu-5bq">
<rect key="frame" x="0.0" y="-2" width="169" height="88"/>
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Z61-9S-dVs">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Z61-9S-dVs">
<rect key="frame" x="6" y="62" width="157" height="22"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="Il1-tv-yoM"/>
Expand All @@ -81,7 +81,7 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="0kR-WP-yxU">
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="0kR-WP-yxU">
<rect key="frame" x="6" y="20" width="157" height="42"/>
<constraints>
<constraint firstAttribute="height" constant="42" id="Dfo-yv-4Xz"/>
Expand All @@ -92,7 +92,7 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5hA-bl-Zuo" userLabel="ArmorTooltipRange">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5hA-bl-Zuo" userLabel="ArmorTooltipRange">
<rect key="frame" x="6" y="7" width="157" height="13"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="ArmorTooltipRange" id="yQO-8l-IQq">
<font key="font" metaFont="system" size="10"/>
Expand Down
2 changes: 1 addition & 1 deletion HSTracker/cards-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210009
212197

0 comments on commit 0626416

Please sign in to comment.