public async Task DisplayAsync() { var guid = BlackJackService.CreateImage(Context.User.Id); var embedBuilder = new EmbedBuilder() .WithSuccessColor() .WithImageUrl($"attachment://board{guid}.png") .WithDescription(BlackJackService.GetScoreFromMatch(Context.User.Id)) .WithFooter("React with the action you want to perform. (timeout = 30 seconds)"); var message = await InteractiveBase.SendFileAsync($"BlackJack/board{guid}.png", embed : embedBuilder); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them await Task.Run(async() => { await message.AddReactionAsync(_options.HitEmote); await message.AddReactionAsync(_options.StandEmote); }); if (Timeout != null) { await Task.Delay(Timeout.Value).ContinueWith(async _ => { //BlackJackService.RemovePlayerFromMatch(Context.User.Id); Interactive.RemoveReactionCallback(message); if (!_userClicked) { await Message.DeleteAsync(); } }); } }
public PageBlackJackVm(PageBlackJack pageBlackJack) { _pageBlackJack = pageBlackJack; _blackJackService = new BlackJackService(); StartNewRound(); }
public InteractiveService(DiscordSocketClient discord, BlackJackService blackJackService, TimeSpan?defaultTimeout = null) { _blackJackService = blackJackService; Discord = discord; Discord.ReactionAdded += HandleReactionAsync; _callbacks = new Dictionary <ulong, IReactionCallback>(); _defaultTimeout = defaultTimeout ?? TimeSpan.FromSeconds(15); }
public ReactionResponseCallback(InteractiveService interactive, InteractiveBase interactiveBase, CustomCommandContext sourceContext, ICriterion <SocketReaction> criterion = null, BlackJackService blackJackService = null) { InteractiveBase = interactiveBase; Timeout = TimeSpan.FromSeconds(30); Interactive = interactive; Context = sourceContext; Criterion = criterion ?? new EmptyCriterion <SocketReaction>(); BlackJackService = blackJackService; }
private void FinalizeGame() { if (_dealer.Hand.GetSumOfHand() < 17) { while (_dealer.Hand.GetSumOfHand() < 17) { _dealer.Hand.Cards.Add(_deck.Draw()); } } var prize = _players.Select(player => player.Bet) .Sum(); var players = _players.ToObservable().StartWith(_dealer); var winner = players.Where(player => player.Hand.GetSumOfHand() < 22) .MaxBy(player => player.Hand.GetSumOfHand()) .SelectMany(winners => winners.ToObservable()); winner.Where(plr => plr.Name == _dealer.Name) .Subscribe(wner => { _players.ToObservable().Select(pl => pl.Callback) .Subscribe(ServAux.Broadcast <IBlackJackServiceCallback> (callback => callback.PlayerStatus(wner, "Wins!Casino takes the price\n\n\n"))); }); winner.Any(wnr => wnr.Name == _dealer.Name) .Where(result => !result) .SelectMany(result => winner) .Take(1) .Subscribe(wner => { _players.ToObservable().Select(pl => pl.Callback) .Subscribe(ServAux.Broadcast <IBlackJackServiceCallback> (callback => callback.PlayerStatus(wner, "Wins!\n\n\n"))); }); Console.WriteLine("Finilizing"); BlackJackService.FinalizeSession(ID); }
public BlackJackModule(BlackJackService blackjackService) => _blackjackService = blackjackService;
public BlackjackModule(BlackJackService service) { this.service = service; }