mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-11-27 18:16:53 -08:00
Merge 13427e1c6fa5de8719f0dce69aa2e11d606ed71b into 83526569c1341353f2f63c2fa8d902dc0ddfd94f
This commit is contained in:
commit
0472da5f52
@ -2146,7 +2146,7 @@ public class ContentController : Controller {
|
|||||||
[Route("ContentWebService.asmx/GetPeriodicGameDataByGame")] // used by Math Blaster and WoJS (probably from 24 hours ago to now)
|
[Route("ContentWebService.asmx/GetPeriodicGameDataByGame")] // used by Math Blaster and WoJS (probably from 24 hours ago to now)
|
||||||
[VikingSession(UseLock = true)]
|
[VikingSession(UseLock = true)]
|
||||||
public IActionResult GetPeriodicGameDataByGame(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 GetPeriodicGameDataByGame(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, DateTime.Now.AddHours(-24), DateTime.Now));
|
return Ok(gameDataService.GetDailyGameData(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, buddyFilter, apiKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|||||||
@ -10,6 +10,7 @@ public class GameDataPair {
|
|||||||
public int GameDataId { get; set; }
|
public int GameDataId { get; set; }
|
||||||
public string Name { get; set; } = null!;
|
public string Name { get; set; } = null!;
|
||||||
public int Value { get; set; }
|
public int Value { get; set; }
|
||||||
|
public int DailyValue { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public virtual GameData GameData { get; set; } = null!;
|
public virtual GameData GameData { get; set; } = null!;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,30 +31,32 @@ public class GameDataService {
|
|||||||
viking.GameData.Add(gameData);
|
viking.GameData.Add(gameData);
|
||||||
|
|
||||||
}
|
}
|
||||||
gameData.DatePlayed = DateTime.UtcNow;
|
|
||||||
SavePairs(gameData, xmlDocumentData);
|
SavePairs(gameData, xmlDocumentData);
|
||||||
|
gameData.DatePlayed = DateTime.UtcNow;
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<GameDataResponse> GameDataResponseToList(IQueryable<Model.GameData> originalQuery, string key, int count, bool AscendingOrder, string apiKey) {
|
List<GameDataResponse> GameDataResponseToList(IQueryable<Model.GameData> originalQuery, string key, int count, bool AscendingOrder, string apiKey, bool daily=false) {
|
||||||
var query = originalQuery.SelectMany(e => e.GameDataPairs)
|
var query = originalQuery.SelectMany(e => e.GameDataPairs)
|
||||||
.Where(x => x.Name == key);
|
.Where(x => x.Name == key);
|
||||||
|
|
||||||
if (AscendingOrder)
|
if (AscendingOrder)
|
||||||
query = query.OrderBy(e => e.Value);
|
query = query.OrderBy(e => daily ? e.DailyValue : e.Value);
|
||||||
else
|
else
|
||||||
query = query.OrderByDescending(e => e.Value);
|
query = query.OrderByDescending(e => daily ? e.DailyValue : e.Value);
|
||||||
|
|
||||||
uint gameVersion = ClientVersion.GetVersion(apiKey);
|
uint gameVersion = ClientVersion.GetVersion(apiKey);
|
||||||
if (gameVersion <= ClientVersion.Max_OldJS)
|
if (gameVersion <= ClientVersion.Max_OldJS)
|
||||||
// use DisplayName instead of Name
|
// use DisplayName instead of Name
|
||||||
return query.Select(e => new GameDataResponse(
|
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)
|
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, daily ? e.DailyValue : e.Value)
|
||||||
).Take(count).ToList();
|
).Take(count).ToList();
|
||||||
else
|
else
|
||||||
return query.Select(e => new GameDataResponse(
|
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)
|
e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, daily ? e.DailyValue : e.Value)
|
||||||
).Take(count).ToList();
|
).Take(count).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +73,20 @@ public class GameDataService {
|
|||||||
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameDataSummary GetDailyGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, bool buddyFilter, string apiKey) {
|
||||||
|
IQueryable<Model.GameData> query = ctx.GameData
|
||||||
|
.Where(x =>
|
||||||
|
x.GameId == gameId && x.IsMultiplayer == false &&
|
||||||
|
x.Difficulty == difficulty && x.GameLevel == gameLevel &&
|
||||||
|
x.DatePlayed.Date == DateTime.UtcNow.Date);
|
||||||
|
|
||||||
|
// TODO: Buddy filter
|
||||||
|
|
||||||
|
List<GameDataResponse> selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey, true);
|
||||||
|
|
||||||
|
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
|
||||||
|
}
|
||||||
|
|
||||||
// ByUser for JumpStart's My Scores
|
// 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) {
|
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);
|
IQueryable<Model.GameData> query = ctx.GameData.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel && x.VikingId == viking.Id);
|
||||||
@ -141,12 +157,20 @@ public class GameDataService {
|
|||||||
private void SavePairs(Model.GameData gameData, string xmlDocumentData) {
|
private void SavePairs(Model.GameData gameData, string xmlDocumentData) {
|
||||||
foreach (var pair in GetGameDataPairs(xmlDocumentData)) {
|
foreach (var pair in GetGameDataPairs(xmlDocumentData)) {
|
||||||
GameDataPair? dbPair = gameData.GameDataPairs.FirstOrDefault(x => x.Name == pair.Name);
|
GameDataPair? dbPair = gameData.GameDataPairs.FirstOrDefault(x => x.Name == pair.Name);
|
||||||
if (dbPair == null)
|
|
||||||
|
// If the score type is "time", use newBest <= existing (newest time is smaller than (or the same as) existing time).
|
||||||
|
// For anything else, use newBest > existing (newest score is larger than existing score).
|
||||||
|
bool newBest = (dbPair == null) || ((pair.Name == "time") != (dbPair.Value <= pair.Value));
|
||||||
|
|
||||||
|
if (dbPair == null) {
|
||||||
gameData.GameDataPairs.Add(pair);
|
gameData.GameDataPairs.Add(pair);
|
||||||
else if (pair.Name == "time" && dbPair.Value > pair.Value)
|
dbPair = pair;
|
||||||
dbPair.Value = pair.Value;
|
} else if (newBest) dbPair.Value = pair.Value;
|
||||||
else if (pair.Name != "time" && dbPair.Value <= pair.Value)
|
|
||||||
dbPair.Value = pair.Value;
|
if (
|
||||||
|
newBest || // Surpassed Score (or Unset)
|
||||||
|
gameData.DatePlayed.Date != DateTime.UtcNow.Date // Another Day
|
||||||
|
) dbPair.DailyValue = pair.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user