Ejemplo n.º 1
0
            public async Task SlotTest(int tests = 1000)
            {
                if (tests <= 0)
                {
                    return;
                }
                //multi vs how many times it occured
                var dict = new Dictionary <int, int>();

                for (int i = 0; i < tests; i++)
                {
                    var res = SlotMachine.Pull();
                    if (dict.ContainsKey(res.Multiplier))
                    {
                        dict[res.Multiplier] += 1;
                    }
                    else
                    {
                        dict.Add(res.Multiplier, 1);
                    }
                }

                var       sb     = new StringBuilder();
                const int bet    = 1;
                int       payout = 0;

                foreach (var key in dict.Keys.OrderByDescending(x => x))
                {
                    sb.AppendLine($"x{key} occured {dict[key]} times. {dict[key] * 1.0f / tests * 100}%");
                    payout += key * dict[key];
                }
                await Context.Channel.SendConfirmAsync("Slot Test Results", sb.ToString(),
                                                       footer : $"Total Bet: {tests * bet} | Payout: {payout * bet} | {payout * 1.0f / tests * 100}%").ConfigureAwait(false);
            }
Ejemplo n.º 2
0
            public async Task Slot(int amount = 0)
            {
                if (!_runningUsers.Add(Context.User.Id))
                {
                    return;
                }
                try
                {
                    if (amount < 1)
                    {
                        await ReplyErrorLocalized("min_bet_limit", 1 + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    const int maxAmount = 9999;
                    if (amount > maxAmount)
                    {
                        GetText("slot_maxbet", maxAmount + _bc.BotConfig.CurrencySign);
                        await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false))
                    {
                        await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    Interlocked.Add(ref _totalBet, amount);
                    using (var bgFileStream = _images.SlotBackground.ToStream())
                    {
                        var bgImage = ImageSharp.Image.Load(bgFileStream);

                        var   result  = SlotMachine.Pull();
                        int[] numbers = result.Numbers;

                        for (int i = 0; i < 3; i++)
                        {
                            using (var file = _images.SlotEmojis[numbers[i]].ToStream())
                                using (var randomImage = ImageSharp.Image.Load(file))
                                {
                                    bgImage.DrawImage(randomImage, 100, default, new Point(95 + 142 * i, 330));
Ejemplo n.º 3
0
            public async Task Slot(ShmartNumber amount)
            {
                if (!_runningUsers.Add(Context.User.Id))
                {
                    return;
                }
                try
                {
                    if (!await CheckBetMandatory(amount).ConfigureAwait(false))
                    {
                        return;
                    }
                    const int maxAmount = 9999;
                    if (amount > maxAmount)
                    {
                        await ReplyErrorLocalized("max_bet_limit", maxAmount + Bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false, gamble: true).ConfigureAwait(false))
                    {
                        await ReplyErrorLocalized("not_enough", Bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    Interlocked.Add(ref _totalBet, amount.Value);
                    using (var bgImage = Image.Load(_images.SlotBackground))
                    {
                        var   result  = SlotMachine.Pull();
                        int[] numbers = result.Numbers;

                        for (int i = 0; i < 3; i++)
                        {
                            using (var randomImage = Image.Load(_images.SlotEmojis[numbers[i]]))
                            {
                                bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, randomImage, new Point(95 + 142 * i, 330)));
                            }
                        }

                        var won      = amount * result.Multiplier;
                        var printWon = won;
                        var n        = 0;
                        do
                        {
                            var digit = (int)(printWon % 10);
                            using (var img = Image.Load(_images.SlotNumbers[digit]))
                            {
                                bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, img, new Point(230 - n * 16, 462)));
                            }
                            n++;
                        } while ((printWon /= 10) != 0);

                        var printAmount = amount;
                        n = 0;
                        do
                        {
                            var digit = (int)(printAmount % 10);
                            using (var img = Image.Load(_images.SlotNumbers[digit]))
                            {
                                bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, img, new Point(395 - n * 16, 462)));
                            }
                            n++;
                        } while ((printAmount /= 10) != 0);

                        var msg = GetText("better_luck");
                        if (result.Multiplier != 0)
                        {
                            await _cs.AddAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount *result.Multiplier, false, gamble : true).ConfigureAwait(false);

                            Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier);
                            if (result.Multiplier == 1)
                            {
                                msg = GetText("slot_single", Bc.BotConfig.CurrencySign, 1);
                            }
                            else if (result.Multiplier == 4)
                            {
                                msg = GetText("slot_two", Bc.BotConfig.CurrencySign, 4);
                            }
                            else if (result.Multiplier == 10)
                            {
                                msg = GetText("slot_three", 10);
                            }
                            else if (result.Multiplier == 30)
                            {
                                msg = GetText("slot_jackpot", 30);
                            }
                        }

                        using (var imgStream = bgImage.ToStream())
                        {
                            await Context.Channel.SendFileAsync(imgStream, "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("won")}:` {amount * result.Multiplier}{Bc.BotConfig.CurrencySign}").ConfigureAwait(false);
                        }
                    }
                }
                finally
                {
                    var _ = Task.Run(async() =>
                    {
                        await Task.Delay(1500).ConfigureAwait(false);
                        _runningUsers.Remove(Context.User.Id);
                    });
                }
            }
Ejemplo n.º 4
0
            public async Task Slot(int amount = 0)
            {
                if (!runningUsers.Add(Context.User.Id))
                {
                    return;
                }
                try
                {
                    if (amount < 1)
                    {
                        await Context.Channel.SendErrorAsync($"You can't bet less than 1{NadekoBot.BotConfig.CurrencySign}").ConfigureAwait(false);

                        return;
                    }

                    if (amount > 999)
                    {
                        await Context.Channel.SendErrorAsync($"You can't bet more than 999{NadekoBot.BotConfig.CurrencySign}").ConfigureAwait(false);

                        return;
                    }

                    if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Slot Machine", amount, false))
                    {
                        await Context.Channel.SendErrorAsync($"You don't have enough {NadekoBot.BotConfig.CurrencySign}.").ConfigureAwait(false);

                        return;
                    }
                    Interlocked.Add(ref totalBet, amount);
                    using (var bgFileStream = new MemoryStream(backgroundBuffer))
                    {
                        var bgImage = new ImageSharp.Image(bgFileStream);

                        var   result  = SlotMachine.Pull();
                        int[] numbers = result.Numbers;
                        using (var bgPixels = bgImage.Lock())
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                using (var file = new MemoryStream(emojiBuffer[numbers[i]]))
                                {
                                    var randomImage = new ImageSharp.Image(file);
                                    using (var toAdd = randomImage.Lock())
                                    {
                                        for (int j = 0; j < toAdd.Width; j++)
                                        {
                                            for (int k = 0; k < toAdd.Height; k++)
                                            {
                                                var x     = 95 + 142 * i + j;
                                                int y     = 330 + k;
                                                var toSet = toAdd[j, k];
                                                if (toSet.A < alphaCutOut)
                                                {
                                                    continue;
                                                }
                                                bgPixels[x, y] = toAdd[j, k];
                                            }
                                        }
                                    }
                                }
                            }

                            var won      = amount * result.Multiplier;
                            var printWon = won;
                            var n        = 0;
                            do
                            {
                                var digit = printWon % 10;
                                using (var fs = new MemoryStream(numbersBuffer[digit]))
                                {
                                    var img = new ImageSharp.Image(fs);
                                    using (var pixels = img.Lock())
                                    {
                                        for (int i = 0; i < pixels.Width; i++)
                                        {
                                            for (int j = 0; j < pixels.Height; j++)
                                            {
                                                if (pixels[i, j].A < alphaCutOut)
                                                {
                                                    continue;
                                                }
                                                var x = 230 - n * 16 + i;
                                                bgPixels[x, 462 + j] = pixels[i, j];
                                            }
                                        }
                                    }
                                }
                                n++;
                            } while ((printWon /= 10) != 0);

                            var printAmount = amount;
                            n = 0;
                            do
                            {
                                var digit = printAmount % 10;
                                using (var fs = new MemoryStream(numbersBuffer[digit]))
                                {
                                    var img = new ImageSharp.Image(fs);
                                    using (var pixels = img.Lock())
                                    {
                                        for (int i = 0; i < pixels.Width; i++)
                                        {
                                            for (int j = 0; j < pixels.Height; j++)
                                            {
                                                if (pixels[i, j].A < alphaCutOut)
                                                {
                                                    continue;
                                                }
                                                var x = 395 - n * 16 + i;
                                                bgPixels[x, 462 + j] = pixels[i, j];
                                            }
                                        }
                                    }
                                }
                                n++;
                            } while ((printAmount /= 10) != 0);
                        }

                        var msg = "Better luck next time ^_^";
                        if (result.Multiplier != 0)
                        {
                            await CurrencyHandler.AddCurrencyAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount *result.Multiplier, false);

                            Interlocked.Add(ref totalPaidOut, amount * result.Multiplier);
                            if (result.Multiplier == 1)
                            {
                                msg = $"A single {NadekoBot.BotConfig.CurrencySign}, x1 - Try again!";
                            }
                            else if (result.Multiplier == 4)
                            {
                                msg = $"Good job! Two {NadekoBot.BotConfig.CurrencySign} - bet x4";
                            }
                            else if (result.Multiplier == 10)
                            {
                                msg = "Wow! Lucky! Three of a kind! x10";
                            }
                            else if (result.Multiplier == 30)
                            {
                                msg = "WOAAHHHHHH!!! Congratulations!!! x30";
                            }
                        }

                        await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`Bet:`{amount} `Won:` {amount * result.Multiplier}{NadekoBot.BotConfig.CurrencySign}").ConfigureAwait(false);
                    }
                }
                finally
                {
                    var t = Task.Run(async() =>
                    {
                        await Task.Delay(3000);
                        runningUsers.Remove(Context.User.Id);
                    });
                }
            }
