mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	.slot should now show correct messages if multipliers are changed in the config
This commit is contained in:
		@@ -8,21 +8,44 @@ public class SlotGame
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        var rolls = new[] { _rng.Next(0, 6), _rng.Next(0, 6), _rng.Next(0, 6) };
 | 
					        var rolls = new[] { _rng.Next(0, 6), _rng.Next(0, 6), _rng.Next(0, 6) };
 | 
				
			||||||
        var multi = 0;
 | 
					        var multi = 0;
 | 
				
			||||||
 | 
					        var winType = SlotWinType.None;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (rolls.All(x => x == 5))
 | 
					        if (rolls.All(x => x == 5))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            winType = SlotWinType.TrippleJoker;
 | 
				
			||||||
            multi = 30;
 | 
					            multi = 30;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else if (rolls.All(x => x == rolls[0]))
 | 
					        else if (rolls.All(x => x == rolls[0]))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            winType = SlotWinType.TrippleNormal;
 | 
				
			||||||
            multi = 10;
 | 
					            multi = 10;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else if (rolls.Count(x => x == 5) == 2)
 | 
					        else if (rolls.Count(x => x == 5) == 2)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            winType = SlotWinType.DoubleJoker;
 | 
				
			||||||
            multi = 4;
 | 
					            multi = 4;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else if (rolls.Any(x => x == 5))
 | 
					        else if (rolls.Any(x => x == 5))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            winType = SlotWinType.SingleJoker;
 | 
				
			||||||
            multi = 1;
 | 
					            multi = 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new()
 | 
					        return new()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Won = bet * multi,
 | 
					            Won = bet * multi,
 | 
				
			||||||
 | 
					            WinType = winType,
 | 
				
			||||||
            Multiplier = multi,
 | 
					            Multiplier = multi,
 | 
				
			||||||
            Rolls = rolls,
 | 
					            Rolls = rolls,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum SlotWinType : byte
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    None,
 | 
				
			||||||
 | 
					    SingleJoker,
 | 
				
			||||||
 | 
					    DoubleJoker,
 | 
				
			||||||
 | 
					    TrippleNormal,
 | 
				
			||||||
 | 
					    TrippleJoker,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -5,4 +5,5 @@ public readonly struct SlotResult
 | 
				
			|||||||
    public decimal Multiplier { get; init; }
 | 
					    public decimal Multiplier { get; init; }
 | 
				
			||||||
    public int[] Rolls { get; init; }
 | 
					    public int[] Rolls { get; init; }
 | 
				
			||||||
    public decimal Won { get; init; }
 | 
					    public decimal Won { get; init; }
 | 
				
			||||||
 | 
					    public SlotWinType WinType { get; init; }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -13,31 +13,11 @@ using NadekoBot.Services.Database.Models;
 | 
				
			|||||||
using System.Collections.Immutable;
 | 
					using System.Collections.Immutable;
 | 
				
			||||||
using System.Globalization;
 | 
					using System.Globalization;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using Nadeko.Common;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.Gambling;
 | 
					namespace NadekoBot.Modules.Gambling;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public partial class Gambling : GamblingModule<GamblingService>
 | 
					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 IGamblingService _gs;
 | 
				
			||||||
    private readonly DbService _db;
 | 
					    private readonly DbService _db;
 | 
				
			||||||
    private readonly ICurrencyService _cs;
 | 
					    private readonly ICurrencyService _cs;
 | 
				
			||||||
@@ -668,17 +648,13 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var result = await _gs.BetRollAsync()
 | 
					        var maybeResult = await _gs.BetRollAsync(ctx.User.Id, amount);
 | 
				
			||||||
        if (!)
 | 
					        if (!maybeResult.TryPickT0(out var result, out _))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
 | 
					            await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var br = new BetrollGame(Config.BetRoll);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var result = br.Roll();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var win = (long)result.Won;
 | 
					        var win = (long)result.Won;
 | 
				
			||||||
        var str = Format.Bold(ctx.User.ToString()) + Format.Code(GetText(strs.roll(result.Roll)));
 | 
					        var str = Format.Bold(ctx.User.ToString()) + Format.Code(GetText(strs.roll(result.Roll)));
 | 
				
			||||||
        if (win > 0)
 | 
					        if (win > 0)
 | 
				
			||||||
@@ -776,6 +752,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
            opts.Clean);
 | 
					            opts.Clean);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // todo check if trivia is being disposed
 | 
				
			||||||
    [Cmd]
 | 
					    [Cmd]
 | 
				
			||||||
    public async partial Task Rps(RpsPick pick, ShmartNumber amount = default)
 | 
					    public async partial Task Rps(RpsPick pick, ShmartNumber amount = default)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -803,7 +780,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (amount > 0)
 | 
					        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));
 | 
					                await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@@ -847,16 +824,15 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
        if (!await CheckBetMandatory(amount))
 | 
					        if (!await CheckBetMandatory(amount))
 | 
				
			||||||
            return;
 | 
					            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));
 | 
					            await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var result = await _service.WheelOfFortuneSpinAsync(ctx.User.Id, amount);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var wofMultipliers = Config.WheelOfFortune.Multipliers;
 | 
					        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]}』
 | 
					   『{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,
 | 
					    InsufficientFunds,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// public interface ISlotService
 | 
					 | 
				
			||||||
// {
 | 
					 | 
				
			||||||
//     ValueTask<OneOf<SlotResult, SlotError>> PullAsync(ulong userId, long amount);
 | 
					 | 
				
			||||||
// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public partial class Gambling
 | 
					public partial class Gambling
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Group]
 | 
					    [Group]
 | 
				
			||||||
@@ -204,18 +199,15 @@ public partial class Gambling
 | 
				
			|||||||
                        bgImage.Mutate(x => x.DrawImage(img, new Point(148 + (105 * i), 217), 1f));
 | 
					                        bgImage.Mutate(x => x.DrawImage(img, new Point(148 + (105 * i), 217), 1f));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var msg = GetText(strs.better_luck);
 | 
					                    var multi = result.Multiplier.ToString("0.##");
 | 
				
			||||||
                    if (result.Multiplier > 0)
 | 
					                    var msg = result.WinType switch
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        if (Math.Abs(result.Multiplier - 1M) <= decimal.)
 | 
					                        SlotWinType.SingleJoker => GetText(strs.slot_single(CurrencySign, multi)),
 | 
				
			||||||
                            msg = GetText(strs.slot_single(CurrencySign, 1));
 | 
					                        SlotWinType.DoubleJoker => GetText(strs.slot_two(CurrencySign, multi)),
 | 
				
			||||||
                        else if (Math.Abs(result.Multiplier - 4M) < float.Epsilon)
 | 
					                        SlotWinType.TrippleNormal => GetText(strs.slot_three(multi)),
 | 
				
			||||||
                            msg = GetText(strs.slot_two(CurrencySign, 4));
 | 
					                        SlotWinType.TrippleJoker => GetText(strs.slot_jackpot(multi)),
 | 
				
			||||||
                        else if (Math.Abs(result.Multiplier - 10M) <= float.Epsilon)
 | 
					                        _ => GetText(strs.better_luck),
 | 
				
			||||||
                            msg = GetText(strs.slot_three(10));
 | 
					                    };
 | 
				
			||||||
                        else if (Math.Abs(result.Multiplier - 30M) <= float.Epsilon)
 | 
					 | 
				
			||||||
                            msg = GetText(strs.slot_jackpot(30));
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    await using (var imgStream = await bgImage.ToStreamAsync())
 | 
					                    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