Properly fix time lord issues

When resetting the timer, only reset it if we would be decreasing
the time remaining, never increase it. Also, use > 0 checks instead of
checking for debug mode to be consistent with the rest of the code, and
so that the next commit works properly.

The funky checks are because in debug mode (as of next commit) it will
be possible to enable certain subsets of timers, and these checks are
needed to prevent things from breaking when some subsets are enabled but
others are not.
This commit is contained in:
skizzerz 2015-03-22 12:21:13 -05:00
parent aefd9cf5ab
commit 8b2023f133

View File

@ -2384,19 +2384,35 @@ def del_player(cli, nick, forced_death = False, devoice = True, end_game = True,
cli.msg(botconfig.CHANNEL, ("Tick tock! Since the time lord has died, " + cli.msg(botconfig.CHANNEL, ("Tick tock! Since the time lord has died, " +
"day will now only last {0} seconds and night will now only " + "day will now only last {0} seconds and night will now only " +
"last {1} seconds!").format(var.TIME_LORD_DAY_LIMIT, var.TIME_LORD_NIGHT_LIMIT)) "last {1} seconds!").format(var.TIME_LORD_DAY_LIMIT, var.TIME_LORD_NIGHT_LIMIT))
if var.PHASE == "day" and not botconfig.DEBUG_MODE: if var.GAMEPHASE == "day" and timeleft_internal("day") > var.DAY_TIME_LIMIT and var.DAY_TIME_LIMIT > 0:
if "day" in var.TIMERS: if "day" in var.TIMERS:
var.TIMERS["day"][0].cancel() var.TIMERS["day"][0].cancel()
if "day_warn" in var.TIMERS and var.TIMERS["day_warn"][0].isAlive(): t = threading.Timer(var.DAY_TIME_LIMIT, hurry_up, [cli, var.DAY_ID, True])
var.TIMERS["day_warn"][0].cancel() var.TIMERS["day"] = (t, time.time(), var.DAY_TIME_LIMIT)
t = threading.Timer(var.TIME_LORD_DAY_LIMIT, hurry_up, [cli, var.DAY_ID, True])
var.TIMERS["day"] = (t, time.time(), var.TIME_LORD_DAY_LIMIT)
t.daemon = True t.daemon = True
t.start() t.start()
tw = threading.Timer(var.TIME_LORD_DAY_WARN, hurry_up, [cli, var.DAY_ID, False]) # Don't duplicate warnings, e.g. only set the warn timer if a warning was not already given
var.TIMERS["day_warn"] = (tw, time.time(), var.TIME_LORD_DAY_WARN) if "day_warn" in var.TIMERS and var.TIMERS["day_warn"][0].isAlive():
tw.daemon = True var.TIMERS["day_warn"][0].cancel()
tw.start() t = threading.Timer(var.DAY_TIME_WARN, hurry_up, [cli, var.DAY_ID, False])
var.TIMERS["day_warn"] = (t, time.time(), var.DAY_TIME_WARN)
t.daemon = True
t.start()
elif var.GAMEPHASE == "night" and timeleft_internal("night") > var.NIGHT_TIME_LIMIT and var.NIGHT_TIME_LIMIT > 0:
if "night" in var.TIMERS:
var.TIMERS["night"][0].cancel()
t = threading.Timer(var.NIGHT_TIME_LIMIT, hurry_up, [cli, var.NIGHT_ID, True])
var.TIMERS["night"] = (t, time.time(), var.NIGHT_TIME_LIMIT)
t.daemon = True
t.start()
# Don't duplicate warnings, e.g. only set the warn timer if a warning was not already given
if "night_warn" in var.TIMERS and var.TIMERS["night_warn"][0].isAlive():
var.TIMERS["night_warn"][0].cancel()
t = threading.Timer(var.NIGHT_TIME_WARN, hurry_up, [cli, var.NIGHT_ID, False])
var.TIMERS["night_warn"] = (t, time.time(), var.NIGHT_TIME_WARN)
t.daemon = True
t.start()
debuglog(nick, "(time lord) TRIGGER") debuglog(nick, "(time lord) TRIGGER")
if nickrole == "vengeful ghost": if nickrole == "vengeful ghost":
if killer_role in var.WOLFTEAM_ROLES: if killer_role in var.WOLFTEAM_ROLES:
@ -6738,8 +6754,7 @@ def timeleft(cli, nick, chan, rest):
var.LAST_TIME = datetime.now() var.LAST_TIME = datetime.now()
if var.PHASE in var.TIMERS: if var.PHASE in var.TIMERS:
t = var.TIMERS[var.PHASE] remaining = timeleft_internal(var.PHASE)
remaining = int((t[1] + t[2]) - time.time())
if var.PHASE == "day": if var.PHASE == "day":
what = "sunset" what = "sunset"
elif var.PHASE == "night": elif var.PHASE == "night":
@ -6757,6 +6772,9 @@ def timeleft(cli, nick, chan, rest):
else: else:
cli.msg(chan, msg) cli.msg(chan, msg)
def timeleft_internal(phase):
return int((var.TIMERS[phase][1] + var.TIMERS[phase][2]) - time.time()) if phase in var.TIMERS else -1
@cmd("roles", pm=True) @cmd("roles", pm=True)
def listroles(cli, nick, chan, rest): def listroles(cli, nick, chan, rest):
"""Displays which roles are enabled at a certain number of players.""" """Displays which roles are enabled at a certain number of players."""