Exemple #1
0
        private async Task OnBlackjackHold(EventContext e, bool charlie = false)
        {
            var cache           = (ICacheClient)e.Services.GetService(typeof(ICacheClient));
            BlackjackManager bm = await BlackjackManager.FromCacheClientAsync(cache, e.Channel.Id, e.Author.Id);

            CardHand Player = bm.GetPlayer(e.Author.Id);
            CardHand Dealer = bm.GetPlayer(0);

            Dealer.Hand.ForEach(x => x.isPublic = true);

            while (true)
            {
                if (bm.Worth(Dealer) >= Math.Max(bm.Worth(Player), 17))
                {
                    if (charlie)
                    {
                        if (Dealer.Hand.Count == 5)
                        {
                            if (bm.Worth(Dealer) == bm.Worth(Player))
                            {
                                await OnBlackjackDraw(e, bm);

                                return;
                            }
                            await OnBlackjackDead(e, bm);

                            return;
                        }
                    }
                    else
                    {
                        if (bm.Worth(Dealer) == bm.Worth(Player))
                        {
                            await OnBlackjackDraw(e, bm);

                            return;
                        }
                        await OnBlackjackDead(e, bm);

                        return;
                    }
                }

                bm.DealTo(Dealer);

                if (bm.Worth(Dealer) > 21)
                {
                    await OnBlackjackWin(e, bm);

                    return;
                }
            }
        }
Exemple #2
0
        private async Task OnBlackjackHit(EventContext e)
        {
            var cache = (ICacheClient)e.Services.GetService(typeof(ICacheClient));
            var api   = (IApiClient)e.Services.GetService(typeof(IApiClient));

            BlackjackManager bm = await BlackjackManager.FromCacheClientAsync(cache, e.Channel.Id, e.Author.Id);

            CardHand Player = bm.GetPlayer(e.Author.Id);
            CardHand Dealer = bm.GetPlayer(0);

            bm.DealTo(Player);

            if (bm.Worth(Player) > 21)
            {
                await OnBlackjackDead(e, bm);
            }
            else
            {
                if (Player.Hand.Count == 5)
                {
                    await OnBlackjackHold(e, true);

                    return;
                }
                else if (bm.Worth(Player) == 21 && bm.Worth(Dealer) != 21)
                {
                    await OnBlackjackWin(e, bm);

                    return;
                }
                else if (bm.Worth(Dealer) == 21 && bm.Worth(Player) != 21)
                {
                    await OnBlackjackDead(e, bm);

                    return;
                }

                await api.EditMessageAsync(e.Channel.Id, bm.MessageId, new EditMessageArgs
                {
                    embed = bm.CreateEmbed(e).ToEmbed()
                });

                await cache.UpsertAsync($"miki:blackjack:{e.Channel.Id}:{e.Author.Id}", bm.ToContext(), TimeSpan.FromHours(24));
            }
        }
Exemple #3
0
        private async Task OnBlackjackHit(EventContext e)
        {
            BlackjackManager bm = await BlackjackManager.FromCacheClientAsync(Global.RedisClient, e.Channel.Id, e.Author.Id);

            CardHand Player = bm.GetPlayer(e.Author.Id);
            CardHand Dealer = bm.GetPlayer(0);

            bm.DealTo(Player);

            if (bm.Worth(Player) > 21)
            {
                await OnBlackjackDead(e, bm);
            }
            else
            {
                if (Player.Hand.Count == 5)
                {
                    await OnBlackjackHold(e, true);

                    return;
                }
                else if (bm.Worth(Player) == 21 && bm.Worth(Dealer) != 21)
                {
                    await OnBlackjackWin(e, bm);

                    return;
                }
                else if (bm.Worth(Dealer) == 21 && bm.Worth(Player) != 21)
                {
                    await OnBlackjackDead(e, bm);

                    return;
                }

                await Global.Client.ChatClient._apiClient.EditMessageAsync(e.Channel.Id, bm.MessageId, new EditMessageArgs
                {
                    embed = bm.CreateEmbed(e).ToEmbed()
                });

                await Global.RedisClient.UpsertAsync($"miki:blackjack:{e.Channel.Id}:{e.Author.Id}", bm.ToContext(), TimeSpan.FromHours(24));
            }
        }