From aa959af09a1135c40a5cb4f51776bc9fd6ff0f3c Mon Sep 17 00:00:00 2001 From: Tomer Date: Fri, 15 Dec 2023 21:08:06 +0200 Subject: [PATCH] feat: ui win probability --- .../src/dota/events/gsi-events/newdata.ts | 25 +++++++++++++++++++ packages/settings/src/settings.ts | 2 ++ 2 files changed, 27 insertions(+) diff --git a/packages/dota/src/dota/events/gsi-events/newdata.ts b/packages/dota/src/dota/events/gsi-events/newdata.ts index fbed19768..3bb9b8955 100644 --- a/packages/dota/src/dota/events/gsi-events/newdata.ts +++ b/packages/dota/src/dota/events/gsi-events/newdata.ts @@ -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 @@ -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) diff --git a/packages/settings/src/settings.ts b/packages/settings/src/settings.ts index bcdd7342a..4d479747b 100644 --- a/packages/settings/src/settings.ts +++ b/packages/settings/src/settings.ts @@ -105,6 +105,8 @@ export const defaultSettings = { notablePlayersOverlay: true, notablePlayersOverlayFlags: true, notablePlayersOverlayFlagsCmd: true, + winProbabilityOverlay: true, + winProbabilityOverlayIntervalMinutes: 10, tellChatNewMMR: true, tellChatBets: true, queueBlocker: false,