Skip to content

Commit

Permalink
feat: ui win probability
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomerxp committed Dec 15, 2023
1 parent bc3318c commit aa959af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/dota/src/dota/events/gsi-events/newdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { isPlayingMatch } from '../../lib/isPlayingMatch.js'
import { say } from '../../say.js'
import eventHandler from '../EventHandler.js'
import minimapParser from '../minimap/parser.js'
import { server } from '../../index'
import { GetLiveMatch } from '../../../stratz/livematch'

function chatterMatchFound(client: SocketClient) {
if (!client.stream_online) return
Expand Down Expand Up @@ -130,6 +132,29 @@ eventHandler.registerEvent(`newdata`, {
dotaClient.client.gsi?.map?.win_team && dotaClient.client.gsi.map.win_team !== 'none'
if (hasWon) return

const winChanceEnabled = getValueOrDefault(
DBSettings.winProbabilityOverlay,
dotaClient.client.settings,
)
if (winChanceEnabled) {
const updateInterval = getValueOrDefault(
DBSettings.winProbabilityOverlayIntervalMinutes,
dotaClient.client.settings,
)

if (
dotaClient.client.gsi?.map?.clock_time &&
dotaClient.client.gsi?.map?.clock_time % (updateInterval * 60) === 0
) {
const matchDetails = await GetLiveMatch(parseInt(dotaClient.client.gsi?.map?.matchid, 10))
const lastWinRate = matchDetails?.data.live.match?.liveWinRateValues.slice(-1).pop()
server.io.to(dotaClient.client.token).emit('update-radiant-win-chance', {
value: lastWinRate?.winRate,
time: lastWinRate?.time,
})
}
}

// only if they're in a match ^ and they're a beta tester
if (dotaClient.client.beta_tester && dotaClient.client.stream_online) {
const enabled = getValueOrDefault(DBSettings['minimap-blocker'], dotaClient.client.settings)
Expand Down
2 changes: 2 additions & 0 deletions packages/settings/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export const defaultSettings = {
notablePlayersOverlay: true,
notablePlayersOverlayFlags: true,
notablePlayersOverlayFlagsCmd: true,
winProbabilityOverlay: true,
winProbabilityOverlayIntervalMinutes: 10,
tellChatNewMMR: true,
tellChatBets: true,
queueBlocker: false,
Expand Down

0 comments on commit aa959af

Please sign in to comment.