mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 16:28:50 -07:00
Daily Scoreboard now works correctly.
This commit is contained in:
parent
8e141ab43d
commit
66bb9f0a82
@ -2150,7 +2150,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]
|
||||||
|
@ -19,6 +19,8 @@ public class DBContext : DbContext {
|
|||||||
public DbSet<RoomItem> RoomItems { get; set; } = null!;
|
public DbSet<RoomItem> RoomItems { get; set; } = null!;
|
||||||
public DbSet<GameData> GameData { get; set; } = null!;
|
public DbSet<GameData> GameData { get; set; } = null!;
|
||||||
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
|
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
|
||||||
|
public DbSet<DailyHighscore> DailyHighscores { get; set; } = null!;
|
||||||
|
public DbSet<DailyHighscorePair> DailyHighscorePairs { get; set; } = null!;
|
||||||
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
|
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
|
||||||
public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
public DbSet<MMORole> MMORoles { get; set; } = null!;
|
public DbSet<MMORole> MMORoles { get; set; } = null!;
|
||||||
@ -129,6 +131,9 @@ public class DBContext : DbContext {
|
|||||||
builder.Entity<Viking>().HasMany(v => v.GameData)
|
builder.Entity<Viking>().HasMany(v => v.GameData)
|
||||||
.WithOne(e => e.Viking);
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
|
builder.Entity<Viking>().HasMany(v => v.DailyHighscores)
|
||||||
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
builder.Entity<Viking>().HasMany(v => v.SavedData)
|
builder.Entity<Viking>().HasMany(v => v.SavedData)
|
||||||
.WithOne(e => e.Viking);
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
@ -222,6 +227,15 @@ public class DBContext : DbContext {
|
|||||||
builder.Entity<GameDataPair>().HasOne(e => e.GameData)
|
builder.Entity<GameDataPair>().HasOne(e => e.GameData)
|
||||||
.WithMany(e => e.GameDataPairs);
|
.WithMany(e => e.GameDataPairs);
|
||||||
|
|
||||||
|
builder.Entity<DailyHighscore>().HasOne(e => e.Viking)
|
||||||
|
.WithMany(e => e.DailyHighscores);
|
||||||
|
|
||||||
|
builder.Entity<DailyHighscore>().HasMany(e => e.ScorePairs)
|
||||||
|
.WithOne(e => e.DailyScore);
|
||||||
|
|
||||||
|
builder.Entity<DailyHighscorePair>().HasOne(e => e.DailyScore)
|
||||||
|
.WithMany(e => e.ScorePairs);
|
||||||
|
|
||||||
// Others ..
|
// Others ..
|
||||||
builder.Entity<Image>().HasOne(s => s.Viking)
|
builder.Entity<Image>().HasOne(s => s.Viking)
|
||||||
.WithMany(e => e.Images)
|
.WithMany(e => e.Images)
|
||||||
|
15
src/Model/DailyHighscore.cs
Normal file
15
src/Model/DailyHighscore.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace sodoff.Model;
|
||||||
|
|
||||||
|
public class DailyHighscore {
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int VikingId { get; set; }
|
||||||
|
public int GameId { get; set; }
|
||||||
|
public int Difficulty { get; set; }
|
||||||
|
public int GameLevel { get; set; }
|
||||||
|
public bool IsMultiplayer { get; set; }
|
||||||
|
public virtual ICollection<DailyHighscorePair> ScorePairs { get; set; } = null!;
|
||||||
|
public virtual Viking Viking { get; set; } = null!;
|
||||||
|
}
|
13
src/Model/DailyHighscorePair.cs
Normal file
13
src/Model/DailyHighscorePair.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace sodoff.Model;
|
||||||
|
|
||||||
|
public class DailyHighscorePair {
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int DailyScoreId { get; set; }
|
||||||
|
public string Name { get; set; } = null!;
|
||||||
|
public int Value { get; set; }
|
||||||
|
public DateTime DatePlayed { get; set; }
|
||||||
|
public virtual DailyHighscore DailyScore { get; set; } = null!;
|
||||||
|
}
|
@ -34,6 +34,7 @@ public class Viking {
|
|||||||
public virtual ICollection<PairData> PairData { get; set; } = null!;
|
public virtual ICollection<PairData> PairData { get; set; } = null!;
|
||||||
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
||||||
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
||||||
|
public virtual ICollection<DailyHighscore> DailyHighscores { get; set; } = null!;
|
||||||
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
public virtual ICollection<SavedData> SavedData { get; set; } = null!;
|
public virtual ICollection<SavedData> SavedData { get; set; } = null!;
|
||||||
public virtual ICollection<Party> Parties { get; set; } = null!;
|
public virtual ICollection<Party> Parties { get; set; } = null!;
|
||||||
|
@ -32,8 +32,21 @@ public class GameDataService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
gameData.DatePlayed = DateTime.UtcNow;
|
gameData.DatePlayed = DateTime.UtcNow;
|
||||||
SavePairs(gameData, xmlDocumentData);
|
|
||||||
|
DailyHighscore? daily = viking.DailyHighscores.FirstOrDefault(x => x.GameId == gameId && x.IsMultiplayer == isMultiplayer && x.Difficulty == difficulty && x.GameLevel == gameLevel);
|
||||||
|
if (daily == null) {
|
||||||
|
daily = new DailyHighscore {
|
||||||
|
GameId = gameId,
|
||||||
|
Difficulty = difficulty,
|
||||||
|
GameLevel = gameLevel,
|
||||||
|
IsMultiplayer = isMultiplayer,
|
||||||
|
ScorePairs = new List<DailyHighscorePair>()
|
||||||
|
};
|
||||||
|
viking.DailyHighscores.Add(daily);
|
||||||
|
}
|
||||||
|
SavePairs(gameData, daily, xmlDocumentData);
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +83,30 @@ 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<DailyHighscorePair> query = ctx.DailyHighscores
|
||||||
|
.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel)
|
||||||
|
.SelectMany(e => e.ScorePairs).Where(x => x.DatePlayed == DateTime.Today && x.Name == key);
|
||||||
|
|
||||||
|
// TODO: Buddy filter
|
||||||
|
|
||||||
|
if (AscendingOrder) query = query.OrderBy(e => e.Value);
|
||||||
|
else query = query.OrderByDescending(e => e.Value);
|
||||||
|
|
||||||
|
List<GameDataResponse> selectedData;
|
||||||
|
if (ClientVersion.GetVersion(apiKey) <= ClientVersion.Max_OldJS)
|
||||||
|
// use DisplayName instead of Name
|
||||||
|
selectedData = query.Select(e => new GameDataResponse(
|
||||||
|
XmlUtil.DeserializeXml<AvatarData>(e.DailyScore.Viking.AvatarSerialized).DisplayName, e.DailyScore.Viking.Uid, e.DatePlayed, false, false, e.Value)
|
||||||
|
).Take(count).ToList();
|
||||||
|
else
|
||||||
|
selectedData = query.Select(e => new GameDataResponse(
|
||||||
|
e.DailyScore.Viking.Name, e.DailyScore.Viking.Uid, e.DatePlayed, false, false, e.Value)
|
||||||
|
).Take(count).ToList();
|
||||||
|
|
||||||
|
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) {
|
||||||
@ -138,7 +175,7 @@ public class GameDataService {
|
|||||||
return gameData;
|
return gameData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SavePairs(Model.GameData gameData, string xmlDocumentData) {
|
private void SavePairs(Model.GameData gameData, DailyHighscore daily, 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 (dbPair == null)
|
||||||
@ -147,6 +184,27 @@ public class GameDataService {
|
|||||||
dbPair.Value = pair.Value;
|
dbPair.Value = pair.Value;
|
||||||
else if (pair.Name != "time" && dbPair.Value <= pair.Value)
|
else if (pair.Name != "time" && dbPair.Value <= pair.Value)
|
||||||
dbPair.Value = pair.Value;
|
dbPair.Value = pair.Value;
|
||||||
|
|
||||||
|
DailyHighscorePair? dailyPair = daily.ScorePairs.FirstOrDefault(x => x.Name == pair.Name);
|
||||||
|
if (dailyPair == null) {
|
||||||
|
daily.Difficulty = gameData.Difficulty;
|
||||||
|
daily.GameLevel = gameData.GameLevel;
|
||||||
|
dailyPair = new DailyHighscorePair {
|
||||||
|
Name = pair.Name,
|
||||||
|
Value = pair.Value,
|
||||||
|
DatePlayed = DateTime.Today
|
||||||
|
};
|
||||||
|
daily.ScorePairs.Add(dailyPair);
|
||||||
|
} else if (
|
||||||
|
(pair.Name == "time" && dailyPair.Value > pair.Value) || // Better Time
|
||||||
|
(pair.Name != "time" && dailyPair.Value <= pair.Value) || // Better Score
|
||||||
|
dailyPair.DatePlayed != DateTime.Today // Another Day
|
||||||
|
) {
|
||||||
|
daily.Difficulty = gameData.Difficulty;
|
||||||
|
daily.GameLevel = gameData.GameLevel;
|
||||||
|
dailyPair.DatePlayed = DateTime.Today;
|
||||||
|
dailyPair.Value = pair.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user