From f3d7e569ae7b87ee19c44e8d8672cd3dffdf0562 Mon Sep 17 00:00:00 2001 From: Janik Kleinhoff Date: Sun, 28 Sep 2014 08:05:21 +0200 Subject: [PATCH] frole: Adjust behaviour for templates; allow specifying totem The syntax to give 'foo' the additional 'bar' template is now !frole foo +bar or, in the case of templates like gunner that can take an argument, !frole foo +gunner = 9001 Removing a template uses - instead: !frole foo -bar The new "role = arg" syntax also applies for shamans and crazed shamans: !frole foo shaman = impatience A random totem is selected as usual, rather than the bot crashing, if no argument is given. --- modules/wolfgame.py | 63 +++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/modules/wolfgame.py b/modules/wolfgame.py index f6f4fc5..c6a8921 100644 --- a/modules/wolfgame.py +++ b/modules/wolfgame.py @@ -6041,28 +6041,57 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS: cli.msg(chan, "No.") return pl = var.list_players() - if rol in var.ROLES.keys() or rol.startswith("gunner") or rol.startswith("sharpshooter"): - if rol.startswith("gunner") or rol.startswith("sharpshooter"): - rolargs = re.split(" +",rol, 1) - rol = rolargs[0] - if len(rolargs) == 2 and rolargs[1].isdigit(): - if len(rolargs[1]) < 7: - var.GUNNERS[who] = int(rolargs[1]) - var.WOLF_GUNNERS[who] = int(rolargs[1]) + rolargs = re.split("\s*=\s*", rol, 1) + rol = rolargs[0] + if rol[1:] in var.TEMPLATE_RESTRICTIONS.keys(): + addrem = rol[0] + rol = rol[1:] + is_gunner = (rol == "gunner" or rol == "sharpshooter") + if addrem == "+" and who not in var.ROLES[rol]: + if is_gunner: + if len(rolargs) == 2 and rolargs[1].isdigit(): + if len(rolargs[1]) < 7: + var.GUNNERS[who] = int(rolargs[1]) + var.WOLF_GUNNERS[who] = int(rolargs[1]) + else: + var.GUNNERS[who] = 999 + var.WOLF_GUNNERS[who] = 999 + elif rol == "gunner": + var.GUNNERS[who] = math.ceil(var.SHOTS_MULTIPLIER * len(pl)) else: - var.GUNNERS[who] = 999 - var.WOLF_GUNNERS[who] = 999 - elif rol.startswith("gunner"): - var.GUNNERS[who] = math.ceil(var.SHOTS_MULTIPLIER * len(pl)) + var.GUNNERS[who] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl)) + var.ROLES[rol].append(who) + elif addrem == "-" and who in var.ROLES[rol]: + var.ROLES[rol].remove(who) + if is_gunner and who in var.GUNNERS: + del var.GUNNERS[who] + else: + cli.msg(chan, "Improper template modification.") + return + elif rol in var.TEMPLATE_RESTRICTIONS.keys(): + cli.msg(chan, "Please specify \u0002+{0}\u0002 or \u0002-{0}\u0002 to add/remove this template.".format(rol)) + return + elif rol in var.ROLES.keys(): + if who in pl: + oldrole = var.get_role(who) + var.ROLES[oldrole].remove(who) + if rol == "shaman" or rol == "crazed shaman": + if len(rolargs) == 2: + var.TOTEMS[who] = rolargs[1] else: - var.GUNNERS[who] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl)) + rand = random.random() + target = 0 + for t, c in var.TOTEM_CHANCES.items(): + target += var.TOTEM_CHANCES[t][0 if rol == "shaman" else 1] + if rand <= target: + var.TOTEMS[who] = t + break + else: + var.TOTEMS[who] = 'death' + var.ROLES[rol].append(who) else: cli.msg(chan, "Not a valid role.") return - if who in pl and rol not in var.TEMPLATE_RESTRICTIONS.keys(): - oldrole = var.get_role(who) - var.ROLES[oldrole].remove(who) - var.ROLES[rol].append(who) cli.msg(chan, "Operation successful.") if var.PHASE not in ('none','join'): chk_win(cli)