Save Jubility

This commit is contained in:
BtbN 2019-06-03 20:24:51 +02:00
parent fe0a2d25c4
commit 8275516d7a
6 changed files with 76 additions and 28 deletions

View File

@ -28,11 +28,6 @@ namespace ClanServer
cardEntity
.HasIndex(card => card.DataId);
var juProfEntity = modelBuilder.Entity<JubeatProfile>();
juProfEntity
.HasIndex(profile => profile.JID)
.IsUnique();
var jbScoreEntity = modelBuilder.Entity<JubeatScore>();
jbScoreEntity
.HasIndex(score => new { score.ProfileID, score.MusicID, score.Seq })

View File

@ -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();

View File

@ -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();

View File

@ -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; }
}
}

View File

@ -45,5 +45,7 @@ namespace ClanServer.Models
public int BonusTunePoints { get; set; }
public bool BonusTunePlayed { get; set; }
public int JubilityParam { get; set; }
}
}

View File

@ -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<JubeatClanJubility> Jubilitys { get; set; }
public ICollection<JubeatScore> Scores { get; set; }
}
}