Browse Source

add optional night time warning, not enabled by default

master
jcao219 12 years ago
parent
commit
eeea079a6c
  1. 58
      modules/wolfgame.py
  2. 1
      settings/wolfgame.py

58
modules/wolfgame.py

@ -51,7 +51,7 @@ var.DCED_PLAYERS = {} @@ -51,7 +51,7 @@ var.DCED_PLAYERS = {}
var.ADMIN_TO_PING = None
var.AFTER_FLASTGAME = None
var.PHASE = "none" # "join", "day", or "night"
var.TIMERS = [None, None]
var.TIMERS = {}
var.DEAD = []
var.ORIGINAL_SETTINGS = {}
@ -157,12 +157,10 @@ def reset(cli): @@ -157,12 +157,10 @@ def reset(cli):
chan = botconfig.CHANNEL
var.PHASE = "none"
if var.TIMERS[0]:
var.TIMERS[0].cancel()
var.TIMERS[0] = None
if var.TIMERS[1]:
var.TIMERS[1].cancel()
var.TIMERS[1] = None
for x, timr in var.TIMERS.items():
timr.cancel()
var.TIMERS = {}
var.GAME_ID = 0
cli.mode(chan, "-m")
@ -554,9 +552,10 @@ def hurry_up(cli, gameid, change): @@ -554,9 +552,10 @@ def hurry_up(cli, gameid, change):
"are no votes or an even split.\02"))
if not var.DAY_TIME_LIMIT_CHANGE:
return
var.TIMERS[1] = threading.Timer(var.DAY_TIME_LIMIT_CHANGE, hurry_up, [cli, var.DAY_ID, True])
var.TIMERS[1].daemon = True
var.TIMERS[1].start()
tmr = threading.Timer(var.DAY_TIME_LIMIT_CHANGE, hurry_up, [cli, var.DAY_ID, True])
tmr.daemon = True
var.TIMERS["day"] = tmr
tmr.start()
return
@ -1222,11 +1221,21 @@ def begin_day(cli): @@ -1222,11 +1221,21 @@ def begin_day(cli):
if var.DAY_TIME_LIMIT_WARN > 0: # Time limit enabled
var.DAY_ID = time.time()
t = threading.Timer(var.DAY_TIME_LIMIT_WARN, hurry_up, [cli, var.DAY_ID, False])
var.TIMERS[1] = t
var.TIMERS[1].daemon = True
var.TIMERS["day_warn"] = t
t.daemon = True
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):
if gameid:
@ -1395,9 +1404,10 @@ def chk_nightdone(cli): @@ -1395,9 +1404,10 @@ def chk_nightdone(cli):
if len(set(var.KILLS.values())) > 1:
return
if var.TIMERS[0]:
var.TIMERS[0].cancel() # cancel timer
var.TIMERS[0] = None
for x, t in var.TIMERS.items():
t.cancel()
var.TIMERS = {}
if var.PHASE == "night": # Double check
transition_day(cli)
@ -1993,9 +2003,9 @@ def transition_night(cli): @@ -1993,9 +2003,9 @@ def transition_night(cli):
return
var.PHASE = "night"
if var.TIMERS[1]: # cancel daytime-limit timer
var.TIMERS[1].cancel()
var.TIMERS[1] = None
for x, tmr in var.TIMERS.items(): # cancel daytime timer
tmr.cancel()
var.TIMERS = {}
# Reset nighttime variables
var.KILLS = {}
@ -2020,9 +2030,15 @@ def transition_night(cli): @@ -2020,9 +2030,15 @@ def transition_night(cli):
if var.NIGHT_TIME_LIMIT > 0:
var.NIGHT_ID = time.time()
t = threading.Timer(var.NIGHT_TIME_LIMIT, transition_day, [cli, var.NIGHT_ID])
var.TIMERS[0] = t
var.TIMERS[0].daemon = True
var.TIMERS["night"] = t
var.TIMERS["night"].daemon = True
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
ps = var.list_players()

1
settings/wolfgame.py

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

Loading…
Cancel
Save