Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Roshan kill message to include Radiant/Dire percentages #453

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface RoshRes {
minDate: Date
maxDate: Date
count: number
radiantPercentage: number
direPercentage: number
}

// Doing it this way so i18n can pick up the t('') strings
Expand Down Expand Up @@ -49,6 +51,20 @@ export function getNewRoshTime(res: RoshRes) {
return res
}

export function calculateRadiantDirePercentages(minS: number, maxS: number) {
const totalDuration = maxS - minS
const radiantDuration = 300 - minS
const direDuration = maxS - 300

const radiantPercentage = (radiantDuration / totalDuration) * 100
const direPercentage = (direDuration / totalDuration) * 100

return {
radiantPercentage: radiantPercentage > 0 ? radiantPercentage : 0,
direPercentage: direPercentage > 0 ? direPercentage : 0,
}
}

export function generateRoshanMessage(res: RoshRes, lng: string) {
res = getNewRoshTime(res)

Expand All @@ -63,6 +79,18 @@ export function generateRoshanMessage(res: RoshRes, lng: string) {
)
}

const percentages = calculateRadiantDirePercentages(res.minS, res.maxS)
res.radiantPercentage = percentages.radiantPercentage
res.direPercentage = percentages.direPercentage

msgs.push(
t('roshanPercentages', {
radiant: res.radiantPercentage.toFixed(0),
dire: res.direPercentage.toFixed(0),
lng,
}),
)

msgs.push(getRoshCountMessage({ lng, count: res.count }))

return msgs.join(' · ')
Expand Down Expand Up @@ -113,6 +141,8 @@ eventHandler.registerEvent(`event:${DotaEventTypes.RoshanKilled}`, {
minDate,
maxDate,
count: count + 1,
radiantPercentage: 0,
direPercentage: 0,
}

await redisClient.client.json.set(`${dotaClient.getToken()}:roshan`, '$', res)
Expand Down
Loading