mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	.slot should now show correct messages if multipliers are changed in the config
This commit is contained in:
		@@ -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<GamblingService>
 | 
			
		||||
{
 | 
			
		||||
    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<GamblingService>
 | 
			
		||||
            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<GamblingService>
 | 
			
		||||
            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<GamblingService>
 | 
			
		||||
 | 
			
		||||
        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<GamblingService>
 | 
			
		||||
        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]}』
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								src/NadekoBot/Modules/Gambling/RpsPick.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/NadekoBot/Modules/Gambling/RpsPick.cs
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
}
 | 
			
		||||
@@ -19,11 +19,6 @@ public enum GamblingError
 | 
			
		||||
    InsufficientFunds,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// public interface ISlotService
 | 
			
		||||
// {
 | 
			
		||||
//     ValueTask<OneOf<SlotResult, SlotError>> 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())
 | 
			
		||||
                    {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
#nullable disable
 | 
			
		||||
namespace NadekoBot.Modules.Gambling;
 | 
			
		||||
 | 
			
		||||
public enum OldGamblingError
 | 
			
		||||
{
 | 
			
		||||
    None,
 | 
			
		||||
    NotEnough
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user