Skip to content

Commit 3c3c7f2

Browse files
committed
division by 0 checks
1 parent cfad42c commit 3c3c7f2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

client/src/playback/RoundStat.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class RoundStat {
7676
let totalCatDamage = 0
7777
let totalRatKings = 0
7878
for (let i = 0; i < delta.teamIdsLength(); i++) {
79-
totalCheese += delta.teamCheeseAmounts(i)!
79+
totalCheese += delta.teamCollectedCheeseAmounts(i)!
8080
totalCatDamage += delta.teamCatDamage(i)!
8181
totalRatKings += delta.teamAliveRatKings(i)!
8282
}
@@ -87,11 +87,11 @@ export default class RoundStat {
8787
const teamStat = this.teams.get(team) ?? assert.fail(`team ${i} not found in team stats in round`)
8888

8989
teamStat.cheeseAmount = delta.teamCollectedCheeseAmounts(i) ?? assert.fail('missing cheese amount')
90-
teamStat.cheesePercent = teamStat.cheeseAmount / totalCheese
90+
teamStat.cheesePercent = totalCheese ? teamStat.cheeseAmount / totalCheese : 0
9191
teamStat.catDamageAmount = delta.teamCatDamage(i) ?? assert.fail('missing cat damage amount')
92-
teamStat.catDamagePercent = teamStat.catDamageAmount / totalCatDamage
92+
teamStat.catDamagePercent = totalCatDamage ? teamStat.catDamageAmount / totalCatDamage : 0
9393
teamStat.ratKingCount = delta.teamAliveRatKings(i) ?? assert.fail('missing rat king count')
94-
teamStat.ratKingPercent = teamStat.ratKingCount / totalRatKings
94+
teamStat.ratKingPercent = totalRatKings ? teamStat.ratKingCount / totalRatKings : 0
9595
teamStat.dirtAmount = delta.teamDirtAmounts(i) ?? assert.fail('missing dirt amount')
9696
teamStat.ratTrapAmount = delta.teamRatTrapCount(i) ?? assert.fail('missing rat trap amount')
9797
teamStat.catTrapAmount = delta.teamCatTrapCount(i) ?? assert.fail('missing cat trap amount')

0 commit comments

Comments
 (0)