top achievement points leaderboard

This commit is contained in:
Spirtix 2023-11-25 22:51:00 +01:00
parent a0e2e198da
commit c5bc21e539
10 changed files with 128 additions and 3 deletions

View File

@ -116,6 +116,7 @@ Then run School of Dragons.
- ApplyRewards - ApplyRewards
- GetGameDataByGame (friend tab displays all players - friend filter is not yet implemented because friend lists are not implemented) - GetGameDataByGame (friend tab displays all players - friend filter is not yet implemented because friend lists are not implemented)
- GetGameDataByGameForDateRange (friend tab displays all players) - GetGameDataByGameForDateRange (friend tab displays all players)
- GetTopAchievementPointUsers (ignores type [all, buddy, hall of fame, ...] and mode [overall, monthly, weekly] properties)
- GetUserAchievements (used by Magic & Mythies) - GetUserAchievements (used by Magic & Mythies)
- GetUserRoomList (room categories are not implemented, but it's enough for SoD) - GetUserRoomList (room categories are not implemented, but it's enough for SoD)
- ProcessRewardedItems (gives gems, but doesn't give gold, gold is not yet implemented) - ProcessRewardedItems (gives gems, but doesn't give gold, gold is not yet implemented)

View File

@ -84,6 +84,7 @@ methods = [
'SendRawGameData', 'SendRawGameData',
'GetGameDataByGame', 'GetGameDataByGame',
'GetGameDataByGameForDateRange', 'GetGameDataByGameForDateRange',
'GetTopAchievementPointUsers',
] ]
def routable(path): def routable(path):

View File

@ -204,4 +204,13 @@ public class AchievementController : Controller {
return Ok(rewards); return Ok(rewards);
} }
[HttpPost]
[Produces("application/xml")]
[Route("V2/AchievementWebService.asmx/GetTopAchievementPointUsers")]
[VikingSession]
public IActionResult GetTopAchievementPointUsers(string request) {
UserAchievementInfoRequest infoRequest = XmlUtil.DeserializeXml<UserAchievementInfoRequest>(request);
return Ok(achievementService.GetTopAchievementUsers(infoRequest));
}
} }

View File

@ -14,8 +14,9 @@ public class DBContext : DbContext {
public DbSet<MissionState> MissionStates { get; set; } = null!; public DbSet<MissionState> MissionStates { get; set; } = null!;
public DbSet<Room> Rooms { get; set; } = null!; public DbSet<Room> Rooms { get; set; } = null!;
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<AchievementPoints> AchievementPoints { get; set; } = null!;
public string DbPath { get; } public string DbPath { get; }

13
src/Schema/DateRange.cs Normal file
View File

@ -0,0 +1,13 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
[XmlRoot(ElementName = "R", Namespace = "")]
[Serializable]
public class DateRange {
[XmlElement(ElementName = "SD")]
public DateTime? StartDate;
[XmlElement(ElementName = "ED")]
public DateTime? EndDate;
}

14
src/Schema/ModeType.cs Normal file
View File

@ -0,0 +1,14 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
public enum ModeType {
[XmlEnum("1")]
AllTime = 1,
[XmlEnum("2")]
Daily,
[XmlEnum("3")]
Weekly,
[XmlEnum("4")]
Monthly
}

16
src/Schema/RequestType.cs Normal file
View File

@ -0,0 +1,16 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
public enum RequestType {
[XmlEnum("1")]
All = 1,
[XmlEnum("2")]
Buddy,
[XmlEnum("3")]
Group,
[XmlEnum("4")]
Facebook,
[XmlEnum("5")]
HallOfFame
}

View File

@ -0,0 +1,31 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
[XmlRoot(ElementName = "AREQ", Namespace = "")]
[Serializable]
public class UserAchievementInfoRequest {
[XmlElement(ElementName = "PID")]
public int ProductGroupID;
[XmlElement(ElementName = "UID")]
public Guid UserID;
[XmlElement(ElementName = "PTID")]
public int PointTypeID;
[XmlElement(ElementName = "T")]
public RequestType Type;
[XmlElement(ElementName = "M")]
public ModeType Mode;
[XmlElement(ElementName = "P")]
public int Page;
[XmlElement(ElementName = "Q")]
public int Quantity;
[XmlElement(ElementName = "FBIDS")]
public List<long> FacebookUserIDs;
}

View File

@ -0,0 +1,13 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
[XmlRoot(ElementName = "UAIR", Namespace = "")]
[Serializable]
public class UserAchievementInfoResponse {
[XmlElement(ElementName = "UAI")]
public UserAchievementInfo[] AchievementInfo;
[XmlElement(ElementName = "DR")]
public DateRange DateRange;
}

View File

@ -9,10 +9,12 @@ namespace sodoff.Services {
public class AchievementService { public class AchievementService {
private AchievementStoreSingleton achievementStore; private AchievementStoreSingleton achievementStore;
private InventoryService inventoryService; private InventoryService inventoryService;
public readonly DBContext ctx;
public AchievementService(AchievementStoreSingleton achievementStore, InventoryService inventoryService) { public AchievementService(AchievementStoreSingleton achievementStore, InventoryService inventoryService, DBContext ctx) {
this.achievementStore = achievementStore; this.achievementStore = achievementStore;
this.inventoryService = inventoryService; this.inventoryService = inventoryService;
this.ctx = ctx;
} }
public UserAchievementInfo CreateUserAchievementInfo(Guid userId, int? value, AchievementPointTypes type) { public UserAchievementInfo CreateUserAchievementInfo(Guid userId, int? value, AchievementPointTypes type) {
@ -162,5 +164,29 @@ namespace sodoff.Services {
UserID = viking.Uid UserID = viking.Uid
}; };
} }
public UserAchievementInfoResponse GetTopAchievementUsers(UserAchievementInfoRequest request) {
// TODO: Type and mode are currently ignored
List<UserAchievementInfo> achievementInfo = new();
var topAchievers = ctx.AchievementPoints.Where(x => x.Type == request.PointTypeID)
.Select(e => new { e.Viking.Uid, e.Viking.Name, e.Value })
.Skip((request.Page - 1) * request.Quantity)
.Take(request.Quantity)
.OrderByDescending(e => e.Value);
foreach (var a in topAchievers) {
achievementInfo.Add(new UserAchievementInfo {
UserID = a.Uid,
UserName = a.Name,
AchievementPointTotal = a.Value,
PointTypeID = (AchievementPointTypes)request.PointTypeID
});
}
return new UserAchievementInfoResponse {
AchievementInfo = achievementInfo.ToArray(),
DateRange = new DateRange()
};
}
} }
} }