private static void ResetStageTimer() { _stageTimer.Dispose(); _stageCounter = 0; if (_state == BettingState.Idle) { _rolls.Clear(); _joinedUsers.Clear(); _sessionOwner = null; } _state = BettingState.Idle; }
private async void RollTimer_Tick(object state) { if (_rollingCounter >= RollingDurationInSeconds && _rolls.Count == 0) { await Context.Channel.SendMessageAsync($"Well this is awkward... no one rolled. Really {_sessionOwner.Mention}, you didn't even roll in your own game?"); _state = BettingState.Idle; ResetRollTimer(); return; } else if (_rollingCounter >= RollingDurationInSeconds || _state == BettingState.Results) { // Show the results! var sb = new StringBuilder(); int ctr = 1; IUser winner = null; foreach (var roll in _rolls.OrderByDescending(r => r.Value)) { if (ctr == 1) { winner = roll.Key; } sb.AppendLine($"{ctr++}. {roll.Key.Username}: {roll.Value}"); } var builder = new EmbedBuilder() .WithColor(new Color(95, 186, 125)) .WithTitle($"Congratulations {winner.Username}, you are the winner!") .WithDescription(sb.ToString()) .WithFooter(new EmbedFooterBuilder().WithText($"Thank you {_sessionOwner.Username} for hosting this game.")); builder.Build(); await Context.Channel.SendMessageAsync("", embed : builder); _state = BettingState.Idle; ResetRollTimer(); return; } else if (RollingDurationInSeconds - _rollingCounter <= 5) { await Context.Channel.SendMessageAsync("5 seconds... `!bet roll` to play!"); } else if (RollingDurationInSeconds - _rollingCounter <= 10) { await Context.Channel.SendMessageAsync("There's only 10 seconds left to roll. `!bet join` to play!"); } _rollingCounter += RollingStepLengthInSeconds; }
private void CloseBetting() { // We use this being non-null as an indicator that betting was active if (activeBets != null) { var groupedBets = activeBets.Values .Select(b => (name: TournamentHelpers.TeamNames[b.team], b.bet)) .GroupBy(b => b.name) .ToList(); if (groupedBets.Count == 1) { // refund bets if only one team was bet on RefundBets(); activeBets = null; CurrentBettingState = BettingState.disabled; Log.LogFeedMessage($"Betting is now CLOSED: only one team bet on, bets refunded"); ActionManager.SendChat($"Betting is now CLOSED: only one team bet on, bets refunded"); } else if (!groupedBets.Any()) { activeBets = null; CurrentBettingState = BettingState.disabled; Log.LogFeedMessage($"Betting is now CLOSED: no bets placed"); ActionManager.SendChat($"Betting is now CLOSED: no bets placed"); } else { CurrentBettingState = BettingState.closed; var betTotals = activeBets.Values .Select(b => (name: TournamentHelpers.TeamNames[b.team], b.bet)) .GroupBy(b => b.name) .Select(g => $"{g.Key} {g.Select(x => x.bet).Sum()}{Naming.Gold}") .ToList() ; string msg = $"Betting is now CLOSED: {string.Join(", ", betTotals)}"; Log.LogFeedMessage(msg); ActionManager.SendChat(msg); } } else { CurrentBettingState = BettingState.disabled; } TournamentHub.UpdateBets(); }
public void OpenBetting(TournamentBehavior tournamentBehavior) { if (BLTAdoptAHeroModule.TournamentConfig.EnableBetting && tournamentBehavior.CurrentMatch != null && (tournamentBehavior.CurrentRoundIndex == 3 || !BLTAdoptAHeroModule.TournamentConfig.BettingOnFinalOnly)) { var teams = TournamentHelpers.TeamNames.Take(tournamentBehavior.CurrentMatch.Teams.Count()); string round = tournamentBehavior.CurrentRoundIndex < 3 ? $"round {tournamentBehavior.CurrentRoundIndex + 1}" : "final"; string msg = $"Betting is now OPEN for {round} match: {string.Join(" vs ", teams)}!"; Log.LogFeedMessage(msg); ActionManager.SendChat(msg); activeBets = new(); CurrentBettingState = BettingState.open; } else { CurrentBettingState = BettingState.disabled; } TournamentHub.UpdateBets(); }
public async Task RollAsync() { if (_state == BettingState.Rolling && _joinedUsers.Any(u => u.Id == Context.User.Id) && !_rolls.Any(r => r.Key.Id == Context.User.Id)) { _rolls.Add(Context.User, _randomGenerator.Next(50000 + 1)); await Context.Channel.SendMessageAsync($"{Context.User.Mention}, your roll has been recorded."); if (_rolls.Count == _joinedUsers.Count) { await Context.Channel.SendMessageAsync("Everyone has rolled... tallying up results"); _state = BettingState.Results; } } else if (_state == BettingState.Stage && Context.User.Id != _sessionOwner.Id) { await Context.Channel.SendMessageAsync($"MODiX is currently setting the stage for a bet. There is only `{StageDurationInSeconds - _stageCounter}` seconds left to join. `!bet join` to participate in this session"); } else { await Context.Channel.SendMessageAsync("There is no bet currently in progress. `!bet stage` to start a new session"); } }
public async Task StartAsync() { if (_state == BettingState.Stage && Context.User.Id == _sessionOwner.Id) { ResetStageTimer(); _state = BettingState.Rolling; await Context.Channel.SendMessageAsync("Ok everyone, The stage is set! `!bet roll` to place your bets!"); _rollingTimer = new Timer(RollTimer_Tick, _rollingCounter, 0, 1000 * RollingStepLengthInSeconds); } else if (_state == BettingState.Stage && Context.User.Id != _sessionOwner.Id) { await Context.Channel.SendMessageAsync($"MODiX is currently setting the stage for a bet. There is only `{StageDurationInSeconds - _stageCounter}` seconds left to join. `!bet join` to participate in this session"); } else if (_state == BettingState.Rolling) { await Context.Channel.SendMessageAsync("MODiX is currently in a bet. Please wait for the current game to end"); } else { await Context.Channel.SendMessageAsync("There is no bet currently in progress. `!bet stage` to start a new session"); } }
public async Task StageAsync() { if (_state == BettingState.Idle) { _state = BettingState.Stage; _sessionOwner = Context.User; _joinedUsers.Add(_sessionOwner); await Context.Channel.SendMessageAsync($"{Context.User.Mention} has set the stage for a new betting game. `!bet join` to participate in this session. `!bet start` to begin!"); _stageTimer = new Timer(StageTimer_Tick, _stageCounter, 0, 1000 * StageStepLengthInSeconds); } else if (_state == BettingState.Stage && Context.User.Id != _sessionOwner.Id) { await Context.Channel.SendMessageAsync($"MODiX is currently setting the stage for a bet. There is only `{StageDurationInSeconds - _stageCounter}` seconds left to join. `!bet join` to participate in this session"); } else if (_state == BettingState.Stage && Context.User.Id == _sessionOwner.Id) { await Context.Channel.SendMessageAsync($"You're the owner of the current session, {Context.User.Mention}. Type `!bet start` to begin the game!"); } else { await Context.Channel.SendMessageAsync("MODiX is currently in a bet. Please wait for the current game to end"); } }