private async Task Bj_StateUpdated(Blackjack bj) { try { if (_msg != null) { var _ = _msg.DeleteAsync(); } var c = bj.Dealer.Cards.Select(x => x.GetEmojiString()); var dealerIcon = "❔ "; if (bj.State == Blackjack.GameState.Ended) { if (bj.Dealer.GetHandValue() == 21) { dealerIcon = "💰 "; } else if (bj.Dealer.GetHandValue() > 21) { dealerIcon = "💥 "; } else { dealerIcon = "🏁 "; } } var cStr = string.Concat(c.Select(x => x.Substring(0, x.Length - 1) + " ")); cStr += "\n" + string.Concat(c.Select(x => x.Last() + " ")); var embed = new EmbedBuilder() .WithOkColor() .WithTitle("BlackJack") .AddField($"{dealerIcon} Dealer's Hand | Value: {bj.Dealer.GetHandValue()}", cStr); if (bj.CurrentUser != null) { embed.WithFooter($"Player to make a choice: {bj.CurrentUser.DiscordUser.ToString()}"); } foreach (var p in bj.Players) { c = p.Cards.Select(x => x.GetEmojiString()); cStr = "-\t" + string.Concat(c.Select(x => x.Substring(0, x.Length - 1) + " ")); cStr += "\n-\t" + string.Concat(c.Select(x => x.Last() + " ")); var full = $"{p.DiscordUser.ToString().TrimTo(20)} | Bet: {p.Bet} | Value: {p.GetHandValue()}"; if (bj.State == Blackjack.GameState.Ended) { if (p.State == User.UserState.Lost) { full = "❌ " + full; } else { full = "✅ " + full; } } else if (p == bj.CurrentUser) { full = "▶ " + full; } else if (p.State == User.UserState.Stand) { full = "⏹ " + full; } else if (p.State == User.UserState.Bust) { full = "💥 " + full; } else if (p.State == User.UserState.Blackjack) { full = "💰 " + full; } embed.AddField(full, cStr); } _msg = await Context.Channel.EmbedAsync(embed); } catch { } }
private Task Bj_GameEnded(Blackjack arg) { _service.Games.TryRemove(Context.Channel.Id, out _); return(Task.CompletedTask); }