Stats is stats again, dices now have modifiers
This commit is contained in:
parent
61542c5a3e
commit
e57b80d4b4
2 changed files with 23 additions and 5 deletions
|
@ -19,33 +19,51 @@ namespace Geekbot.net.Modules
|
||||||
public async Task RollCommand([Remainder] [Summary("diceType")] string diceType = "1d6")
|
public async Task RollCommand([Remainder] [Summary("diceType")] string diceType = "1d6")
|
||||||
{
|
{
|
||||||
var dice = diceType.Split("d");
|
var dice = diceType.Split("d");
|
||||||
|
var maxAndMod = dice[1].Split("+");
|
||||||
|
|
||||||
if (dice.Length != 2
|
if (dice.Length != 2
|
||||||
|| !int.TryParse(dice[0], out int times)
|
|| !int.TryParse(dice[0], out int times)
|
||||||
|| !int.TryParse(dice[1], out int max))
|
|| !int.TryParse(maxAndMod[0], out int max))
|
||||||
{
|
{
|
||||||
await ReplyAsync("That is not a valid dice, examples are: 1d20, 1d6, 2d10, 5d12, etc...");
|
await ReplyAsync("That is not a valid dice, examples are: 1d20, 1d6, 2d10, 5d12, 1d20+5, 1d6+2, etc...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Console.WriteLine($"Max: {max} - Times {times}");
|
|
||||||
|
int modifier = 0;
|
||||||
|
if (maxAndMod.Length == 2 && !int.TryParse(maxAndMod[1], out modifier) || maxAndMod.Length > 2)
|
||||||
|
{
|
||||||
|
await ReplyAsync("That is not a valid dice, examples are: 1d20, 1d6, 2d10, 5d12, 1d20+5, 1d6+2, etc...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (times > 10 && !(times < 0))
|
if (times > 10 && !(times < 0))
|
||||||
{
|
{
|
||||||
await ReplyAsync("You can only roll between 1 and 10 dices");
|
await ReplyAsync("You can only roll between 1 and 10 dices");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max > 100 && !(max < 1))
|
if (max > 100 && !(max < 1))
|
||||||
{
|
{
|
||||||
await ReplyAsync("The dice must have between 1 and 100 sides");
|
await ReplyAsync("The dice must have between 1 and 100 sides");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder();
|
||||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||||
.WithIconUrl(Context.User.GetAvatarUrl())
|
.WithIconUrl(Context.User.GetAvatarUrl())
|
||||||
.WithName(Context.User.Username));
|
.WithName(Context.User.Username));
|
||||||
eb.WithColor(new Color(133, 189, 219));
|
eb.WithColor(new Color(133, 189, 219));
|
||||||
eb.Title = $":game_die: Dice Roll - Type {diceType} :game_die:";
|
eb.Title = $":game_die: Dice Roll - Type {diceType} :game_die:";
|
||||||
|
|
||||||
|
var total = 0;
|
||||||
for (var i = 0; i < times; i++)
|
for (var i = 0; i < times; i++)
|
||||||
eb.AddInlineField($"Dice {i + 1}", rnd.Next(1, max));
|
{
|
||||||
|
var roll = rnd.Next(1, max);
|
||||||
|
eb.AddInlineField($"Dice {i + 1}", roll);
|
||||||
|
total = total + roll;
|
||||||
|
}
|
||||||
|
|
||||||
|
eb.AddField("Total", modifier == 0 ? $"{total}" : $"{total} (+{modifier})");
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Geekbot.net.Modules
|
||||||
this.redis = redis;
|
this.redis = redis;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("user", RunMode = RunMode.Async)]
|
[Command("stats", RunMode = RunMode.Async)]
|
||||||
[Summary("Get information about this user")]
|
[Summary("Get information about this user")]
|
||||||
public async Task User([Summary("@someone")] IUser user = null)
|
public async Task User([Summary("@someone")] IUser user = null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue