From 0310a3b32c1e8967bff368028dbcd1195a9305f6 Mon Sep 17 00:00:00 2001 From: 2riniar Date: Mon, 25 Nov 2024 01:09:15 +0900 Subject: [PATCH] =?UTF-8?q?Purchase:=20=E5=88=A9=E7=9B=8A=E3=81=A8?= =?UTF-8?q?=E8=AA=B2=E9=87=91=E9=A1=8D=E3=82=92=E5=88=86=E3=81=91=E3=81=A6?= =?UTF-8?q?=E8=A8=98=E9=8C=B2=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Models/User.cs | 10 ++- Events/DailyResetPresenter.cs | 2 +- Events/MonthlyResetPresenter.cs | 16 +++-- Events/PurchaseInfoCommandPresenter.cs | 13 ++-- Events/PurchaseUtility.cs | 26 ------- Events/RankingUtility.cs | 44 ++++++++++++ Events/SlotExecutePresenter.cs | 10 +-- .../20241124155902_AddSlotReward.Designer.cs | 71 +++++++++++++++++++ Migrations/20241124155902_AddSlotReward.cs | 29 ++++++++ Migrations/AppServiceModelSnapshot.cs | 3 + 10 files changed, 180 insertions(+), 44 deletions(-) delete mode 100644 Events/PurchaseUtility.cs create mode 100644 Events/RankingUtility.cs create mode 100644 Migrations/20241124155902_AddSlotReward.Designer.cs create mode 100644 Migrations/20241124155902_AddSlotReward.cs diff --git a/Common/Models/User.cs b/Common/Models/User.cs index 01aa63b..1d9fe99 100644 --- a/Common/Models/User.cs +++ b/Common/Models/User.cs @@ -6,6 +6,7 @@ public class User { [Key] public ulong DiscordID { get; set; } public int MonthlyPurchase { get; set; } + public int MonthlySlotReward { get; set; } public int TodaySlotExecuteCount { get; set; } public User DeepCopy() @@ -14,12 +15,13 @@ public User DeepCopy() return user; } - public void ResetMonthlyPurchase() + public void ResetMonthlyState() { MonthlyPurchase = 0; + MonthlySlotReward = 0; } - public void ResetDailySlotExecuteCount() + public void ResetDailyState() { TodaySlotExecuteCount = 0; } @@ -52,7 +54,9 @@ public SlotExecuteResult ExecuteSlot() var price = MasterManager.SettingMaster.PricePerSlotOnce; var result = SlotManager.Instance.Execute(); - MonthlyPurchase += price - (int)(NumberUtility.GetPercentFromPermillage(result.ResultRatePermillage) * price); + var reward = (int)(NumberUtility.GetPercentFromPermillage(result.ResultRatePermillage) * price); + MonthlyPurchase += price; + MonthlySlotReward += reward; TodaySlotExecuteCount++; return result; } diff --git a/Events/DailyResetPresenter.cs b/Events/DailyResetPresenter.cs index 51db80a..8acf2d9 100644 --- a/Events/DailyResetPresenter.cs +++ b/Events/DailyResetPresenter.cs @@ -8,7 +8,7 @@ public class DailyResetPresenter : SchedulerJobPresenterBase protected override async Task MainAsync() { await using var app = AppService.CreateSession(); - await app.Users.ForEachAsync(user => user.ResetDailySlotExecuteCount()); + await app.Users.ForEachAsync(user => user.ResetDailyState()); await app.SaveChangesAsync(); // 排出確率を変える diff --git a/Events/MonthlyResetPresenter.cs b/Events/MonthlyResetPresenter.cs index fc169be..5106fa9 100644 --- a/Events/MonthlyResetPresenter.cs +++ b/Events/MonthlyResetPresenter.cs @@ -10,25 +10,31 @@ protected override async Task MainAsync() { await using var app = AppService.CreateSession(); - var summaryUsers = await app.Users + var purchaseRankingUsers = await app.Users .OrderByDescending(user => user.MonthlyPurchase) .Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount) .Select(x => x.DeepCopy()) .ToListAsync(); + var slotRewardRankingUsers = await app.Users + .OrderByDescending(user => user.MonthlySlotReward) + .Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount) + .Select(x => x.DeepCopy()) + .ToListAsync(); - await app.Users.ForEachAsync(user => user.ResetMonthlyPurchase()); + await app.Users.ForEachAsync(user => user.ResetMonthlyState()); await app.SaveChangesAsync(); - await SendSummaryAsync(summaryUsers); + await SendSummaryAsync(purchaseRankingUsers, slotRewardRankingUsers); } - private async Task SendSummaryAsync(IReadOnlyList rankingUsers) + private async Task SendSummaryAsync(IReadOnlyList purchaseRankingUsers, IReadOnlyList slotRewardRankingUsers) { var embed = new EmbedBuilder() .WithColor(Color.LightOrange) .WithTitle(Format.Bold($"{IssoUtility.SmileStamp} †今月も貢げカス† {IssoUtility.SmileStamp}")) .WithDescription("月が変わったから課金額をリセットした") - .AddField("先月のランキング", PurchaseUtility.CreateRankingView(rankingUsers)) + .AddField("先月の課金額ランキング", RankingUtility.CreatePurchaseView(purchaseRankingUsers)) + .AddField("先月の利益ランキング", RankingUtility.CreateSlotRewardView(slotRewardRankingUsers)) .WithCurrentTimestamp() .Build(); diff --git a/Events/PurchaseInfoCommandPresenter.cs b/Events/PurchaseInfoCommandPresenter.cs index 4cf8955..e1f6a5f 100644 --- a/Events/PurchaseInfoCommandPresenter.cs +++ b/Events/PurchaseInfoCommandPresenter.cs @@ -11,20 +11,25 @@ protected override async Task MainAsync() await using var app = AppService.CreateSession(); var selfUser = await app.FindOrCreateUserAsync(Message.Author.Id); - var rankingUsers = await app.Users + var purchaseRankingUsers = await app.Users .OrderByDescending(user => user.MonthlyPurchase) .Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount) .ToListAsync(); + var slotRewardRankingUsers = await app.Users + .OrderByDescending(user => user.MonthlySlotReward) + .Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount) + .ToListAsync(); - await SendReplyAsync(selfUser, rankingUsers); + await SendReplyAsync(selfUser, purchaseRankingUsers, slotRewardRankingUsers); } - private async Task SendReplyAsync(User selfUser, IReadOnlyList rankingUsers) + private async Task SendReplyAsync(User selfUser, IReadOnlyList purchaseRankingUsers, IReadOnlyList slotRewardRankingUsers) { var embed = new EmbedBuilder() .WithColor(Color.LightOrange) .AddField("おまえの今月の課金額", $"{selfUser.MonthlyPurchase:N0}†カス†(税込)", inline: true) - .AddField("ランキング", PurchaseUtility.CreateRankingView(rankingUsers)) + .AddField("課金額ランキング", RankingUtility.CreatePurchaseView(purchaseRankingUsers)) + .AddField("利益ランキング", RankingUtility.CreateSlotRewardView(slotRewardRankingUsers)) .WithCurrentTimestamp() .Build(); diff --git a/Events/PurchaseUtility.cs b/Events/PurchaseUtility.cs deleted file mode 100644 index 64cbdf4..0000000 --- a/Events/PurchaseUtility.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text; -using Approvers.King.Common; -using Discord; - -namespace Approvers.King.Events; - -public static class PurchaseUtility -{ - public static string CreateRankingView(IReadOnlyList rankingUsers) - { - var embedBuilder = new StringBuilder(); - var order = 1; - foreach (var user in rankingUsers) - { - var scoreText = Math.Min(999_999_999, user.MonthlyPurchase).ToString("N0"); - var whiteSpace = Math.Max(0, 11 - scoreText.Length); - var line = - Format.Code($"#{order:D2} - {"".PadLeft(whiteSpace, ' ')}{scoreText}†カス†(税込)") + " " + - MentionUtils.MentionUser(user.DiscordID); - embedBuilder.AppendLine(line); - order++; - } - - return embedBuilder.ToString(); - } -} diff --git a/Events/RankingUtility.cs b/Events/RankingUtility.cs new file mode 100644 index 0000000..24eeee0 --- /dev/null +++ b/Events/RankingUtility.cs @@ -0,0 +1,44 @@ +using System.Text; +using Approvers.King.Common; +using Discord; + +namespace Approvers.King.Events; + +public static class RankingUtility +{ + public static string CreatePurchaseView(IReadOnlyList rankingUsers) + { + var embedBuilder = new StringBuilder(); + var order = 1; + foreach (var user in rankingUsers) + { + var scoreText = Math.Min(999_999_999, user.MonthlyPurchase).ToString("N0"); + var whiteSpace = Math.Max(0, 11 - scoreText.Length); + var line = + Format.Code($"#{order:D2} - {"".PadLeft(whiteSpace, ' ')}{scoreText}†カス†(税込)") + " " + + MentionUtils.MentionUser(user.DiscordID); + embedBuilder.AppendLine(line); + order++; + } + + return embedBuilder.ToString(); + } + + public static string CreateSlotRewardView(IReadOnlyList rankingUsers) + { + var embedBuilder = new StringBuilder(); + var order = 1; + foreach (var user in rankingUsers) + { + var scoreText = Math.Min(999_999_999, user.MonthlySlotReward).ToString("N0"); + var whiteSpace = Math.Max(0, 11 - scoreText.Length); + var line = + Format.Code($"#{order:D2} - {"".PadLeft(whiteSpace, ' ')}{scoreText}†カス†(税込)") + " " + + MentionUtils.MentionUser(user.DiscordID); + embedBuilder.AppendLine(line); + order++; + } + + return embedBuilder.ToString(); + } +} diff --git a/Events/SlotExecutePresenter.cs b/Events/SlotExecutePresenter.cs index 656e7cd..8845ce2 100644 --- a/Events/SlotExecutePresenter.cs +++ b/Events/SlotExecutePresenter.cs @@ -17,7 +17,7 @@ protected override async Task MainAsync() var slotMessage = await Message.ReplyAsync(CreateSlotMessage(result, 0)); var purchaseMessage = - await slotMessage.Channel.SendMessageAsync(CreatePurchaseMessage(result, user.MonthlyPurchase, false)); + await slotMessage.Channel.SendMessageAsync(CreatePurchaseMessage(result, user, false)); await Task.Delay(TimeSpan.FromSeconds(1)); var reelCount = result.ReelItems.Length; @@ -31,7 +31,7 @@ protected override async Task MainAsync() } await purchaseMessage.ModifyAsync(prop => - prop.Content = CreatePurchaseMessage(result, user.MonthlyPurchase, true)); + prop.Content = CreatePurchaseMessage(result, user, true)); } private static string CreateSlotMessage(SlotExecuteResult result, int openReelCount) @@ -56,7 +56,7 @@ private static string CreateSlotMessage(SlotExecuteResult result, int openReelCo return sb.ToString(); } - private static string CreatePurchaseMessage(SlotExecuteResult result, int monthlyPurchase, bool isOpen) + private static string CreatePurchaseMessage(SlotExecuteResult result, User user, bool isOpen) { var sb = new StringBuilder(); @@ -79,11 +79,11 @@ private static string CreatePurchaseMessage(SlotExecuteResult result, int monthl if (isOpen == false) { - sb.AppendLine("おまえの今月の課金額 → ???"); + sb.AppendLine("おまえの今月の利益 → ???"); } else { - sb.AppendLine($"おまえの今月の課金額 → {monthlyPurchase:N0}†カス†(税込)"); + sb.AppendLine($"おまえの今月の利益 → {user.MonthlySlotReward:N0}†カス†(税込)"); } return sb.ToString(); diff --git a/Migrations/20241124155902_AddSlotReward.Designer.cs b/Migrations/20241124155902_AddSlotReward.Designer.cs new file mode 100644 index 0000000..f17d89b --- /dev/null +++ b/Migrations/20241124155902_AddSlotReward.Designer.cs @@ -0,0 +1,71 @@ +// +using Approvers.King.Common; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Approvers.King.Migrations +{ + [DbContext(typeof(AppService))] + [Migration("20241124155902_AddSlotReward")] + partial class AddSlotReward + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.10"); + + modelBuilder.Entity("Approvers.King.Common.AppState", b => + { + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("Value") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Type"); + + b.ToTable("AppStates"); + }); + + modelBuilder.Entity("Approvers.King.Common.GachaProbability", b => + { + b.Property("RandomMessageId") + .HasColumnType("TEXT"); + + b.Property("Probability") + .HasColumnType("REAL"); + + b.HasKey("RandomMessageId"); + + b.ToTable("GachaProbabilities"); + }); + + modelBuilder.Entity("Approvers.King.Common.User", b => + { + b.Property("DiscordID") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MonthlyPurchase") + .HasColumnType("INTEGER"); + + b.Property("MonthlySlotReward") + .HasColumnType("INTEGER"); + + b.Property("TodaySlotExecuteCount") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordID"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20241124155902_AddSlotReward.cs b/Migrations/20241124155902_AddSlotReward.cs new file mode 100644 index 0000000..2e88f6d --- /dev/null +++ b/Migrations/20241124155902_AddSlotReward.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Approvers.King.Migrations +{ + /// + public partial class AddSlotReward : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "MonthlySlotReward", + table: "Users", + type: "INTEGER", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "MonthlySlotReward", + table: "Users"); + } + } +} diff --git a/Migrations/AppServiceModelSnapshot.cs b/Migrations/AppServiceModelSnapshot.cs index f268df8..2b00fac 100644 --- a/Migrations/AppServiceModelSnapshot.cs +++ b/Migrations/AppServiceModelSnapshot.cs @@ -52,6 +52,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("MonthlyPurchase") .HasColumnType("INTEGER"); + b.Property("MonthlySlotReward") + .HasColumnType("INTEGER"); + b.Property("TodaySlotExecuteCount") .HasColumnType("INTEGER");