diff --git a/TaikoLocalServer/Controllers/Game/BaidController.cs b/TaikoLocalServer/Controllers/Game/BaidController.cs index 9e4a988..ea79fbf 100644 --- a/TaikoLocalServer/Controllers/Game/BaidController.cs +++ b/TaikoLocalServer/Controllers/Game/BaidController.cs @@ -113,10 +113,7 @@ public class BaidController : BaseController var genericInfoFlgLength = genericInfoFlg.Any()? genericInfoFlg.Max() + 1 : 0; var genericInfoFlgArray = FlagCalculator.GetBitArrayFromIds(genericInfoFlg, (int)genericInfoFlgLength, Logger); - - var aiScores = await aiDatumService.GetAllAiScoreById(baid); - var totalWin = aiScores.Count(datum => datum.IsWin); - + response = new BAIDResponse { Result = 1, @@ -164,7 +161,7 @@ public class BaidController : BaseController LastPlayMode = userData.LastPlayMode, IsDispSouuchiOn = true, AiRank = 1, - AiTotalWin = (uint)totalWin, + AiTotalWin = (uint)userData.AiWinCount, Accesstoken = "123456", ContentInfo = GZipBytesUtil.GetGZipBytes(new byte[10]) }; diff --git a/TaikoLocalServer/Controllers/Game/GetAiDataController.cs b/TaikoLocalServer/Controllers/Game/GetAiDataController.cs index 2880229..e31f8e6 100644 --- a/TaikoLocalServer/Controllers/Game/GetAiDataController.cs +++ b/TaikoLocalServer/Controllers/Game/GetAiDataController.cs @@ -1,14 +1,16 @@ -namespace TaikoLocalServer.Controllers.Game; +using Throw; + +namespace TaikoLocalServer.Controllers.Game; [Route("/v12r03/chassis/getaidata.php")] [ApiController] public class GetAiDataController : BaseController { - private readonly IAiDatumService aiDatumService; + private readonly IUserDatumService userDatumService; - public GetAiDataController(IAiDatumService aiDatumService) + public GetAiDataController(IUserDatumService userDatumService) { - this.aiDatumService = aiDatumService; + this.userDatumService = userDatumService; } [HttpPost] @@ -17,12 +19,12 @@ public class GetAiDataController : BaseController { Logger.LogInformation("GetAiData request : {Request}", request.Stringify()); - var aiScoreData = await aiDatumService.GetAllAiScoreById(request.Baid); - var totalWin = aiScoreData.Count(datum => datum.IsWin); + var user = await userDatumService.GetFirstUserDatumOrNull(request.Baid); + user.ThrowIfNull($"User with baid {request.Baid} does not exist!"); var response = new GetAiDataResponse { Result = 1, - TotalWinnings = (uint)totalWin, + TotalWinnings = (uint)user.AiWinCount, InputMedian = "1000", InputVariance = "2000" }; diff --git a/TaikoLocalServer/Controllers/Game/PlayResultController.cs b/TaikoLocalServer/Controllers/Game/PlayResultController.cs index 6ed4642..4a3c50e 100644 --- a/TaikoLocalServer/Controllers/Game/PlayResultController.cs +++ b/TaikoLocalServer/Controllers/Game/PlayResultController.cs @@ -223,6 +223,7 @@ public class PlayResultController : BaseController userdata.GenericInfoFlgArray = UpdateJsonUintFlagArray(userdata.GenericInfoFlgArray, playResultData.GetGenericInfoNoes, nameof(userdata.GenericInfoFlgArray)); + userdata.AiWinCount += playResultData.AryStageInfoes.Count(data => data.IsWin); await userDatumService.UpdateUserDatum(userdata); } @@ -352,7 +353,9 @@ public class PlayResultController : BaseController Baid = request.BaidConf, SongId = stageData.SongNo, Difficulty = difficulty, - SectionIndex = index + SectionIndex = index, + OkCount = sectionData.OkCnt, + MissCount = sectionData.NgCnt }; aiSectionScoreDatum.UpdateBest(sectionData); aiScoreDatum.AiSectionScoreData.Add(aiSectionScoreDatum); diff --git a/TaikoLocalServer/Entities/UserDatum.cs b/TaikoLocalServer/Entities/UserDatum.cs index 21d0653..04723e7 100644 --- a/TaikoLocalServer/Entities/UserDatum.cs +++ b/TaikoLocalServer/Entities/UserDatum.cs @@ -26,6 +26,7 @@ public bool DisplayAchievement { get; set; } public Difficulty AchievementDisplayDifficulty { get; set; } + public int AiWinCount { get; set; } public virtual Card? Ba { get; set; } } } diff --git a/TaikoLocalServer/Migrations/20220919022643_AddWinCountToUserdata.Designer.cs b/TaikoLocalServer/Migrations/20220919022643_AddWinCountToUserdata.Designer.cs new file mode 100644 index 0000000..73f5e92 --- /dev/null +++ b/TaikoLocalServer/Migrations/20220919022643_AddWinCountToUserdata.Designer.cs @@ -0,0 +1,435 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TaikoLocalServer.Context; + +#nullable disable + +namespace TaikoLocalServer.Migrations +{ + [DbContext(typeof(TaikoDbContext))] + [Migration("20220919022643_AddWinCountToUserdata")] + partial class AddWinCountToUserdata + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.0-preview.7.22376.2"); + + modelBuilder.Entity("TaikoLocalServer.Entities.AiScoreDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("SongId") + .HasColumnType("INTEGER"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("IsWin") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "SongId", "Difficulty"); + + b.ToTable("AiScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.AiSectionScoreDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("SongId") + .HasColumnType("INTEGER"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("SectionIndex") + .HasColumnType("INTEGER"); + + b.Property("Crown") + .HasColumnType("INTEGER"); + + b.Property("DrumrollCount") + .HasColumnType("INTEGER"); + + b.Property("GoodCount") + .HasColumnType("INTEGER"); + + b.Property("IsWin") + .HasColumnType("INTEGER"); + + b.Property("MissCount") + .HasColumnType("INTEGER"); + + b.Property("OkCount") + .HasColumnType("INTEGER"); + + b.Property("Score") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "SongId", "Difficulty", "SectionIndex"); + + b.ToTable("AiSectionScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.Card", b => + { + b.Property("AccessCode") + .HasColumnType("TEXT"); + + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.HasKey("AccessCode"); + + b.HasIndex(new[] { "Baid" }, "IX_Card_Baid") + .IsUnique(); + + b.ToTable("Card", (string)null); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanScoreDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("DanId") + .HasColumnType("INTEGER"); + + b.Property("ArrivalSongCount") + .HasColumnType("INTEGER"); + + b.Property("ClearState") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(0u); + + b.Property("ComboCountTotal") + .HasColumnType("INTEGER"); + + b.Property("SoulGaugeTotal") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "DanId"); + + b.ToTable("DanScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanStageScoreDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("DanId") + .HasColumnType("INTEGER"); + + b.Property("SongNumber") + .HasColumnType("INTEGER"); + + b.Property("BadCount") + .HasColumnType("INTEGER"); + + b.Property("ComboCount") + .HasColumnType("INTEGER"); + + b.Property("DrumrollCount") + .HasColumnType("INTEGER"); + + b.Property("GoodCount") + .HasColumnType("INTEGER"); + + b.Property("HighScore") + .HasColumnType("INTEGER"); + + b.Property("OkCount") + .HasColumnType("INTEGER"); + + b.Property("PlayScore") + .HasColumnType("INTEGER"); + + b.Property("TotalHitCount") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "DanId", "SongNumber"); + + b.ToTable("DanStageScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongBestDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("SongId") + .HasColumnType("INTEGER"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("BestCrown") + .HasColumnType("INTEGER"); + + b.Property("BestRate") + .HasColumnType("INTEGER"); + + b.Property("BestScore") + .HasColumnType("INTEGER"); + + b.Property("BestScoreRank") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "SongId", "Difficulty"); + + b.ToTable("SongBestData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongPlayDatum", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("ComboCount") + .HasColumnType("INTEGER"); + + b.Property("Crown") + .HasColumnType("INTEGER"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("DrumrollCount") + .HasColumnType("INTEGER"); + + b.Property("GoodCount") + .HasColumnType("INTEGER"); + + b.Property("HitCount") + .HasColumnType("INTEGER"); + + b.Property("MissCount") + .HasColumnType("INTEGER"); + + b.Property("OkCount") + .HasColumnType("INTEGER"); + + b.Property("PlayTime") + .HasColumnType("datetime"); + + b.Property("Score") + .HasColumnType("INTEGER"); + + b.Property("ScoreRank") + .HasColumnType("INTEGER"); + + b.Property("ScoreRate") + .HasColumnType("INTEGER"); + + b.Property("Skipped") + .HasColumnType("INTEGER"); + + b.Property("SongId") + .HasColumnType("INTEGER"); + + b.Property("SongNumber") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Baid"); + + b.ToTable("SongPlayData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.UserDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("AchievementDisplayDifficulty") + .HasColumnType("INTEGER"); + + b.Property("AiWinCount") + .HasColumnType("INTEGER"); + + b.Property("ColorBody") + .HasColumnType("INTEGER"); + + b.Property("ColorFace") + .HasColumnType("INTEGER"); + + b.Property("ColorLimb") + .HasColumnType("INTEGER"); + + b.Property("CostumeData") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CostumeFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DisplayAchievement") + .HasColumnType("INTEGER"); + + b.Property("DisplayDan") + .HasColumnType("INTEGER"); + + b.Property("FavoriteSongsArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("GenericInfoFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsSkipOn") + .HasColumnType("INTEGER"); + + b.Property("IsVoiceOn") + .HasColumnType("INTEGER"); + + b.Property("LastPlayDatetime") + .HasColumnType("datetime"); + + b.Property("LastPlayMode") + .HasColumnType("INTEGER"); + + b.Property("MyDonName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NotesPosition") + .HasColumnType("INTEGER"); + + b.Property("OptionSetting") + .HasColumnType("INTEGER"); + + b.Property("SelectedToneId") + .HasColumnType("INTEGER"); + + b.Property("Title") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TitleFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TitlePlateId") + .HasColumnType("INTEGER"); + + b.Property("ToneFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Baid"); + + b.ToTable("UserData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.AiScoreDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.AiSectionScoreDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.AiScoreDatum", "Parent") + .WithMany("AiSectionScoreData") + .HasForeignKey("Baid", "SongId", "Difficulty") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanScoreDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanStageScoreDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.DanScoreDatum", "Parent") + .WithMany("DanStageScoreData") + .HasForeignKey("Baid", "DanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongBestDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongPlayDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.UserDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.AiScoreDatum", b => + { + b.Navigation("AiSectionScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanScoreDatum", b => + { + b.Navigation("DanStageScoreData"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TaikoLocalServer/Migrations/20220919022643_AddWinCountToUserdata.cs b/TaikoLocalServer/Migrations/20220919022643_AddWinCountToUserdata.cs new file mode 100644 index 0000000..ef9dce1 --- /dev/null +++ b/TaikoLocalServer/Migrations/20220919022643_AddWinCountToUserdata.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace TaikoLocalServer.Migrations +{ + /// + public partial class AddWinCountToUserdata : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "AiWinCount", + table: "UserData", + type: "INTEGER", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AiWinCount", + table: "UserData"); + } + } +} diff --git a/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs b/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs index f4951d8..36ca4e8 100644 --- a/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs +++ b/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs @@ -256,6 +256,9 @@ namespace TaikoLocalServer.Migrations b.Property("AchievementDisplayDifficulty") .HasColumnType("INTEGER"); + b.Property("AiWinCount") + .HasColumnType("INTEGER"); + b.Property("ColorBody") .HasColumnType("INTEGER");