Browse Source

add optional night time warning, not enabled by default

master
jcao219 13 years ago
parent
commit
eeea079a6c
  1. 56
      modules/wolfgame.py
  2. 1
      settings/wolfgame.py

56
modules/wolfgame.py

@ -51,7 +51,7 @@ var.DCED_PLAYERS = {}
var.ADMIN_TO_PING = None var.ADMIN_TO_PING = None
var.AFTER_FLASTGAME = None var.AFTER_FLASTGAME = None
var.PHASE = "none" # "join", "day", or "night" var.PHASE = "none" # "join", "day", or "night"
var.TIMERS = [None, None] var.TIMERS = {}
var.DEAD = [] var.DEAD = []
var.ORIGINAL_SETTINGS = {} var.ORIGINAL_SETTINGS = {}
@ -157,12 +157,10 @@ def reset(cli):
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
var.PHASE = "none" var.PHASE = "none"
if var.TIMERS[0]: for x, timr in var.TIMERS.items():
var.TIMERS[0].cancel() timr.cancel()
var.TIMERS[0] = None var.TIMERS = {}
if var.TIMERS[1]:
var.TIMERS[1].cancel()
var.TIMERS[1] = None
var.GAME_ID = 0 var.GAME_ID = 0
cli.mode(chan, "-m") cli.mode(chan, "-m")
@ -554,9 +552,10 @@ def hurry_up(cli, gameid, change):
"are no votes or an even split.\02")) "are no votes or an even split.\02"))
if not var.DAY_TIME_LIMIT_CHANGE: if not var.DAY_TIME_LIMIT_CHANGE:
return return
var.TIMERS[1] = threading.Timer(var.DAY_TIME_LIMIT_CHANGE, hurry_up, [cli, var.DAY_ID, True]) tmr = threading.Timer(var.DAY_TIME_LIMIT_CHANGE, hurry_up, [cli, var.DAY_ID, True])
var.TIMERS[1].daemon = True tmr.daemon = True
var.TIMERS[1].start() var.TIMERS["day"] = tmr
tmr.start()
return return
@ -1222,11 +1221,21 @@ def begin_day(cli):
if var.DAY_TIME_LIMIT_WARN > 0: # Time limit enabled if var.DAY_TIME_LIMIT_WARN > 0: # Time limit enabled
var.DAY_ID = time.time() var.DAY_ID = time.time()
t = threading.Timer(var.DAY_TIME_LIMIT_WARN, hurry_up, [cli, var.DAY_ID, False]) t = threading.Timer(var.DAY_TIME_LIMIT_WARN, hurry_up, [cli, var.DAY_ID, False])
var.TIMERS[1] = t var.TIMERS["day_warn"] = t
var.TIMERS[1].daemon = True t.daemon = True
t.start() t.start()
def night_warn(cli, gameid):
if gameid != var.NIGHT_ID:
return
if var.PHASE == "day":
return
cli.msg(botconfig.CHANNEL, ("\02A few villagers awake early and notice it " +
"is still dark outside. " +
"The night is almost over and there are " +
"still whispers heard in the village.\02"))
def transition_day(cli, gameid=0): def transition_day(cli, gameid=0):
if gameid: if gameid:
@ -1395,9 +1404,10 @@ def chk_nightdone(cli):
if len(set(var.KILLS.values())) > 1: if len(set(var.KILLS.values())) > 1:
return return
if var.TIMERS[0]: for x, t in var.TIMERS.items():
var.TIMERS[0].cancel() # cancel timer t.cancel()
var.TIMERS[0] = None
var.TIMERS = {}
if var.PHASE == "night": # Double check if var.PHASE == "night": # Double check
transition_day(cli) transition_day(cli)
@ -1993,9 +2003,9 @@ def transition_night(cli):
return return
var.PHASE = "night" var.PHASE = "night"
if var.TIMERS[1]: # cancel daytime-limit timer for x, tmr in var.TIMERS.items(): # cancel daytime timer
var.TIMERS[1].cancel() tmr.cancel()
var.TIMERS[1] = None var.TIMERS = {}
# Reset nighttime variables # Reset nighttime variables
var.KILLS = {} var.KILLS = {}
@ -2020,10 +2030,16 @@ def transition_night(cli):
if var.NIGHT_TIME_LIMIT > 0: if var.NIGHT_TIME_LIMIT > 0:
var.NIGHT_ID = time.time() var.NIGHT_ID = time.time()
t = threading.Timer(var.NIGHT_TIME_LIMIT, transition_day, [cli, var.NIGHT_ID]) t = threading.Timer(var.NIGHT_TIME_LIMIT, transition_day, [cli, var.NIGHT_ID])
var.TIMERS[0] = t var.TIMERS["night"] = t
var.TIMERS[0].daemon = True var.TIMERS["night"].daemon = True
t.start() t.start()
if var.NIGHT_TIME_WARN > 0:
t2 = threading.Timer(var.NIGHT_TIME_WARN, night_warn, [cli, var.NIGHT_ID])
var.TIMERS["night_warn"] = t2
var.TIMERS["night_warn"].daemon = True
t2.start()
# send PMs # send PMs
ps = var.list_players() ps = var.list_players()
wolves = var.ROLES["wolf"]+var.ROLES["traitor"]+var.ROLES["werecrow"] wolves = var.ROLES["wolf"]+var.ROLES["traitor"]+var.ROLES["werecrow"]

1
settings/wolfgame.py

@ -10,6 +10,7 @@ SHOTS_MULTIPLIER = .12 # ceil(shots_multiplier * len_players) = bullets given
MAX_PLAYERS = 30 MAX_PLAYERS = 30
DRUNK_SHOTS_MULTIPLIER = 3 DRUNK_SHOTS_MULTIPLIER = 3
NIGHT_TIME_LIMIT = 120 NIGHT_TIME_LIMIT = 120
NIGHT_TIME_WARN = 0 # should be less than NIGHT_TIME_LIMIT
DAY_TIME_LIMIT_WARN = 780 DAY_TIME_LIMIT_WARN = 780
DAY_TIME_LIMIT_CHANGE = 120 # seconds after DAY_TIME_LIMIT_WARN has passed DAY_TIME_LIMIT_CHANGE = 120 # seconds after DAY_TIME_LIMIT_WARN has passed
START_WITH_DAY = False START_WITH_DAY = False

Loading…
Cancel
Save