added $rolluo (unordered roll) for games where order of dice matters
This commit is contained in:
parent
c005d6c006
commit
5c36a90408
@ -24,6 +24,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
" If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y. | $roll or $roll 7 or $roll 3d5")
|
||||
.Parameter("num", ParameterType.Optional)
|
||||
.Do(RollFunc());
|
||||
|
||||
cgb.CreateCommand(Module.Prefix + "rolluo")
|
||||
.Description("Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice (unordered)." +
|
||||
" If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y. | $roll or $roll 7 or $roll 3d5")
|
||||
.Parameter("num", ParameterType.Optional)
|
||||
.Do(RollFunc(false));
|
||||
|
||||
cgb.CreateCommand(Module.Prefix + "nroll")
|
||||
.Description("Rolls in a given range. | `$nroll 5` (rolls 0-5) or `$nroll 5-15`")
|
||||
.Parameter("range", ParameterType.Required)
|
||||
@ -40,7 +47,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
|
||||
Regex dndRegex = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
||||
private Func<CommandEventArgs, Task> RollFunc()
|
||||
private Func<CommandEventArgs, Task> RollFunc(bool ordered = true)
|
||||
{
|
||||
var r = new Random();
|
||||
return async e =>
|
||||
@ -73,7 +80,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
arr[i] = r.Next(1, n2 + 1);
|
||||
}
|
||||
var elemCnt = 0;
|
||||
await e.Channel.SendMessage($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", arr.OrderBy(x => x).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||
await e.Channel.SendMessage($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -92,17 +99,23 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var randomNumber = r.Next(1, 7);
|
||||
var toInsert = dices.Count;
|
||||
if (randomNumber == 6 || dices.Count == 0)
|
||||
toInsert = 0;
|
||||
else if (randomNumber != 1)
|
||||
for (var j = 0; j < dices.Count; j++)
|
||||
{
|
||||
if (values[j] < randomNumber)
|
||||
if (ordered)
|
||||
{
|
||||
if (randomNumber == 6 || dices.Count == 0)
|
||||
toInsert = 0;
|
||||
else if (randomNumber != 1)
|
||||
for (var j = 0; j < dices.Count; j++)
|
||||
{
|
||||
toInsert = j;
|
||||
break;
|
||||
if (values[j] < randomNumber)
|
||||
{
|
||||
toInsert = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
toInsert = dices.Count;
|
||||
}
|
||||
dices.Insert(toInsert, GetDice(randomNumber));
|
||||
values.Insert(toInsert, randomNumber);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user