mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-17 15:22:26 +00:00
Make all players in lobby submit unique score
Matches official server behavior.
This commit is contained in:
parent
2b90ed52aa
commit
3f52f10960
1 changed files with 29 additions and 13 deletions
|
@ -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();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue