From d4e2940b00830af38e9ef58b80a691fc09c83481 Mon Sep 17 00:00:00 2001 From: BtbN Date: Mon, 3 Jun 2019 20:24:51 +0200 Subject: [PATCH] Save Jubility --- ClanServer/ClanServerContext.cs | 5 --- ClanServer/Controllers/L44/Gameend.cs | 38 +++++++++++++--------- ClanServer/Controllers/L44/Gametop.cs | 29 ++++++++++++++--- ClanServer/Models/JubeatClanJubility.cs | 25 ++++++++++++++ ClanServer/Models/JubeatClanProfileData.cs | 2 ++ ClanServer/Models/JubeatProfile.cs | 5 ++- 6 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 ClanServer/Models/JubeatClanJubility.cs diff --git a/ClanServer/ClanServerContext.cs b/ClanServer/ClanServerContext.cs index 767a376..ecf05fe 100644 --- a/ClanServer/ClanServerContext.cs +++ b/ClanServer/ClanServerContext.cs @@ -28,11 +28,6 @@ namespace ClanServer cardEntity .HasIndex(card => card.DataId); - var juProfEntity = modelBuilder.Entity(); - juProfEntity - .HasIndex(profile => profile.JID) - .IsUnique(); - var jbScoreEntity = modelBuilder.Entity(); jbScoreEntity .HasIndex(score => new { score.ProfileID, score.MusicID, score.Seq }) diff --git a/ClanServer/Controllers/L44/Gameend.cs b/ClanServer/Controllers/L44/Gameend.cs index 8f7243f..1dd5042 100644 --- a/ClanServer/Controllers/L44/Gameend.cs +++ b/ClanServer/Controllers/L44/Gameend.cs @@ -32,24 +32,17 @@ namespace ClanServer.Controllers.L44 XElement dataE = xrpcData.Document.Element("call").Element("gameend").Element("data"); XElement playerE = dataE.Element("player"); - byte[] refId = playerE.Element("refid").Value.ToBytesFromHex(); + int jid = int.Parse(playerE.Element("jid").Value); - Card card = await ctx.Cards - .Include(c => c.Player.JubeatProfile) - .SingleOrDefaultAsync(c => c.RefId.SequenceEqual(refId)); + JubeatProfile profile = await ctx.JubeatProfiles + .Include(p => p.ClanData) + .Include(p => p.ClanSettings) + .Include(p => p.Jubilitys) + .SingleOrDefaultAsync(p => p.ID == jid); - if (card == null) + if (profile == null) return NotFound(); - var player = card.Player; - - await ctx.Entry(player).Reference(p => p.JubeatProfile).LoadAsync(); - - var profile = player.JubeatProfile; - - await ctx.Entry(profile).Reference(p => p.ClanData).LoadAsync(); - await ctx.Entry(profile).Reference(p => p.ClanSettings).LoadAsync(); - if (profile.ClanData == null) profile.ClanData = new JubeatClanProfileData(); if (profile.ClanSettings == null) @@ -141,7 +134,22 @@ namespace ClanServer.Controllers.L44 score.MBar = Array.ConvertAll(mbarStrs, s => byte.Parse(s)); } - //TODO: save jubility, player->jubility + XElement jubility = playerE.Element("jubility"); + data.JubilityParam = int.Parse(jubility.Attribute("param").Value); + + profile.Jubilitys.Clear(); + + foreach (XElement targetMusic in jubility.Element("target_music_list").Elements("target_music")) + { + profile.Jubilitys.Add(new JubeatClanJubility() + { + MusicID = int.Parse(targetMusic.Element("music_id").Value), + Seq = sbyte.Parse(targetMusic.Element("seq").Value), + Score = int.Parse(targetMusic.Element("score").Value), + Value = int.Parse(targetMusic.Element("value").Value), + IsHardMode = targetMusic.Element("is_hard_mode").Value == "1" + }); + } await ctx.SaveChangesAsync(); diff --git a/ClanServer/Controllers/L44/Gametop.cs b/ClanServer/Controllers/L44/Gametop.cs index b4389fa..0092d9d 100644 --- a/ClanServer/Controllers/L44/Gametop.cs +++ b/ClanServer/Controllers/L44/Gametop.cs @@ -33,6 +33,8 @@ namespace ClanServer.Controllers.L44 string name = player.Element("name").Value; Card card = await ctx.Cards + .Include(c => c.Player.JubeatProfile) + .ThenInclude(p => p.Jubilitys) .Include(c => c.Player.JubeatProfile.ClanData) .Include(c => c.Player.JubeatProfile.ClanSettings) .SingleOrDefaultAsync(c => c.RefId.SequenceEqual(refId)); @@ -43,7 +45,6 @@ namespace ClanServer.Controllers.L44 if (card.Player.JubeatProfile == null) card.Player.JubeatProfile = new JubeatProfile(); - card.Player.JubeatProfile.JID = Math.Abs(new Random().Next()); card.Player.JubeatProfile.Name = name; await ctx.SaveChangesAsync(); @@ -210,7 +211,7 @@ namespace ClanServer.Controllers.L44 latestScore = new JubeatScore(); return new XElement("player", - new KS32("jid", profile.JID), + new KS32("jid", profile.ID), new KS32("session_id", 1), new KStr("name", profile.Name), new KU64("event_flag", 2), @@ -312,8 +313,8 @@ namespace ClanServer.Controllers.L44 ), new XElement("new_music"), new XElement("gift_list"), - new XElement("jubility", new XAttribute("param", "0"), - new XElement("target_music_list") + new XElement("jubility", new XAttribute("param", data.JubilityParam), + GenJubilityTargetMusicList(profile) ), new XElement("born", new KS8("status", 1), @@ -344,6 +345,24 @@ namespace ClanServer.Controllers.L44 ); } + private XElement GenJubilityTargetMusicList(JubeatProfile profile) + { + XElement res = new XElement("target_music_list"); + + foreach (JubeatClanJubility jubility in profile.Jubilitys) + { + res.Add(new XElement("target_music", + new KS32("music_id", jubility.MusicID), + new KS8("seq", jubility.Seq), + new KS32("score", jubility.Score), + new KS32("value", jubility.Value), + new KBool("is_hard_mode", jubility.IsHardMode) + )); + } + + return res; + } + private static XElement GenClanCourseList() { XElement categoryList = new XElement("category_list"); @@ -394,7 +413,7 @@ namespace ClanServer.Controllers.L44 var player = gametop.Element("data").Element("player"); int jid = int.Parse(player.Element("jid").Value); - var profile = await ctx.JubeatProfiles.SingleOrDefaultAsync(p => p.JID == jid); + var profile = await ctx.JubeatProfiles.SingleOrDefaultAsync(p => p.ID == jid); if (profile == null) return NotFound(); diff --git a/ClanServer/Models/JubeatClanJubility.cs b/ClanServer/Models/JubeatClanJubility.cs new file mode 100644 index 0000000..178e7af --- /dev/null +++ b/ClanServer/Models/JubeatClanJubility.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ClanServer.Models +{ + public class JubeatClanJubility + { + public int ID { get; set; } + + public JubeatProfile Profile { get; set; } + public int ProfileID { get; set; } + + public int MusicID { get; set; } + + public sbyte Seq { get; set; } + + public int Score { get; set; } + + public int Value { get; set; } + + public bool IsHardMode { get; set; } + } +} diff --git a/ClanServer/Models/JubeatClanProfileData.cs b/ClanServer/Models/JubeatClanProfileData.cs index 50e4371..b4fb1f3 100644 --- a/ClanServer/Models/JubeatClanProfileData.cs +++ b/ClanServer/Models/JubeatClanProfileData.cs @@ -45,5 +45,7 @@ namespace ClanServer.Models public int BonusTunePoints { get; set; } public bool BonusTunePlayed { get; set; } + + public int JubilityParam { get; set; } } } diff --git a/ClanServer/Models/JubeatProfile.cs b/ClanServer/Models/JubeatProfile.cs index b431da3..c9019ee 100644 --- a/ClanServer/Models/JubeatProfile.cs +++ b/ClanServer/Models/JubeatProfile.cs @@ -12,9 +12,6 @@ namespace ClanServer.Models public Player Player { get; set; } public int PlayerID { get; set; } - [Required] - public int JID { get; set; } - [Required] public string Name { get; set; } @@ -22,6 +19,8 @@ namespace ClanServer.Models public JubeatClanSettings ClanSettings { get; set; } + public ICollection Jubilitys { get; set; } + public ICollection Scores { get; set; } } }