From d9a446d87408960f80b6f3d52d7720befa73d719 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 3 Aug 2017 20:19:09 +0200 Subject: [PATCH] Nunchi is much more fair and forgiving now. There are 5 seconds delays between rounds, and only one player can fail per round (multiple users can still get booted if they're inactive) --- .../Modules/Games/Common/Nunchi/Nunchi.cs | 15 +++++++++++++-- src/NadekoBot/Modules/Games/NunchiCommands.cs | 18 +++++++++--------- src/NadekoBot/Resources/CommandStrings.resx | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/NadekoBot/Modules/Games/Common/Nunchi/Nunchi.cs b/src/NadekoBot/Modules/Games/Common/Nunchi/Nunchi.cs index 0cf517db..dd489bf0 100644 --- a/src/NadekoBot/Modules/Games/Common/Nunchi/Nunchi.cs +++ b/src/NadekoBot/Modules/Games/Common/Nunchi/Nunchi.cs @@ -14,6 +14,7 @@ namespace NadekoBot.Modules.Games.Common.Nunchi { Joining, Playing, + WaitingForNextRound, Ended, } @@ -35,6 +36,7 @@ namespace NadekoBot.Modules.Games.Common.Nunchi public int ParticipantCount => _participants.Count; private const int _killTimeout = 20 * 1000; + private const int _nextRoundTimeout = 5 * 1000; private Timer _killTimer; public Nunchi(ulong creatorId, string creatorName) @@ -62,7 +64,7 @@ namespace NadekoBot.Modules.Games.Common.Nunchi await _locker.WaitAsync().ConfigureAwait(false); try { - if (_participants.Count < 2) + if (_participants.Count < 3) { CurrentPhase = Phase.Ended; return false; @@ -119,6 +121,7 @@ namespace NadekoBot.Modules.Games.Common.Nunchi // if only 2 players are left, game is over if (_participants.Count == 2) { + _killTimer.Change(Timeout.Infinite, Timeout.Infinite); CurrentPhase = Phase.Ended; var _ = OnGameEnded?.Invoke(this, userTuple.Name); } @@ -151,11 +154,19 @@ namespace NadekoBot.Modules.Games.Common.Nunchi var __ = OnRoundEnded?.Invoke(this, failure); if (_participants.Count <= 1) // means we have a winner or everyone was booted out { + _killTimer.Change(Timeout.Infinite, Timeout.Infinite); CurrentPhase = Phase.Ended; var _ = OnGameEnded?.Invoke(this, _participants.Count > 0 ? _participants.First().Name : null); return; } - var ___ = OnRoundStarted?.Invoke(this); + CurrentPhase = Phase.WaitingForNextRound; + var throwawayDelay = Task.Run(async () => + { + await Task.Delay(_nextRoundTimeout).ConfigureAwait(false); + CurrentPhase = Phase.Playing; + var ___ = OnRoundStarted?.Invoke(this); + }); + } public void Dispose() diff --git a/src/NadekoBot/Modules/Games/NunchiCommands.cs b/src/NadekoBot/Modules/Games/NunchiCommands.cs index 9f2aa58a..3f4fdc7d 100644 --- a/src/NadekoBot/Modules/Games/NunchiCommands.cs +++ b/src/NadekoBot/Modules/Games/NunchiCommands.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Games } - try { await ReplyConfirmLocalized("nunchi_created").ConfigureAwait(false); } catch { } + try { await ConfirmLocalized("nunchi_created").ConfigureAwait(false); } catch { } nunchi.OnGameEnded += Nunchi_OnGameEnded; //nunchi.OnGameStarted += Nunchi_OnGameStarted; @@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Games { if (Games.TryRemove(Context.Guild.Id, out var game)) game.Dispose(); - await ReplyErrorLocalized("nunchi_failed_to_start").ConfigureAwait(false); + await ConfirmLocalized("nunchi_failed_to_start").ConfigureAwait(false); } async Task _client_MessageReceived(SocketMessage arg) @@ -84,26 +84,26 @@ namespace NadekoBot.Modules.Games private Task Nunchi_OnRoundStarted(Nunchi arg) { - return ReplyConfirmLocalized("nunchi_round_started", Format.Bold(arg.CurrentNumber.ToString())); + return ConfirmLocalized("nunchi_round_started", Format.Bold(arg.CurrentNumber.ToString())); } private Task Nunchi_OnUserGuessed(Nunchi arg) { - return ReplyConfirmLocalized("nunchi_next_number", Format.Bold(arg.CurrentNumber.ToString())); + return ConfirmLocalized("nunchi_next_number", Format.Bold(arg.CurrentNumber.ToString())); } private Task Nunchi_OnRoundEnded(Nunchi arg1, (ulong Id, string Name)? arg2) { if(arg2.HasValue) - return ReplyConfirmLocalized("nunchi_round_ended", Format.Bold(arg2.Value.Name)); + return ConfirmLocalized("nunchi_round_ended", Format.Bold(arg2.Value.Name)); else - return ReplyConfirmLocalized("nunchi_round_ended_boot", + return ConfirmLocalized("nunchi_round_ended_boot", Format.Bold("\n" + string.Join("\n, ", arg1.Participants.Select(x => x.Name)))); // this won't work if there are too many users } private Task Nunchi_OnGameStarted(Nunchi arg) { - return ReplyConfirmLocalized("nunchi_started", Format.Bold(arg.ParticipantCount.ToString())); + return ConfirmLocalized("nunchi_started", Format.Bold(arg.ParticipantCount.ToString())); } private Task Nunchi_OnGameEnded(Nunchi arg1, string arg2) @@ -112,9 +112,9 @@ namespace NadekoBot.Modules.Games game.Dispose(); if(arg2 == null) - return ReplyConfirmLocalized("nunchi_ended_no_winner", Format.Bold(arg2)); + return ConfirmLocalized("nunchi_ended_no_winner", Format.Bold(arg2)); else - return ReplyConfirmLocalized("nunchi_ended", Format.Bold(arg2)); + return ConfirmLocalized("nunchi_ended", Format.Bold(arg2)); } } } diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 51fe44fb..6336b76f 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1273,7 +1273,7 @@ nunchi - Creates or joins a nunchi game. Minimum 3 users required. + Creates or joins an existing nunchi game. Users have to count up by 1 from the starting number shown by the bot. If someone makes a mistake (types an incorrent number, or repeats the same number) they are out of the game and a new round starts without them. Minimum 3 users required. `{0}nunchi`