Skip to content

Commit

Permalink
Report more details in GameLevelResponse (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden authored Aug 12, 2024
2 parents ad65f52 + 1ef45cb commit d19a854
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Relations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ public int GetTotalPlaysForLevelByUser(GameLevel level, GameUser user) =>
public int GetUniquePlaysForLevel(GameLevel level, bool includingAuthor = true) =>
this.UniquePlayLevelRelations.Count(r => r.Level == level && (includingAuthor || r.User != level.Publisher));

public int GetTotalCompletionsForLevel(GameLevel level) =>
this.GameSubmittedScores.Count(s => s.Level == level);

#endregion

#region Comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ public class GameLevelResponse : IDataConvertableFrom<GameLevelResponse, GameLev
[XmlElement("heartCount")] public required int HeartCount { get; set; }

[XmlElement("playCount")] public required int TotalPlayCount { get; set; }
[XmlElement("completionCount")] public required int CompletionCount { get; set; }
[XmlElement("uniquePlayCount")] public required int UniquePlayCount { get; set; }

[XmlElement("yourDPadRating")] public int YourRating { get; set; }
[XmlElement("thumbsup")] public required int YayCount { get; set; }
[XmlElement("thumbsdown")] public required int BooCount { get; set; }
[XmlElement("yourRating")] public int YourStarRating { get; set; }

// 1 by default since this will break reviews if set to 0 for GameLevelResponses that do not have extra data being filled in
[XmlElement("yourlbp2PlayCount")] public int YourLbp2PlayCount { get; set; } = 1;

[XmlElement("yourlbp1PlayCount")] public int YourLbp1PlayCount { get; set; }
[XmlElement("yourlbp2PlayCount")] public int YourLbp2PlayCount { get; set; }
[XmlElement("yourlbp3PlayCount")] public int YourLbp3PlayCount { get; set; }

[XmlArray("customRewards")]
[XmlArrayItem("customReward")]
Expand Down Expand Up @@ -116,6 +118,7 @@ public static GameLevelResponse FromHash(string hash, DataContext dataContext)
MaxPlayers = 4,
HeartCount = 0,
TotalPlayCount = 0,
CompletionCount = 0,
UniquePlayCount = 0,
YayCount = 0,
BooCount = 0,
Expand Down Expand Up @@ -161,6 +164,7 @@ public static GameLevelResponse FromHash(string hash, DataContext dataContext)
SameScreenGame = old.SameScreenGame,
HeartCount = dataContext.Database.GetFavouriteCountForLevel(old),
TotalPlayCount = dataContext.Database.GetTotalPlaysForLevel(old),
CompletionCount = dataContext.Database.GetTotalCompletionsForLevel(old),
UniquePlayCount = dataContext.Database.GetUniquePlaysForLevel(old),
YayCount = dataContext.Database.GetTotalRatingsForLevel(old, RatingType.Yay),
BooCount = dataContext.Database.GetTotalRatingsForLevel(old, RatingType.Boo),
Expand Down Expand Up @@ -203,10 +207,16 @@ public static GameLevelResponse FromHash(string hash, DataContext dataContext)
if (dataContext.User != null)
{
RatingType? rating = dataContext.Database.GetRatingByUser(old, dataContext.User);

response.YourRating = rating?.ToDPad() ?? (int)RatingType.Neutral;
response.YourStarRating = rating?.ToLBP1() ?? 0;
response.YourLbp2PlayCount = dataContext.Database.GetTotalPlaysForLevelByUser(old, dataContext.User);

// this is technically invalid, but specifying this for all games ensures they all have the capacity to review if played.
// we don't store the game's version in play relations, so this is the best we can do
int plays = dataContext.Database.GetTotalPlaysForLevelByUser(old, dataContext.User);
response.YourLbp1PlayCount = plays;
response.YourLbp2PlayCount = plays;
response.YourLbp3PlayCount = plays;
}

response.PlayerCount = dataContext.Match.GetPlayerCountForLevel(RoomSlotType.Online, response.LevelId);
Expand Down

0 comments on commit d19a854

Please sign in to comment.