Skip to content

Commit

Permalink
a few fixes related to highscore notifications (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
Metraberryy authored Jan 14, 2025
1 parent a528c65 commit b428b35
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public async Task<IActionResult> SubmitScore(string slotType, int id, int childI
this.database.Scores.Add(existingScore);
}

if (score.Points > existingScore.Points)
bool personalBest = score.Points > existingScore.Points;

if (personalBest)
{
existingScore.Points = score.Points;
existingScore.Timestamp = TimeHelper.TimestampMillis;
Expand All @@ -172,12 +174,14 @@ public async Task<IActionResult> SubmitScore(string slotType, int id, int childI
TargetPlayerIds = null,
});

if (score.Type == 1 && scores.YourRank == 1 && scores.Total > 1)
// if this is a PB, singleplayer, at the top of the leaderboard (not scores.YourRank==1 because it might be tied), and there is at least one other score,
// send a notification to the user with the previous highscore
if (personalBest && score.Type == 1 && scores.Scores[0].UserId == token.UserId && scores.Total > 1)

Check notice on line 179 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Invert 'if' statement to reduce nesting

Invert 'if' statement to reduce nesting
{
GameScore? second = scores.Scores[1];
UserEntity? user = await this.database.UserFromGameToken(token);

await this.database.SendNotification(second.UserId, $"{user?.InfoXml} beat your highscore (<em>{second.Points}</em>) on {slot.InfoXml} with a score of <em>{score.Points}</em>.", true);
await this.database.SendNotification(second.UserId, $"{user?.InfoXml} beat your highscore (<em>{second.Points}</em>) on {slot.InfoXml} with a score of <em>{score.Points}</em>.", false);
}

return this.Ok(scores);
Expand Down

0 comments on commit b428b35

Please sign in to comment.