Make all players in lobby submit unique score

Matches official server behavior.
This commit is contained in:
jvyden 2022-08-15 01:31:29 -04:00
parent 2b90ed52aa
commit 3f52f10960
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -62,20 +62,36 @@ public class ScoreController : ControllerBase
break; break;
} }
IQueryable<Score> existingScore = this.database.Scores.Where(s => s.SlotId == score.SlotId) // Submit scores from all players in lobby
.Where(s => s.PlayerIdCollection == score.PlayerIdCollection) foreach (string player in score.PlayerIds)
.Where(s => s.Type == score.Type); {
List<string> players = new();
players.Add(player); // make sure this player is first
players.AddRange(score.PlayerIds.Where(p => p != player));
Score playerScore = new()
{
PlayerIdCollection = string.Join(',', players),
Type = score.Type,
Points = score.Points,
SlotId = score.SlotId,
};
IQueryable<Score> existingScore = this.database.Scores.Where(s => s.SlotId == playerScore.SlotId)
.Where(s => s.PlayerIdCollection == playerScore.PlayerIdCollection)
.Where(s => s.Type == playerScore.Type);
if (existingScore.Any()) if (existingScore.Any())
{ {
Score first = existingScore.First(s => s.SlotId == score.SlotId); Score first = existingScore.First(s => s.SlotId == playerScore.SlotId);
score.ScoreId = first.ScoreId; playerScore.ScoreId = first.ScoreId;
score.Points = Math.Max(first.Points, score.Points); playerScore.Points = Math.Max(first.Points, playerScore.Points);
this.database.Entry(first).CurrentValues.SetValues(score); this.database.Entry(first).CurrentValues.SetValues(playerScore);
} }
else else
{ {
this.database.Scores.Add(score); this.database.Scores.Add(playerScore);
}
} }
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();