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.
This commit is contained in:
parent
6e372566c6
commit
f646844aad
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user