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)

This commit is contained in:
Master Kwoth 2017-08-03 20:19:09 +02:00
parent f3984c824e
commit d9a446d874
3 changed files with 23 additions and 12 deletions

View File

@ -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()

View File

@ -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));
}
}
}

View File

@ -1273,7 +1273,7 @@
<value>nunchi</value>
</data>
<data name="nunchi_desc" xml:space="preserve">
<value>Creates or joins a nunchi game. Minimum 3 users required.</value>
<value>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.</value>
</data>
<data name="nunchi_usage" xml:space="preserve">
<value>`{0}nunchi`</value>