Skip to content

Commit

Permalink
fix: correctly handle clock running out in solo game
Browse files Browse the repository at this point in the history
previously, the system health would not degrade if a player let the time
run out, which could lead to a victory with 0 points

also fixed an issue where games with 0 points were also excluded from the
study bonus payment info
  • Loading branch information
sgfost committed Dec 6, 2024
1 parent 7dae91a commit edc2fff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 8 additions & 3 deletions server/src/rooms/sologame/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,18 @@ export class DrawCardsCmd extends CmdWithoutPayload {
}
}

export class InvestCmd extends Cmd<{ systemHealthInvestment: number }> {
export class InvestCmd extends Cmd<{ systemHealthInvestment: number; clockRanOut?: boolean }> {
validate({ systemHealthInvestment } = this.payload) {
return this.state.canInvest && systemHealthInvestment <= this.state.resources;
}

async execute({ systemHealthInvestment } = this.payload) {
const surplus = this.state.resources - systemHealthInvestment;
async execute({ systemHealthInvestment, clockRanOut } = this.payload) {
let surplus = 0;
// if the clock ran out (as opposed to player-triggered investment), they get
// 0 points and 0 system health
if (!clockRanOut) {
surplus = this.state.resources - systemHealthInvestment;
}
this.state.systemHealth = Math.min(
this.defaultParams.systemHealthMax,
this.state.systemHealth + systemHealthInvestment
Expand Down
5 changes: 2 additions & 3 deletions server/src/rooms/sologame/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ export class SoloGameRoom extends Room<SoloGameState> {
this.state.timeRemaining -= 1;
} else if (!this.state.isRoundTransitioning) {
this.dispatcher.dispatch(
new PersistRoundCmd().setPayload({
new InvestCmd().setPayload({
systemHealthInvestment: 0,
pointsInvestment: 0,
clockRanOut: true,
})
);
this.dispatcher.dispatch(new SetNextRoundCmd());
}
}, 1000);
}
Expand Down
6 changes: 4 additions & 2 deletions server/src/services/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ export class StudyService extends BaseService {
p =>
p.prolificBaselinePlayer?.game &&
p.prolificVariablePlayer?.game &&
p.prolificBaselinePlayer.points &&
p.prolificVariablePlayer.points
p.prolificBaselinePlayer.points !== null &&
p.prolificBaselinePlayer.points !== undefined &&
p.prolificVariablePlayer.points !== null &&
p.prolificVariablePlayer.points !== undefined
)
// return an array of prolificId and total points earned, if they lost they get 0 points
.map(p => {
Expand Down

0 comments on commit edc2fff

Please sign in to comment.