added custom number of points for winning trivia

This commit is contained in:
Master Kwoth 2016-05-11 12:25:30 +02:00
parent 075c3d503d
commit d5a6f30a18
2 changed files with 14 additions and 5 deletions

View File

@ -34,11 +34,12 @@ namespace NadekoBot.Modules.Games.Commands.Trivia
public int WinRequirement { get; } = 10; public int WinRequirement { get; } = 10;
public TriviaGame(CommandEventArgs e, bool showHints) public TriviaGame(CommandEventArgs e, bool showHints, int winReq = 10)
{ {
ShowHints = showHints; ShowHints = showHints;
server = e.Server; server = e.Server;
channel = e.Channel; channel = e.Channel;
WinRequirement = winReq;
Task.Run(StartGame); Task.Run(StartGame);
} }

View File

@ -1,6 +1,7 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Modules.Games.Commands.Trivia; using NadekoBot.Modules.Games.Commands.Trivia;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq; using System.Linq;
@ -18,8 +19,8 @@ namespace NadekoBot.Modules.Games.Commands
{ {
cgb.CreateCommand(Module.Prefix + "t") cgb.CreateCommand(Module.Prefix + "t")
.Description($"Starts a game of trivia. You can add nohint to prevent hints." + .Description($"Starts a game of trivia. You can add nohint to prevent hints." +
"First player to get to 10 points wins. 30 seconds per question." + "First player to get to 10 points wins by default. You can specify a different number. 30 seconds per question." +
$"\n**Usage**:`{Module.Prefix}t nohint`") $"\n**Usage**:`{Module.Prefix}t nohint` or `{Module.Prefix}t 5 nohint`")
.Parameter("args", ParameterType.Multiple) .Parameter("args", ParameterType.Multiple)
.Do(async e => .Do(async e =>
{ {
@ -27,9 +28,16 @@ namespace NadekoBot.Modules.Games.Commands
if (!RunningTrivias.TryGetValue(e.Server.Id, out trivia)) if (!RunningTrivias.TryGetValue(e.Server.Id, out trivia))
{ {
var showHints = !e.Args.Contains("nohint"); var showHints = !e.Args.Contains("nohint");
var triviaGame = new TriviaGame(e, showHints); var number = e.Args.Select(s =>
{
int num;
return new Tuple<bool, int>(int.TryParse(s, out num), num);
}).Where(t => t.Item1).Select(t => t.Item2).FirstOrDefault();
if (number < 0)
return;
var triviaGame = new TriviaGame(e, showHints, number == 0 ? 10 : number);
if (RunningTrivias.TryAdd(e.Server.Id, triviaGame)) if (RunningTrivias.TryAdd(e.Server.Id, triviaGame))
await e.Channel.SendMessage("**Trivia game started!**").ConfigureAwait(false); await e.Channel.SendMessage($"**Trivia game started! {triviaGame.WinRequirement} points needed to win.**").ConfigureAwait(false);
else else
await triviaGame.StopGame().ConfigureAwait(false); await triviaGame.StopGame().ConfigureAwait(false);
} }