From f35729038e2fa65ec44f06bdf1f6e4bcd0586f3a Mon Sep 17 00:00:00 2001 From: un1c0rn Date: Sat, 12 Oct 2013 20:06:11 +0200 Subject: [PATCH] add a fate dice --- mod.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mod.c b/mod.c index 1afcb83..199d59b 100644 --- a/mod.c +++ b/mod.c @@ -1406,8 +1406,22 @@ static void command_no_deliver(struct bio *b, const char *nick, const char *host static void perform_roll(struct bio *b, const char *nick, const char *target, long sides, long dice, long bonus) { long rem = dice, total = bonus; + + if (!sides) { + // Fate dice.. + while (rem--) + total += (getrand() % 3) - 1; + + if (bonus) + action(b, target, "rolls %li fate %s for a total of %li (%+li)", dice, dice == 1 ? "die" : "dice", total, bonus); + else + action(b, target, "rolls %li fate %s for a total of %li", dice, dice == 1 ? "die" : "dice", total); + return; + } + while (rem--) total += 1 + (getrand() % sides); + if (bonus) action(b, target, "rolls %li %li-sided %s for a total of %li (%+li)", dice, sides, dice == 1 ? "die" : "dice", total, bonus); else @@ -1898,7 +1912,7 @@ void privmsg_hook(struct bio *b, const char *prefix, const char *ident, const ch char *end; long base; base = strtol(cmd+1, &end, 10); - if (base > 1 && base <= 20 && !*end) { + if ((base > 1 || !base) && base <= 20 && !*end) { long dice = 1, bonus = 0; char *strdice; c = &commands[strhash("roll") % elements(commands)]; @@ -1934,8 +1948,8 @@ syntax: char *end; dice = strtol(cmd, &end, 10); if (dice >= 1 && dice <= 25 && *end == 'd' && - (sides = strtol(end+1, &end, 10)) && - sides > 1 && sides <= 20 && !*end) { + ((sides = strtol(end+1, &end, 10)) > 1 || !sides) && + sides <= 20 && !*end) { char *strbonus; c = &commands[strhash("roll") % elements(commands)]; -- 2.11.4.GIT