From f3ed14de5bf6450969b0527e5dadb0296d2e0f86 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 13 Jul 2022 04:01:56 +0200 Subject: [PATCH] .slot should now show correct messages if multipliers are changed in the config --- src/Nadeko.Econ/Gambling/Slot/SlotGame.cs | 23 +++++++++++ src/Nadeko.Econ/Gambling/Slot/SlotResult.cs | 1 + src/NadekoBot/Modules/Gambling/Gambling.cs | 38 ++++--------------- src/NadekoBot/Modules/Gambling/RpsPick.cs | 14 +++++++ .../Modules/Gambling/Slot/SlotCommands.cs | 24 ++++-------- .../Modules/Gambling/~Shared/GamblingError.cs | 8 ---- 6 files changed, 53 insertions(+), 55 deletions(-) create mode 100644 src/NadekoBot/Modules/Gambling/RpsPick.cs delete mode 100644 src/NadekoBot/Modules/Gambling/~Shared/GamblingError.cs diff --git a/src/Nadeko.Econ/Gambling/Slot/SlotGame.cs b/src/Nadeko.Econ/Gambling/Slot/SlotGame.cs index 5e18a75c1..ded119208 100644 --- a/src/Nadeko.Econ/Gambling/Slot/SlotGame.cs +++ b/src/Nadeko.Econ/Gambling/Slot/SlotGame.cs @@ -8,21 +8,44 @@ public class SlotGame { var rolls = new[] { _rng.Next(0, 6), _rng.Next(0, 6), _rng.Next(0, 6) }; var multi = 0; + var winType = SlotWinType.None; if (rolls.All(x => x == 5)) + { + winType = SlotWinType.TrippleJoker; multi = 30; + } else if (rolls.All(x => x == rolls[0])) + { + winType = SlotWinType.TrippleNormal; multi = 10; + } else if (rolls.Count(x => x == 5) == 2) + { + winType = SlotWinType.DoubleJoker; multi = 4; + } else if (rolls.Any(x => x == 5)) + { + winType = SlotWinType.SingleJoker; multi = 1; + } return new() { Won = bet * multi, + WinType = winType, Multiplier = multi, Rolls = rolls, }; } +} + +public enum SlotWinType : byte +{ + None, + SingleJoker, + DoubleJoker, + TrippleNormal, + TrippleJoker, } \ No newline at end of file diff --git a/src/Nadeko.Econ/Gambling/Slot/SlotResult.cs b/src/Nadeko.Econ/Gambling/Slot/SlotResult.cs index 14117f696..78bf2ccd1 100644 --- a/src/Nadeko.Econ/Gambling/Slot/SlotResult.cs +++ b/src/Nadeko.Econ/Gambling/Slot/SlotResult.cs @@ -5,4 +5,5 @@ public readonly struct SlotResult public decimal Multiplier { get; init; } public int[] Rolls { get; init; } public decimal Won { get; init; } + public SlotWinType WinType { get; init; } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 2da1f9762..0e25d5537 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -13,31 +13,11 @@ using NadekoBot.Services.Database.Models; using System.Collections.Immutable; using System.Globalization; using System.Text; -using Nadeko.Common; namespace NadekoBot.Modules.Gambling; public partial class Gambling : GamblingModule { - public enum RpsPick - { - R = 0, - Rock = 0, - Rocket = 0, - P = 1, - Paper = 1, - Paperclip = 1, - S = 2, - Scissors = 2 - } - - public enum RpsResult - { - Win, - Loss, - Draw - } - private readonly IGamblingService _gs; private readonly DbService _db; private readonly ICurrencyService _cs; @@ -668,17 +648,13 @@ public partial class Gambling : GamblingModule return; } - var result = await _gs.BetRollAsync() - if (!) + var maybeResult = await _gs.BetRollAsync(ctx.User.Id, amount); + if (!maybeResult.TryPickT0(out var result, out _)) { await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); return; } - var br = new BetrollGame(Config.BetRoll); - - var result = br.Roll(); - var win = (long)result.Won; var str = Format.Bold(ctx.User.ToString()) + Format.Code(GetText(strs.roll(result.Roll))); if (win > 0) @@ -776,6 +752,7 @@ public partial class Gambling : GamblingModule opts.Clean); } + // todo check if trivia is being disposed [Cmd] public async partial Task Rps(RpsPick pick, ShmartNumber amount = default) { @@ -803,7 +780,7 @@ public partial class Gambling : GamblingModule if (amount > 0) { - if (!await _cs.RemoveAsync(ctx.User.Id, amount, new("rps", "bet", ""))) + if (!await _cs.RemoveAsync(ctx.User.Id, amount, new("rps", "bet"))) { await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); return; @@ -847,16 +824,15 @@ public partial class Gambling : GamblingModule if (!await CheckBetMandatory(amount)) return; - if (!await _cs.RemoveAsync(ctx.User.Id, amount, new("wheel", "bet"))) + var res = await _gs.WofAsync(ctx.User.Id, amount); + if (!res.TryPickT0(out var result, out _)) { await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); return; } - var result = await _service.WheelOfFortuneSpinAsync(ctx.User.Id, amount); - var wofMultipliers = Config.WheelOfFortune.Multipliers; - await SendConfirmAsync(Format.Bold($@"{ctx.User} won: {N(result.Amount)} + await SendConfirmAsync(Format.Bold($@"{ctx.User} won: {N(result.Won)} 『{wofMultipliers[1]}』 『{wofMultipliers[0]}』 『{wofMultipliers[7]}』 diff --git a/src/NadekoBot/Modules/Gambling/RpsPick.cs b/src/NadekoBot/Modules/Gambling/RpsPick.cs new file mode 100644 index 000000000..e50eed3cb --- /dev/null +++ b/src/NadekoBot/Modules/Gambling/RpsPick.cs @@ -0,0 +1,14 @@ +#nullable disable +namespace NadekoBot.Modules.Gambling; + +public enum RpsPick +{ + R = 0, + Rock = 0, + Rocket = 0, + P = 1, + Paper = 1, + Paperclip = 1, + S = 2, + Scissors = 2 +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs index dbab85738..d3fe544c8 100644 --- a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs @@ -19,11 +19,6 @@ public enum GamblingError InsufficientFunds, } -// public interface ISlotService -// { -// ValueTask> PullAsync(ulong userId, long amount); -// } - public partial class Gambling { [Group] @@ -204,18 +199,15 @@ public partial class Gambling bgImage.Mutate(x => x.DrawImage(img, new Point(148 + (105 * i), 217), 1f)); } - var msg = GetText(strs.better_luck); - if (result.Multiplier > 0) + var multi = result.Multiplier.ToString("0.##"); + var msg = result.WinType switch { - if (Math.Abs(result.Multiplier - 1M) <= decimal.) - msg = GetText(strs.slot_single(CurrencySign, 1)); - else if (Math.Abs(result.Multiplier - 4M) < float.Epsilon) - msg = GetText(strs.slot_two(CurrencySign, 4)); - else if (Math.Abs(result.Multiplier - 10M) <= float.Epsilon) - msg = GetText(strs.slot_three(10)); - else if (Math.Abs(result.Multiplier - 30M) <= float.Epsilon) - msg = GetText(strs.slot_jackpot(30)); - } + SlotWinType.SingleJoker => GetText(strs.slot_single(CurrencySign, multi)), + SlotWinType.DoubleJoker => GetText(strs.slot_two(CurrencySign, multi)), + SlotWinType.TrippleNormal => GetText(strs.slot_three(multi)), + SlotWinType.TrippleJoker => GetText(strs.slot_jackpot(multi)), + _ => GetText(strs.better_luck), + }; await using (var imgStream = await bgImage.ToStreamAsync()) { diff --git a/src/NadekoBot/Modules/Gambling/~Shared/GamblingError.cs b/src/NadekoBot/Modules/Gambling/~Shared/GamblingError.cs deleted file mode 100644 index e466f1960..000000000 --- a/src/NadekoBot/Modules/Gambling/~Shared/GamblingError.cs +++ /dev/null @@ -1,8 +0,0 @@ -#nullable disable -namespace NadekoBot.Modules.Gambling; - -public enum OldGamblingError -{ - None, - NotEnough -} \ No newline at end of file