From f646844aad30f64ea9b200a258217c14e68f92b3 Mon Sep 17 00:00:00 2001 From: nyuszika7h Date: Thu, 4 Dec 2014 11:23:24 +0100 Subject: [PATCH] Fix KeyError in chk_win This fixes the error with wolf cub that has been appearing for a while now, and also prevents similar errors from happening with monster and traitor in the same function. --- modules/wolfgame.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/wolfgame.py b/modules/wolfgame.py index cce50c8..d44f096 100644 --- a/modules/wolfgame.py +++ b/modules/wolfgame.py @@ -1293,7 +1293,10 @@ def chk_win(cli, end_game = True): return False lwolves = len(var.list_players(var.WOLFCHAT_ROLES)) - lrealwolves = len(var.list_players(var.WOLF_ROLES)) - len(var.ROLES["wolf cub"]) + cubs = len(var.ROLES["wolf cub"]) if "wolf cub" in var.ROLES else 0 + lrealwolves = len(var.list_players(var.WOLF_ROLES)) - cubs + monsters = len(var.ROLES["monster"]) if "monster" in var.ROLES else 0 + traitors = len(var.ROLES["traitor"]) if "traitor" in var.ROLES else 0 if var.PHASE == "day": for p in var.WOUNDED: try: @@ -1318,8 +1321,8 @@ def chk_win(cli, end_game = True): message = "Game over! There are no players remaining. Nobody wins." winner = "none" elif lwolves == lpl / 2: - if len(var.ROLES["monster"]) > 0: - plural = "s" if len(var.ROLES["monster"]) > 1 else "" + if monsters > 0: + plural = "s" if monsters > 1 else "" message = ("Game over! There are the same number of wolves as uninjured villagers. " + "The wolves overpower the villagers but then get destroyed by the monster{0}, " + "causing the monster{0} to win.").format(plural) @@ -1329,8 +1332,8 @@ def chk_win(cli, end_game = True): "uninjured villagers. The wolves overpower the villagers and win.") winner = "wolves" elif lwolves > lpl / 2: - if len(var.ROLES["monster"]) > 0: - plural = "s" if len(var.ROLES["monster"]) > 1 else "" + if monsters > 0: + plural = "s" if monsters > 1 else "" message = ("Game over! There are more wolves than uninjured villagers. " + "The wolves overpower the villagers but then get destroyed by the monster{0}, " + "causing the monster{0} to win.").format(plural) @@ -1339,9 +1342,9 @@ def chk_win(cli, end_game = True): message = ("Game over! There are more wolves than "+ "uninjured villagers. The wolves overpower the villagers and win.") winner = "wolves" - elif lrealwolves == 0 and len(var.ROLES["traitor"]) == 0 and len(var.ROLES["wolf cub"]) == 0: - if len(var.ROLES["monster"]) > 0: - plural = "s" if len(var.ROLES["monster"]) > 1 else "" + elif lrealwolves == 0 and traitors == 0 and cubs == 0: + if monsters > 0: + plural = "s" if monsters > 1 else "" message = ("Game over! All the wolves are dead! As the villagers start preparing the BBQ, " + "the monster{0} quickly kill{1} the remaining villagers, " + "causing the monster{0} to win.").format(plural, "" if plural else "s")