Ejemplo n.º 5
0
            public async Task Slot(int amount = 0)
            {
                if (!_runningUsers.Add(Context.User.Id))
                {
                    return;
                }
                try
                {
                    if (amount < 1)
                    {
                        await ReplyErrorLocalized("min_bet_limit", 1 + CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    if (amount > 999)
                    {
                        GetText("slot_maxbet", 999 + CurrencySign);
                        await ReplyErrorLocalized("max_bet_limit", 999 + CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Slot Machine", amount, false))
                    {
                        await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    Interlocked.Add(ref _totalBet, amount);
                    using (var bgFileStream = NadekoBot.Images.SlotBackground.ToStream())
                    {
                        var bgImage = new ImageSharp.Image(bgFileStream);

                        var   result  = SlotMachine.Pull();
                        int[] numbers = result.Numbers;

                        for (int i = 0; i < 3; i++)
                        {
                            using (var file = _images.SlotEmojis[numbers[i]].ToStream())
                                using (var randomImage = new ImageSharp.Image(file))
                                {
                                    bgImage.DrawImage(randomImage, 100, default(Size), new Point(95 + 142 * i, 330));
                                }
                        }

                        var won      = amount * result.Multiplier;
                        var printWon = won;
                        var n        = 0;
                        do
                        {
                            var digit = printWon % 10;
                            using (var fs = NadekoBot.Images.SlotNumbers[digit].ToStream())
                                using (var img = new ImageSharp.Image(fs))
                                {
                                    bgImage.DrawImage(img, 100, default(Size), new Point(230 - n * 16, 462));
                                }
                            n++;
                        } while ((printWon /= 10) != 0);

                        var printAmount = amount;
                        n = 0;
                        do
                        {
                            var digit = printAmount % 10;
                            using (var fs = _images.SlotNumbers[digit].ToStream())
                                using (var img = new ImageSharp.Image(fs))
                                {
                                    bgImage.DrawImage(img, 100, default(Size), new Point(395 - n * 16, 462));
                                }
                            n++;
                        } while ((printAmount /= 10) != 0);

                        var msg = GetText("better_luck");
                        if (result.Multiplier != 0)
                        {
                            await CurrencyHandler.AddCurrencyAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount *result.Multiplier, false);

                            Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier);
                            if (result.Multiplier == 1)
                            {
                                msg = GetText("slot_single", CurrencySign, 1);
                            }
                            else if (result.Multiplier == 4)
                            {
                                msg = GetText("slot_two", CurrencySign, 4);
                            }
                            else if (result.Multiplier == 10)
                            {
                                msg = GetText("slot_three", 10);
                            }
                            else if (result.Multiplier == 30)
                            {
                                msg = GetText("slot_jackpot", 30);
                            }
                        }

                        await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{NadekoBot.BotConfig.CurrencySign}").ConfigureAwait(false);
                    }
                }
                finally
                {
                    var _ = Task.Run(async() =>
                    {
                        await Task.Delay(1500);
                        _runningUsers.Remove(Context.User.Id);
                    });
                }
            }
Ejemplo n.º 6
0
            public async Task Slot(int amount = 0)
            {
                if (!RunningUsers.Add(Context.User.Id))
                {
                    return;
                }

                try
                {
                    if (amount < 1)
                    {
                        await ReplyErrorLocalized("min_bet_limit", 1 + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    const int maxAmount = 9999;
                    if (amount > maxAmount)
                    {
                        GetText("slot_maxbet", maxAmount + _bc.BotConfig.CurrencySign);
                        await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false))
                    {
                        await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    Interlocked.Add(ref _totalBet, amount);
                    var result  = SlotMachine.Pull();
                    var numbers = result.Numbers;
                    var won     = amount * result.Multiplier;

                    var msg = result.Multiplier != 0 ? "" : GetText("better_luck");
                    if (result.Multiplier != 0)
                    {
                        await _cs.AddAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount *result.Multiplier, false);

                        Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier);
                        switch (result.Multiplier)
                        {
                        case 1:
                            msg = GetText("slot_single", _bc.BotConfig.CurrencySign, 1);
                            break;

                        case 4:
                            msg = GetText("slot_two", _bc.BotConfig.CurrencySign, 4);
                            break;

                        case 10:
                            msg = GetText("slot_three", 10);
                            break;

                        case 30:
                            msg = GetText("slot_jackpot", 30);
                            break;
                        }
                    }

                    await Context.Channel.SendMessageAsync($"{Context.User.Mention} {msg}\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {won}{_bc.BotConfig.CurrencySign}\n{_emojis[numbers[0]] + _emojis[numbers[1]] + _emojis[numbers[2]]}").ConfigureAwait(false);
                }
                finally
                {
                    var _ = Task.Run(async() =>
                    {
                        await Task.Delay(1500);
                        RunningUsers.Remove(Context.User.Id);
                    });
                }
            }