public override AchievementAwarded IsAwardedForThisPlayer(int playerId)
{
var player = DataContext.GetQueryable<Player>().FirstOrDefault(p => p.Id == playerId);
var result = new AchievementAwarded
{
AchievementId = Id
};
if (player != null)
{
var nemePointsDictionary = (from playerGameResult in DataContext.GetQueryable<PlayerGameResult>()
where playerGameResult.PlayedGame.GamingGroupId == player.GamingGroupId
group playerGameResult by playerGameResult.PlayerId
into groupedResults
select
new
{
BasePoints = groupedResults.Sum(x => x.NemeStatsPointsAwarded),
GameDurationBonusPoints = groupedResults.Sum(x => x.GameDurationBonusPoints),
WeightBonusPoints = groupedResults.Sum(x => x.GameWeightBonusPoints),
PlayerId = groupedResults.Key
}).ToDictionary(key => key.PlayerId,
value =>
new NemePointsSummary(value.BasePoints, value.GameDurationBonusPoints,
value.WeightBonusPoints))
.OrderByDescending(r => r.Value.TotalPoints);
if (nemePointsDictionary.First().Key == player.Id && nemePointsDictionary.First().Value.TotalPoints >= MinNemePointsToUnlock)
{
result.LevelAwarded = LevelThresholds.First().Key;
result.PlayerProgress = 1;
}
}
return result;
}
}