forked from SoDOff-Project/sodoff
Implemented `GetGameDataByUser
`
This commit is contained in:
parent
363ea6a305
commit
2ec4358a39
@ -105,6 +105,7 @@ Almost everything:
|
|||||||
- GetDefaultNameSuggestion
|
- GetDefaultNameSuggestion
|
||||||
- GetDetailedChildList
|
- GetDetailedChildList
|
||||||
- GetGameData
|
- GetGameData
|
||||||
|
- GetGameDataByUser
|
||||||
- GetImage
|
- GetImage
|
||||||
- GetImageByUserId
|
- GetImageByUserId
|
||||||
- GetItem
|
- GetItem
|
||||||
|
@ -84,6 +84,7 @@ methods = [
|
|||||||
'SendRawGameData',
|
'SendRawGameData',
|
||||||
'GetGameData',
|
'GetGameData',
|
||||||
'GetGameDataByGame',
|
'GetGameDataByGame',
|
||||||
|
'GetGameDataByUser',
|
||||||
'GetGameDataByGameForDateRange',
|
'GetGameDataByGameForDateRange',
|
||||||
'GetTopAchievementPointUsers',
|
'GetTopAchievementPointUsers',
|
||||||
'SetDisplayName',
|
'SetDisplayName',
|
||||||
|
@ -2076,6 +2076,14 @@ public class ContentController : Controller {
|
|||||||
public IActionResult GetGameDataByGame(Viking viking, [FromForm] int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, int score, bool buddyFilter, string apiKey) {
|
public IActionResult GetGameDataByGame(Viking viking, [FromForm] int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, int score, bool buddyFilter, string apiKey) {
|
||||||
return Ok(gameDataService.GetGameData(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, buddyFilter, apiKey));
|
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]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
|
@ -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) {
|
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);
|
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 {
|
gameData = new Model.GameData {
|
||||||
GameId = gameId,
|
GameId = gameId,
|
||||||
IsMultiplayer = isMultiplayer,
|
IsMultiplayer = isMultiplayer,
|
||||||
@ -33,39 +36,46 @@ public class GameDataService {
|
|||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
return true;
|
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) {
|
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);
|
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)
|
if (startDate != null && endDate != null)
|
||||||
query = query.Where(x => x.DatePlayed >= startDate.Value.ToUniversalTime() && x.DatePlayed <= endDate.Value.AddMinutes(2).ToUniversalTime());
|
query = query.Where(x => x.DatePlayed >= startDate.Value.ToUniversalTime() && x.DatePlayed <= endDate.Value.AddMinutes(2).ToUniversalTime());
|
||||||
|
|
||||||
var query2 = query.SelectMany(e => e.GameDataPairs)
|
List<GameDataResponse> selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey);
|
||||||
.Where(x => x.Name == key);
|
|
||||||
|
|
||||||
uint gameVersion = ClientVersion.GetVersion(apiKey);
|
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
||||||
if (gameVersion <= ClientVersion.Max_OldJS) {
|
}
|
||||||
// use DisplayName instead of Name
|
|
||||||
if (AscendingOrder)
|
// ByUser for JumpStart's My Scores
|
||||||
selectedData = query2.OrderBy(e => e.Value).Select(e => new GameDataResponse(
|
public GameDataSummary GetGameDataByUser(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, string apiKey) {
|
||||||
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value)
|
IQueryable<Model.GameData> query = ctx.GameData.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel && x.VikingId == viking.Id);
|
||||||
).Take(count).ToList();
|
|
||||||
else
|
List<GameDataResponse> selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey);
|
||||||
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);
|
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user