forked from SoDOff-Project/sodoff
Implemented `GetGameDataByUser
`
This commit is contained in:
parent
363ea6a305
commit
2ec4358a39
@ -105,6 +105,7 @@ Almost everything:
|
||||
- GetDefaultNameSuggestion
|
||||
- GetDetailedChildList
|
||||
- GetGameData
|
||||
- GetGameDataByUser
|
||||
- GetImage
|
||||
- GetImageByUserId
|
||||
- GetItem
|
||||
|
@ -84,6 +84,7 @@ methods = [
|
||||
'SendRawGameData',
|
||||
'GetGameData',
|
||||
'GetGameDataByGame',
|
||||
'GetGameDataByUser',
|
||||
'GetGameDataByGameForDateRange',
|
||||
'GetTopAchievementPointUsers',
|
||||
'SetDisplayName',
|
||||
|
@ -2077,6 +2077,14 @@ public class ContentController : Controller {
|
||||
return Ok(gameDataService.GetGameData(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, buddyFilter, apiKey));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/GetGameDataByUser")] // used in My Scores
|
||||
[VikingSession(UseLock = true)]
|
||||
public IActionResult GetGameDataByUser(Viking viking, [FromForm] int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, string apiKey) {
|
||||
return Ok(gameDataService.GetGameDataByUser(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, apiKey));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/GetGameDataByGameForDateRange")]
|
||||
|
@ -14,8 +14,11 @@ public class GameDataService {
|
||||
}
|
||||
|
||||
public bool SaveGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string xmlDocumentData, bool win, bool loss) {
|
||||
//TODO: save only unique scores; scores that the player hasn't hit yet, probably keep old date for existing scores
|
||||
//or don't if you want ultra-unique scores (overwriting even the old score)
|
||||
Model.GameData? gameData = viking.GameData.FirstOrDefault(x => x.GameId == gameId && x.IsMultiplayer == isMultiplayer && x.Difficulty == difficulty && x.GameLevel == gameLevel && x.Win == win && x.Loss == loss);
|
||||
if (gameData == null) {
|
||||
|
||||
if (gameData == null) { //comment this check to turn off ultra-unique scores (for now)
|
||||
gameData = new Model.GameData {
|
||||
GameId = gameId,
|
||||
IsMultiplayer = isMultiplayer,
|
||||
@ -34,39 +37,46 @@ public class GameDataService {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<GameDataResponse> GameDataResponseToList(IQueryable<Model.GameData> originalQuery, string key, int count, bool AscendingOrder, string apiKey) {
|
||||
var query = originalQuery.SelectMany(e => e.GameDataPairs)
|
||||
.Where(x => x.Name == key);
|
||||
|
||||
if (AscendingOrder)
|
||||
query = query.OrderBy(e => e.Value);
|
||||
else
|
||||
query = query.OrderByDescending(e => e.Value);
|
||||
|
||||
uint gameVersion = ClientVersion.GetVersion(apiKey);
|
||||
if (gameVersion <= ClientVersion.Max_OldJS)
|
||||
// use DisplayName instead of Name
|
||||
return query.Select(e => new GameDataResponse(
|
||||
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
||||
).Take(count).ToList();
|
||||
else
|
||||
return query.Select(e => new GameDataResponse(
|
||||
e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
||||
).Take(count).ToList();
|
||||
}
|
||||
|
||||
public GameDataSummary GetGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, bool buddyFilter, string apiKey, DateTime? startDate = null, DateTime? endDate = null) {
|
||||
// TODO: Buddy filter
|
||||
List<GameDataResponse> selectedData;
|
||||
IQueryable<Model.GameData> query = ctx.GameData.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel);
|
||||
|
||||
// TODO: Buddy filter
|
||||
|
||||
if (startDate != null && endDate != null)
|
||||
query = query.Where(x => x.DatePlayed >= startDate.Value.ToUniversalTime() && x.DatePlayed <= endDate.Value.AddMinutes(2).ToUniversalTime());
|
||||
|
||||
var query2 = query.SelectMany(e => e.GameDataPairs)
|
||||
.Where(x => x.Name == key);
|
||||
List<GameDataResponse> selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey);
|
||||
|
||||
uint gameVersion = ClientVersion.GetVersion(apiKey);
|
||||
if (gameVersion <= ClientVersion.Max_OldJS) {
|
||||
// use DisplayName instead of Name
|
||||
if (AscendingOrder)
|
||||
selectedData = query2.OrderBy(e => e.Value).Select(e => new GameDataResponse(
|
||||
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
||||
).Take(count).ToList();
|
||||
else
|
||||
selectedData = query2.OrderByDescending(e => e.Value).Select(e => new GameDataResponse(
|
||||
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
||||
).Take(count).ToList();
|
||||
} else {
|
||||
if (AscendingOrder)
|
||||
selectedData = query2.OrderBy(e => e.Value).Select(e => new GameDataResponse(
|
||||
e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
||||
).Take(count).ToList();
|
||||
else
|
||||
selectedData = query2.OrderByDescending(e => e.Value).Select(e => new GameDataResponse(
|
||||
e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
||||
).Take(count).ToList();
|
||||
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
||||
}
|
||||
|
||||
// ByUser for JumpStart's My Scores
|
||||
public GameDataSummary GetGameDataByUser(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, string apiKey) {
|
||||
IQueryable<Model.GameData> query = ctx.GameData.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel && x.VikingId == viking.Id);
|
||||
|
||||
List<GameDataResponse> selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey);
|
||||
|
||||
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user