Skip to content

Commit

Permalink
Purchase: ガチャとスロットで集計を分ける (#39)
Browse files Browse the repository at this point in the history
* Purchase: ガチャとスロットで集計を分ける

* コマンドも分けた

* まちがえた
  • Loading branch information
2RiniaR authored Nov 27, 2024
1 parent 8ec34bc commit 7e4a020
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 109 deletions.
3 changes: 2 additions & 1 deletion Common/Master/TriggerPhraseMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public enum TriggerType
GachaExecute,
GachaGet,
Marugame,
PurchaseGet,
GachaRanking,
SlotExecute,
SlotRanking,
}

[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
Expand Down
2 changes: 1 addition & 1 deletion Common/Models/AppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<User> FindOrCreateUserAsync(ulong discordId)
return user;
}

user = new User { DiscordID = discordId };
user = new User { DiscordId = discordId };
Add(user);
return user;
}
Expand Down
19 changes: 9 additions & 10 deletions Common/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Approvers.King.Common;

public class User
{
[Key] public ulong DiscordID { get; set; }
public int MonthlyPurchase { get; set; }
public int MonthlySlotReward { get; set; }
[Key] public ulong DiscordId { get; set; }
public int MonthlyGachaPurchasePrice { get; set; }
public int MonthlySlotProfitPrice { get; set; }
public int TodaySlotExecuteCount { get; set; }

public User DeepCopy()
Expand All @@ -17,8 +17,8 @@ public User DeepCopy()

public void ResetMonthlyState()
{
MonthlyPurchase = 0;
MonthlySlotReward = 0;
MonthlyGachaPurchasePrice = 0;
MonthlySlotProfitPrice = 0;
}

public void ResetDailyState()
Expand All @@ -28,20 +28,20 @@ public void ResetDailyState()

public GachaProbability? RollGachaOnce()
{
MonthlyPurchase += MasterManager.SettingMaster.PricePerGachaOnce;
MonthlyGachaPurchasePrice += MasterManager.SettingMaster.PricePerGachaOnce;
return GachaManager.Instance.Roll();
}

public GachaProbability RollGachaOnceCertain()
{
MonthlyPurchase += MasterManager.SettingMaster.PricePerGachaOnceCertain;
MonthlyGachaPurchasePrice += MasterManager.SettingMaster.PricePerGachaOnceCertain;
return GachaManager.Instance.RollWithoutNone();
}

public List<GachaProbability?> RollGachaTenTimes()
{
const int pickCount = 10;
MonthlyPurchase += MasterManager.SettingMaster.PricePerGachaTenTimes;
MonthlyGachaPurchasePrice += MasterManager.SettingMaster.PricePerGachaTenTimes;
return Enumerable.Range(0, pickCount).Select(_ => GachaManager.Instance.Roll()).ToList();
}

Expand All @@ -55,8 +55,7 @@ public SlotExecuteResult ExecuteSlot()
var price = MasterManager.SettingMaster.PricePerSlotOnce;
var result = SlotManager.Instance.Execute();
var reward = (int)(NumberUtility.GetPercentFromPermillage(result.ResultRatePermillage) * price);
MonthlyPurchase += price;
MonthlySlotReward += reward;
MonthlySlotProfitPrice += reward - price;
TodaySlotExecuteCount++;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Events/DailyReset/DailyResetPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private async Task NotifySlotMaxUsers(IReadOnlyList<User> users)
sb.AppendLine();
foreach (var user in users)
{
sb.AppendLine($"- {MentionUtils.MentionUser(user.DiscordID)}");
sb.AppendLine($"- {MentionUtils.MentionUser(user.DiscordId)}");
}

await DiscordManager.GetMainChannel().SendMessageAsync(sb.ToString());
Expand Down
2 changes: 1 addition & 1 deletion Events/Gacha/GachaCommandPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async Task SendReplyAsync(User user, IReadOnlyList<GachaProbability?> re
}

builder.AppendLine();
builder.AppendLine($"おまえの今月の課金額 → {user.MonthlyPurchase:N0}†カス†(税込)");
builder.AppendLine($"おまえの今月の課金額 → {user.MonthlyGachaPurchasePrice:N0}†カス†(税込)");

await Message.ReplyAsync(builder.ToString());
}
Expand Down
33 changes: 33 additions & 0 deletions Events/Gacha/GachaRankingPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Approvers.King.Common;
using Discord;
using Microsoft.EntityFrameworkCore;

namespace Approvers.King.Events;

public class GachaRankingPresenter : DiscordMessagePresenterBase
{
protected override async Task MainAsync()
{
await using var app = AppService.CreateSession();

var selfUser = await app.FindOrCreateUserAsync(Message.Author.Id);
var users = await app.Users
.OrderByDescending(user => user.MonthlyGachaPurchasePrice)
.Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount)
.ToListAsync();

await SendReplyAsync(selfUser, users);
}

