Make the bot re-attribute roles before sending PMs if the game ends on first night.
This commit is contained in:
parent
3857954d9e
commit
28f4e0a2dd
@ -332,6 +332,7 @@ def reset_modes_timers(cli):
|
|||||||
def reset():
|
def reset():
|
||||||
var.PHASE = "none" # "join", "day", or "night"
|
var.PHASE = "none" # "join", "day", or "night"
|
||||||
var.GAME_ID = 0
|
var.GAME_ID = 0
|
||||||
|
var.RESTART_TRIES = 0
|
||||||
var.DEAD = []
|
var.DEAD = []
|
||||||
var.ROLES = {"person" : []}
|
var.ROLES = {"person" : []}
|
||||||
var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks)
|
var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks)
|
||||||
@ -1800,8 +1801,10 @@ def chk_traitor(cli):
|
|||||||
'frightened as they hear a loud howl. The wolves are '+
|
'frightened as they hear a loud howl. The wolves are '+
|
||||||
'not gone!\u0002'))
|
'not gone!\u0002'))
|
||||||
|
|
||||||
def stop_game(cli, winner = ""):
|
def stop_game(cli, winner = "", abort = False):
|
||||||
chan = botconfig.CHANNEL
|
chan = botconfig.CHANNEL
|
||||||
|
if abort:
|
||||||
|
cli.msg(chan, "The role attribution failed 3 times. Game was canceled.")
|
||||||
if var.DAY_START_TIME:
|
if var.DAY_START_TIME:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
td = now - var.DAY_START_TIME
|
td = now - var.DAY_START_TIME
|
||||||
@ -1820,6 +1823,8 @@ def stop_game(cli, winner = ""):
|
|||||||
"\u0002{4:0>2}:{5:0>2}\u0002 was night. ").format(tmin, tsec,
|
"\u0002{4:0>2}:{5:0>2}\u0002 was night. ").format(tmin, tsec,
|
||||||
daymin, daysec,
|
daymin, daysec,
|
||||||
nitemin, nitesec)
|
nitemin, nitesec)
|
||||||
|
|
||||||
|
if not abort:
|
||||||
cli.msg(chan, gameend_msg)
|
cli.msg(chan, gameend_msg)
|
||||||
|
|
||||||
roles_msg = []
|
roles_msg = []
|
||||||
@ -1863,6 +1868,7 @@ def stop_game(cli, winner = ""):
|
|||||||
var.plural(role)))
|
var.plural(role)))
|
||||||
message = ""
|
message = ""
|
||||||
count = 0
|
count = 0
|
||||||
|
if not abort:
|
||||||
cli.msg(chan, var.break_long_message(roles_msg))
|
cli.msg(chan, var.break_long_message(roles_msg))
|
||||||
|
|
||||||
done = {}
|
done = {}
|
||||||
@ -5142,6 +5148,10 @@ def transition_night(cli):
|
|||||||
var.DYING.append(elder)
|
var.DYING.append(elder)
|
||||||
debuglog(elder, "ELDER DEATH")
|
debuglog(elder, "ELDER DEATH")
|
||||||
|
|
||||||
|
if var.FIRST_NIGHT and chk_win(cli, end_game=False): # prevent game from ending as soon as it begins (useful for the random game mode)
|
||||||
|
start(cli, botconfig.NICK, botconfig.CHANNEL, restart=var.CURRENT_GAMEMODE)
|
||||||
|
return
|
||||||
|
|
||||||
# game ended from bitten / amnesiac turning, narcolepsy totem expiring, or other weirdness
|
# game ended from bitten / amnesiac turning, narcolepsy totem expiring, or other weirdness
|
||||||
if chk_win(cli):
|
if chk_win(cli):
|
||||||
return
|
return
|
||||||
@ -5669,14 +5679,21 @@ def fstart(cli, nick, chan, rest):
|
|||||||
"""Starts a game of Werewolf."""
|
"""Starts a game of Werewolf."""
|
||||||
start(cli, nick, chan)
|
start(cli, nick, chan)
|
||||||
|
|
||||||
def start(cli, nick, chan, forced = False):
|
def start(cli, nick, chan, forced = False, restart = ""):
|
||||||
if (not forced and var.LAST_START and nick in var.LAST_START and
|
if (not forced and var.LAST_START and nick in var.LAST_START and
|
||||||
var.LAST_START[nick] + timedelta(seconds=var.START_RATE_LIMIT) >
|
var.LAST_START[nick] + timedelta(seconds=var.START_RATE_LIMIT) >
|
||||||
datetime.now()):
|
datetime.now() and not restart):
|
||||||
cli.notice(nick, ("This command is rate-limited. Please wait a while "
|
cli.notice(nick, ("This command is rate-limited. Please wait a while "
|
||||||
"before using it again."))
|
"before using it again."))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if restart:
|
||||||
|
var.RESTART_TRIES += 1
|
||||||
|
if var.RESTART_TRIES > 3:
|
||||||
|
stop_game(cli, abort=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if not restart:
|
||||||
var.LAST_START[nick] = datetime.now()
|
var.LAST_START[nick] = datetime.now()
|
||||||
|
|
||||||
if chan != botconfig.CHANNEL:
|
if chan != botconfig.CHANNEL:
|
||||||
@ -5685,6 +5702,7 @@ def start(cli, nick, chan, forced = False):
|
|||||||
villagers = var.list_players()
|
villagers = var.list_players()
|
||||||
pl = villagers[:]
|
pl = villagers[:]
|
||||||
|
|
||||||
|
if not restart:
|
||||||
if var.PHASE == "none":
|
if var.PHASE == "none":
|
||||||
cli.notice(nick, "No game is currently running.")
|
cli.notice(nick, "No game is currently running.")
|
||||||
return
|
return
|
||||||
@ -5726,6 +5744,10 @@ def start(cli, nick, chan, forced = False):
|
|||||||
possiblegamemodes += [gamemode]*(var.GAME_MODES[gamemode][3]+votes.get(gamemode, 0)*15)
|
possiblegamemodes += [gamemode]*(var.GAME_MODES[gamemode][3]+votes.get(gamemode, 0)*15)
|
||||||
cgamemode(cli, random.choice(possiblegamemodes))
|
cgamemode(cli, random.choice(possiblegamemodes))
|
||||||
|
|
||||||
|
else:
|
||||||
|
cgamemode(cli, restart)
|
||||||
|
var.GAME_ID = time.time() # restart reaper timer
|
||||||
|
|
||||||
for index in range(len(var.ROLE_INDEX) - 1, -1, -1):
|
for index in range(len(var.ROLE_INDEX) - 1, -1, -1):
|
||||||
if var.ROLE_INDEX[index] <= len(villagers):
|
if var.ROLE_INDEX[index] <= len(villagers):
|
||||||
addroles = {k:v[index] for k,v in var.ROLE_GUIDE.items()}
|
addroles = {k:v[index] for k,v in var.ROLE_GUIDE.items()}
|
||||||
@ -5734,7 +5756,7 @@ def start(cli, nick, chan, forced = False):
|
|||||||
cli.msg(chan, "{0}: No game settings are defined for \u0002{1}\u0002 player games.".format(nick, len(villagers)))
|
cli.msg(chan, "{0}: No game settings are defined for \u0002{1}\u0002 player games.".format(nick, len(villagers)))
|
||||||
return
|
return
|
||||||
|
|
||||||
if var.ORIGINAL_SETTINGS: # Custom settings
|
if var.ORIGINAL_SETTINGS and not restart: # Custom settings
|
||||||
while True:
|
while True:
|
||||||
wvs = sum(addroles[r] for r in var.WOLFCHAT_ROLES)
|
wvs = sum(addroles[r] for r in var.WOLFCHAT_ROLES)
|
||||||
if len(villagers) < (sum(addroles.values()) - sum([addroles[r] for r in var.TEMPLATE_RESTRICTIONS.keys()])):
|
if len(villagers) < (sum(addroles.values()) - sum([addroles[r] for r in var.TEMPLATE_RESTRICTIONS.keys()])):
|
||||||
@ -5752,7 +5774,7 @@ def start(cli, nick, chan, forced = False):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if var.ADMIN_TO_PING:
|
if var.ADMIN_TO_PING and not restart:
|
||||||
if "join" in COMMANDS.keys():
|
if "join" in COMMANDS.keys():
|
||||||
COMMANDS["join"] = [lambda *spam: cli.msg(chan, "This command has been disabled by an admin.")]
|
COMMANDS["join"] = [lambda *spam: cli.msg(chan, "This command has been disabled by an admin.")]
|
||||||
if "j" in COMMANDS.keys():
|
if "j" in COMMANDS.keys():
|
||||||
@ -5760,6 +5782,7 @@ def start(cli, nick, chan, forced = False):
|
|||||||
if "start" in COMMANDS.keys():
|
if "start" in COMMANDS.keys():
|
||||||
COMMANDS["start"] = [lambda *spam: cli.msg(chan, "This command has been disabled by an admin.")]
|
COMMANDS["start"] = [lambda *spam: cli.msg(chan, "This command has been disabled by an admin.")]
|
||||||
|
|
||||||
|
if not restart: # will already be stored if restarting
|
||||||
var.ALL_PLAYERS = copy.copy(var.ROLES["person"])
|
var.ALL_PLAYERS = copy.copy(var.ROLES["person"])
|
||||||
var.ROLES = {}
|
var.ROLES = {}
|
||||||
var.GUNNERS = {}
|
var.GUNNERS = {}
|
||||||
@ -5879,6 +5902,7 @@ def start(cli, nick, chan, forced = False):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if not restart:
|
||||||
var.SPECIAL_ROLES["goat herder"] = []
|
var.SPECIAL_ROLES["goat herder"] = []
|
||||||
if var.GOAT_HERDER:
|
if var.GOAT_HERDER:
|
||||||
var.SPECIAL_ROLES["goat herder"] = [ nick ]
|
var.SPECIAL_ROLES["goat herder"] = [ nick ]
|
||||||
@ -5889,6 +5913,7 @@ def start(cli, nick, chan, forced = False):
|
|||||||
var.TIMERS[name][0].cancel()
|
var.TIMERS[name][0].cancel()
|
||||||
del var.TIMERS[name]
|
del var.TIMERS[name]
|
||||||
|
|
||||||
|
if not restart:
|
||||||
cli.msg(chan, ("{0}: Welcome to Werewolf, the popular detective/social party "+
|
cli.msg(chan, ("{0}: Welcome to Werewolf, the popular detective/social party "+
|
||||||
"game (a theme of Mafia). Using the \002{1}\002 game mode.").format(", ".join(pl), var.CURRENT_GAMEMODE))
|
"game (a theme of Mafia). Using the \002{1}\002 game mode.").format(", ".join(pl), var.CURRENT_GAMEMODE))
|
||||||
cli.mode(chan, "+m")
|
cli.mode(chan, "+m")
|
||||||
@ -5940,6 +5965,8 @@ def start(cli, nick, chan, forced = False):
|
|||||||
templates = "None"
|
templates = "None"
|
||||||
debuglog("TEMPLATES:", templates)
|
debuglog("TEMPLATES:", templates)
|
||||||
|
|
||||||
|
if restart:
|
||||||
|
var.PHASE = None # allow transition_* to run properly if game was restarted on first night
|
||||||
var.FIRST_NIGHT = True
|
var.FIRST_NIGHT = True
|
||||||
if not var.START_WITH_DAY:
|
if not var.START_WITH_DAY:
|
||||||
var.GAMEPHASE = "night"
|
var.GAMEPHASE = "night"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user