Skip to content

Commit

Permalink
fix: check draw scores after penalty shootout
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRampey committed Jul 6, 2024
1 parent 7538e58 commit 4734c61
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/stackr/transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,25 +365,25 @@ const endMatch: STF<League, MatchRequest> = {
}

const teamScores = { ...match.scores };
const [a, b] = Object.keys(teamScores);

if (teamScores[a] === teamScores[b]) {
if (match.penaltyStartTime) {
const playerIdToTeamId = getPlayerToTeam(state);

const penalties = logs.filter(
(l) => l.matchId === matchId && l.action === LogAction.PENALTY_HIT
);

for (const penalty of penalties) {
const teamId = playerIdToTeamId[penalty.playerId];
teamScores[teamId] += 1;
}
} else {
throw new Error("MATCH_DRAWN");
if (match.penaltyStartTime) {
const playerIdToTeamId = getPlayerToTeam(state);

const penalties = logs.filter(
(l) => l.matchId === matchId && l.action === LogAction.PENALTY_HIT
);

for (const penalty of penalties) {
const teamId = playerIdToTeamId[penalty.playerId];
teamScores[teamId] += 1;
}
}

const [a, b] = Object.keys(teamScores);
if (teamScores[a] === teamScores[b]) {
throw new Error("MATCH_DRAWN");
}

const winner = teamScores[a] > teamScores[b] ? a : b;
match.winnerTeamId = +winner;
match.endTime = block.timestamp;
Expand Down

0 comments on commit 4734c61

Please sign in to comment.