Clean up win checks, and properly detect if clone won. Closes #48

This commit is contained in:
skizzerz 2014-07-27 14:02:40 -05:00
parent 3698e6d6bf
commit 16b3f36eb3

View File

@ -1059,69 +1059,77 @@ def stop_game(cli, winner = ""):
elif len(lovers) > 2: elif len(lovers) > 2:
cli.msg(chan, "The lovers were {0}, and {1}".format(", ".join(lovers[0:-1]), lovers[-1])) cli.msg(chan, "The lovers were {0}, and {1}".format(", ".join(lovers[0:-1]), lovers[-1]))
plrl = [] plrl = {}
winners = [] winners = []
for role,ppl in var.ORIGINAL_ROLES.items(): for role,ppl in var.ORIGINAL_ROLES.items():
if role in var.TEMPLATE_RESTRICTIONS.keys(): if role in var.TEMPLATE_RESTRICTIONS.keys():
continue continue
for x in ppl: for x in ppl:
if x != None: if x != None:
plrl.append((x, role)) plrl[x] = role
for plr, rol in plrl: for plr, rol in plrl.items():
#if plr not in var.USERS.keys(): # they died TODO: when a player leaves, count the game as lost for them orol = rol # original role, since we overwrite rol in case of clone
# if plr in var.DEAD_USERS.keys(): splr = plr # plr stripped of the (dced) bit at the front, since other dicts don't have that
# acc = var.DEAD_USERS[plr]["account"]
# else:
# continue # something wrong happened
#else:
if plr.startswith("(dced)") and plr[6:] in var.DCED_PLAYERS.keys(): if plr.startswith("(dced)") and plr[6:] in var.DCED_PLAYERS.keys():
acc = var.DCED_PLAYERS[plr[6:]]["account"] acc = var.DCED_PLAYERS[plr[6:]]["account"]
splr = plr[6:]
elif plr in var.PLAYERS.keys(): elif plr in var.PLAYERS.keys():
acc = var.PLAYERS[plr]["account"] acc = var.PLAYERS[plr]["account"]
else: else:
acc = "*" #probably fjoin'd fake acc = "*" #probably fjoin'd fake
if rol == "clone":
# see if they became a different role
if splr in var.FINAL_ROLES:
rol = var.FINAL_ROLES[splr]
won = False won = False
iwon = False iwon = False
# determine if this player's team won # determine if this player's team won
if plr in [p for r in var.WOLFTEAM_ROLES for p in var.ORIGINAL_ROLES[r]]: # the player was wolf-aligned if rol in var.WOLFTEAM_ROLES: # the player was wolf-aligned
if winner == "wolves": if winner == "wolves":
won = True won = True
elif plr in [p for r in var.TRUE_NEUTRAL_ROLES for p in var.ORIGINAL_ROLES[r]]: elif rol in var.TRUE_NEUTRAL_ROLES:
# true neutral roles never have a team win (with exception of monsters), only individual wins # true neutral roles never have a team win (with exception of monsters), only individual wins
if winner == "monsters" and plr in var.ORIGINAL_ROLES["monster"]: if winner == "monsters" and rol == "monster":
won = True won = True
else: else:
if winner == "villagers": if winner == "villagers":
won = True won = True
survived = var.list_players() survived = var.list_players()
splr = plr
if plr.startswith("(dced)"): if plr.startswith("(dced)"):
splr = plr[6:]
# You get NOTHING! You LOSE! Good DAY, sir! # You get NOTHING! You LOSE! Good DAY, sir!
won = False won = False
iwon = False iwon = False
elif plr in var.ORIGINAL_ROLES["fool"] and "@" + splr == winner: elif rol == "fool" and "@" + splr == winner:
iwon = True iwon = True
elif plr in var.ORIGINAL_ROLES["monster"] and splr in survived and winner == "monsters": elif rol == "monster" and splr in survived and winner == "monsters":
iwon = True iwon = True
# del_player() doesn't get called on lynched fool, so both will survive even in that case # del_player() doesn't get called on lynched fool, so both will survive even in that case
elif splr in var.LOVERS and splr in survived: elif splr in var.LOVERS and splr in survived:
for lvr in var.LOVERS[splr]: for lvr in var.LOVERS[splr]:
if lvr in plrl:
lvrrol = plrl[lvr]
elif ("(dced)" + lvr) in plrl:
lvrrol = plrrl["(dced)" + lvr]
if lvrrol == "clone" and lvr in var.FINAL_ROLES:
lvrrol = var.FINAL_ROLES[lvr]
if lvr in survived and not winner.startswith("@") and winner != "monsters": if lvr in survived and not winner.startswith("@") and winner != "monsters":
iwon = True iwon = True
break break
elif lvr in survived and winner.startswith("@") and winner == "@" + lvr: elif lvr in survived and winner.startswith("@") and winner == "@" + lvr:
iwon = True iwon = True
break break
elif lvr in survived and winner == "monsters" and lvr in var.ORIGINAL_ROLES["monster"]: elif lvr in survived and winner == "monsters" and lvrrol == "monster":
iwon = True iwon = True
break break
if plr in var.ORIGINAL_ROLES["crazed shaman"]: if rol == "crazed shaman" or rol == "clone":
# For clone, this means they ended game while being clone and not some other role
if splr in survived and not winner.startswith("@") and winner != "monsters": if splr in survived and not winner.startswith("@") and winner != "monsters":
iwon = True iwon = True
elif plr in var.ORIGINAL_ROLES["vengeful ghost"]: elif rol == "vengeful ghost":
if not winner.startswith("@") and winner != "monsters": if not winner.startswith("@") and winner != "monsters":
if splr in survived: if splr in survived:
iwon = True iwon = True
@ -1131,7 +1139,7 @@ def stop_game(cli, winner = ""):
elif splr in var.VENGEFUL_GHOSTS and var.VENGEFUL_GHOSTS[splr] == "wolves" and winner == "villagers": elif splr in var.VENGEFUL_GHOSTS and var.VENGEFUL_GHOSTS[splr] == "wolves" and winner == "villagers":
won = True won = True
iwon = True iwon = True
elif plr in var.ORIGINAL_ROLES["lycan"]: elif rol == "lycan":
if splr in var.LYCANS and winner == "wolves": if splr in var.LYCANS and winner == "wolves":
won = True won = True
elif splr not in var.LYCANS and winner == "villagers": elif splr not in var.LYCANS and winner == "villagers":
@ -1144,7 +1152,7 @@ def stop_game(cli, winner = ""):
iwon = won and splr in survived # survived, team won = individual win iwon = won and splr in survived # survived, team won = individual win
if acc != "*": if acc != "*":
var.update_role_stats(acc, rol, won, iwon) var.update_role_stats(acc, orol, won, iwon)
if won or iwon: if won or iwon:
winners.append(splr) winners.append(splr)