private async Task SendReplyAsync(User selfUser, IReadOnlyList<User> users)
{
var embed = new EmbedBuilder()
.WithColor(Color.LightOrange)
.AddField("おまえの今月のガチャ課金額", $"{selfUser.MonthlyGachaPurchasePrice:N0}†カス†(税込)", inline: true)
.AddField("ガチャ課金額ランキング", GachaUtility.CreateRankingView(users))
.WithCurrentTimestamp()
.Build();

await Message.ReplyAsync(embed: embed);
}
}
21 changes: 20 additions & 1 deletion Events/Gacha/GachaUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Approvers.King.Common;
using System.Text;
using Approvers.King.Common;
using Discord;

namespace Approvers.King.Events;
Expand All @@ -18,4 +19,22 @@ public static EmbedBuilder GetInfoEmbedBuilder()
.WithDescription($"本日は {Format.Bold($"{GachaManager.Instance.RareReplyRate:P0}")} の確率で反応します")
.AddField("排出確率", DiscordMessageUtility.Table(records));
}

public static string CreateRankingView(IReadOnlyList<User> rankingUsers)
{
var embedBuilder = new StringBuilder();
var order = 1;
foreach (var user in rankingUsers)
{
var scoreText = Math.Min(999_999_999, user.MonthlyGachaPurchasePrice).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();
}
}
8 changes: 4 additions & 4 deletions Events/MonthlyReset/MonthlyResetPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ protected override async Task MainAsync()
await using var app = AppService.CreateSession();

var purchaseRankingUsers = await app.Users
.OrderByDescending(user => user.MonthlyPurchase)
.OrderByDescending(user => user.MonthlyGachaPurchasePrice)
.Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount)
.Select(x => x.DeepCopy())
.ToListAsync();
var slotRewardRankingUsers = await app.Users
.OrderByDescending(user => user.MonthlySlotReward)
.OrderByDescending(user => user.MonthlySlotProfitPrice)
.Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount)
.Select(x => x.DeepCopy())
.ToListAsync();
Expand All @@ -33,8 +33,8 @@ private async Task SendSummaryAsync(IReadOnlyList<User> purchaseRankingUsers, IR
.WithColor(Color.LightOrange)
.WithTitle(Format.Bold($"{IssoUtility.SmileStamp} †今月も貢げカス† {IssoUtility.SmileStamp}"))
.WithDescription("月が変わったから課金額をリセットした")
.AddField("先月の課金額ランキング", PurchaseUtility.CreatePurchaseView(purchaseRankingUsers))
.AddField("先月の利益ランキング", PurchaseUtility.CreateSlotRewardView(slotRewardRankingUsers))
.AddField("先月の課金額ランキング", GachaUtility.CreateRankingView(purchaseRankingUsers))
.AddField("先月の利益ランキング", SlotUtility.CreateRankingView(slotRewardRankingUsers))
.WithCurrentTimestamp()
.Build();

Expand Down
38 changes: 0 additions & 38 deletions Events/Purchase/PurchaseShowPresenter.cs

This file was deleted.

44 changes: 0 additions & 44 deletions Events/Purchase/PurchaseUtility.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Events/Slot/SlotExecutePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static string CreatePurchaseMessage(SlotExecuteResult result, User user,
}
else
{
sb.AppendLine($"おまえの今月の利益 → {user.MonthlySlotReward:N0}†カス†(税込)");
sb.AppendLine($"おまえの今月の利益 → {user.MonthlySlotProfitPrice:N0}†カス†(税込)");
}

return sb.ToString();
Expand Down
33 changes: 33 additions & 0 deletions Events/Slot/SlotRankingPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Approvers.King.Common;
using Discord;
using Microsoft.EntityFrameworkCore;

namespace Approvers.King.Events;

public class SlotRankingPresenter : DiscordMessagePresenterBase
{
protected override async Task MainAsync()
{
await using var app = AppService.CreateSession();

var selfUser = await app.FindOrCreateUserAsync(Message.Author.Id);
var users = await app.Users
.OrderByDescending(user => user.MonthlySlotProfitPrice)
.Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount)
.ToListAsync();

await SendReplyAsync(selfUser, users);
}

private async Task SendReplyAsync(User selfUser, IReadOnlyList<User> users)
{
var embed = new EmbedBuilder()
.WithColor(Color.LightOrange)
.AddField("おまえの今月のスロット利益額", $"{selfUser.MonthlySlotProfitPrice:N0}†カス†(税込)", inline: true)
.AddField("スロット利益額ランキング", SlotUtility.CreateRankingView(users))
.WithCurrentTimestamp()
.Build();

await Message.ReplyAsync(embed: embed);
}
}
26 changes: 26 additions & 0 deletions Events/Slot/SlotUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text;
using Approvers.King.Common;
using Discord;

namespace Approvers.King.Events;

public static class SlotUtility
{
public static string CreateRankingView(IReadOnlyList<User> rankingUsers)
{
var embedBuilder = new StringBuilder();
var order = 1;
foreach (var user in rankingUsers)
{
var scoreText = Math.Min(999_999_999, user.MonthlySlotProfitPrice).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();
}
}
Loading

0 comments on commit 7e4a020

Please sign in to comment.