Browse Source

finished day/night transitioning stuff

master
jcao219 14 years ago
parent
commit
e226a0968c
  1. 6
      vars.py
  2. 10
      wolfbot.py
  3. 92
      wolfgame.py

6
vars.py

@ -4,6 +4,7 @@ EXTRA_WAIT = 20
MAXIMUM_WAITED = 2 # limit for amount of !wait's MAXIMUM_WAITED = 2 # limit for amount of !wait's
MAX_SHOTS = 2 MAX_SHOTS = 2
NIGHT_TIME_LIMIT = 90 NIGHT_TIME_LIMIT = 90
DAY_TIME_LIMIT = 137
####################################################################################### #######################################################################################
# PLAYERS SEER WOLF CURSED DRUNK HARLOT TRAITOR GUNNER # # PLAYERS SEER WOLF CURSED DRUNK HARLOT TRAITOR GUNNER #
@ -18,7 +19,10 @@ ROLES_GUIDE = { 4 : ( 1 , 1 , 0 , 0 , 0 , 0 , 0
NO_VICTIMS_MESSAGES = ("The body of a young penguin pet is found.", NO_VICTIMS_MESSAGES = ("The body of a young penguin pet is found.",
"A pool of blood and wolf paw prints are found.", "A pool of blood and wolf paw prints are found.",
"Traces of wolf fur are found.") "Traces of wolf fur are found.")
LYNCH_MESSAGES = ("The villagers, after much debate, finally decide on lynching \u0002{0}\u0002, who turned out to be... a \u0002{1}\u0002.",
"Under a lot of noise, the pitchfork-bearing villagers lynch \u0002{0}\u0002, who turned out to be... a \u0002{1}\u0002.",
"The mob drags a protesting \u0002{0}\u0002 to the hanging tree. S/He succumbs to the will of the horde, and is hanged. It is discovered (s)he was a \u0002{1}\u0002.",
"Resigned to his/her fate, \u0002{0}\u0002 is led to the gallows. After death, it is discovered (s)he was a \u0002{1}\u0002.")
# These change ingame # These change ingame

10
wolfbot.py

@ -13,13 +13,15 @@ class WolfBotHandler(DefaultCommandHandler):
if chan != botconfig.NICK: #not a PM if chan != botconfig.NICK: #not a PM
for x in wolfgame.COMMANDS.keys(): for x in wolfgame.COMMANDS.keys():
if msg.startswith(x): if msg.startswith(x):
h = msg.replace(x, "", 1).lstrip() h = msg.replace(x, "", 1)
wolfgame.COMMANDS[x](self.client, rawnick, chan, h) if not h or h[0] == " " or not x:
wolfgame.COMMANDS[x](self.client, rawnick, chan, h.lstrip())
else: else:
for x in wolfgame.PM_COMMANDS.keys(): for x in wolfgame.PM_COMMANDS.keys():
if msg.startswith(x): if msg.startswith(x):
h = msg.replace(x, "", 1).lstrip() h = msg.replace(x, "", 1)
wolfgame.PM_COMMANDS[x](self.client, rawnick, h) if not h or h[0] == " " or not x:
wolfgame.PM_COMMANDS[x](self.client, rawnick, h.lstrip())
@protected @protected
def __unhandled__(self, cmd, *args): def __unhandled__(self, cmd, *args):

92
wolfgame.py

@ -37,8 +37,8 @@ def reset(cli):
vars.TIMERS[0].cancel() vars.TIMERS[0].cancel()
vars.TIMERS[0] = None vars.TIMERS[0] = None
if vars.TIMERS[1]: if vars.TIMERS[1]:
vars.TIMERS[0].cancel() vars.TIMERS[1].cancel()
vars.TIMERS[0] = None vars.TIMERS[1] = None
cli.mode(chan, "-m") cli.mode(chan, "-m")
for plr in vars.list_players(): for plr in vars.list_players():
@ -189,6 +189,45 @@ def stats(cli, nick, chan, rest):
def hurry_up(cli):
if vars.PHASE != "day": return
chan = botconfig.CHANNEL
pl = vars.list_players()
avail = len(pl) - len(vars.WOUNDED)
votesneeded = avail // 2 + 1
found_dup = False
max = (0, "")
for votee, voters in iter(vars.VOTES.items()):
if len(voters) > max[0]:
max = (len(voters), votee)
found_dup = False
elif len(voters) == max[0]:
found_dup = True
if max[0] > 0 and not found_dup:
vars.VOTES[max[1]] = [None] * votesneeded
chk_decision(cli) # Induce a lynch
else:
cli.msg(chan, "The sun is almost setting.")
for plr in pl:
vars.VOTES[plr] = [None] * (votesneeded - 1)
def chk_decision(cli):
chan = botconfig.CHANNEL
pl = vars.list_players()
avail = len(pl) - len(vars.WOUNDED)
votesneeded = avail // 2 + 1
for votee, voters in iter(vars.VOTES.items()):
if len(voters) >= votesneeded:
cli.msg(botconfig.CHANNEL,
random.choice(vars.LYNCH_MESSAGES).format(
votee, vars.get_role(votee)))
if del_player(cli, votee, True):
transition_night(cli)
@checks @checks
@cmd("!votes") @cmd("!votes")
def show_votes(cli, nick, chan, rest): def show_votes(cli, nick, chan, rest):
@ -198,10 +237,15 @@ def show_votes(cli, nick, chan, rest):
elif vars.PHASE != "day": elif vars.PHASE != "day":
cli.notice(nick, "Voting is only during the day.") cli.notice(nick, "Voting is only during the day.")
return return
if None in [x for voter in vars.VOTES.values() for x in voter]:
cli.msg(chan, (nick+": Tiebreaker conditions. Whoever "+
"receives the next vote will be lynched."))
return
votelist = ["{0}: {1} ({2})".format(votee, votelist = ["{0}: {1} ({2})".format(votee,
len(vars.VOTES[votee]), len(vars.VOTES[votee]),
" ".join(vars.VOTES[votee])) " ".join(vars.VOTES[votee]))
for votee in vars.VOTES.keys()] for votee in votes_copy.keys()]
cli.msg(chan, "{0}: {1}".format(nick, ", ".join(votelist))) cli.msg(chan, "{0}: {1}".format(nick, ", ".join(votelist)))
pl = vars.list_players() pl = vars.list_players()
@ -213,12 +257,15 @@ def show_votes(cli, nick, chan, rest):
def del_player(cli, nick, died_in_game = True): def del_player(cli, nick, forced_death):
cli.mode(botconfig.CHANNEL, "-v", "{0} {0}!*@*".format(nick)) cli.mode(botconfig.CHANNEL, "-v", "{0} {0}!*@*".format(nick))
if vars.PHASE != "join" and died_in_game: if vars.PHASE != "join":
cli.mode(botconfig.CHANNEL, "+q", "{0} {0}!*@*".format(nick)) cli.mode(botconfig.CHANNEL, "+q", "{0} {0}!*@*".format(nick))
vars.DEAD.append(nick) vars.DEAD.append(nick)
vars.del_player(nick) vars.del_player(nick)
if vars.PHASE == "day" and not forced_death: # didn't die from lynching
chk_decision(cli)
return True
@ -226,11 +273,9 @@ def leave(cli, what, nick):
if nick not in vars.list_players(): # not playing if nick not in vars.list_players(): # not playing
return return
msg = "" msg = ""
died_in_game = False
if what in ("!quit", "!leave"): if what in ("!quit", "!leave"):
msg = ("\u0002{0}\u0002 died of an unknown disease. "+ msg = ("\u0002{0}\u0002 died of an unknown disease. "+
"S/He was a \u0002{1}\u0002.") "S/He was a \u0002{1}\u0002.")
died_in_game = True
elif what == "part": elif what == "part":
msg = ("\u0002{0}\u0002 died due to eating poisonous berries. "+ msg = ("\u0002{0}\u0002 died due to eating poisonous berries. "+
"Appears (s)he was a \u0002{1}\u0002.") "Appears (s)he was a \u0002{1}\u0002.")
@ -242,7 +287,7 @@ def leave(cli, what, nick):
"Appears (s)he was a \u0002{1}\u0002.") "Appears (s)he was a \u0002{1}\u0002.")
msg = msg.format(nick, vars.get_role(nick)) msg = msg.format(nick, vars.get_role(nick))
cli.msg(botconfig.CHANNEL, msg) cli.msg(botconfig.CHANNEL, msg)
del_player(cli, nick, died_in_game) del_player(cli, nick, False)
cmd("!leave")(lambda cli, nick, *rest: leave(cli, "!leave", nick)) cmd("!leave")(lambda cli, nick, *rest: leave(cli, "!leave", nick))
cmd("!quit")(lambda cli, nick, *rest: leave(cli, "!quit", nick)) cmd("!quit")(lambda cli, nick, *rest: leave(cli, "!quit", nick))
@ -279,12 +324,17 @@ def transition_day(cli):
# TODO: check if harlot also died # TODO: check if harlot also died
for deadperson in dead: for deadperson in dead:
del_player(cli, deadperson, True) if not del_player(cli, deadperson, True):
return
cli.msg(chan, ("The villagers must now vote for whom to lynch. "+ cli.msg(chan, ("The villagers must now vote for whom to lynch. "+
'Use "!lynch <nick>" to cast your vote. 3 votes '+ 'Use "!lynch <nick>" to cast your vote. 3 votes '+
'are required to lynch.')) 'are required to lynch.'))
if vars.DAY_TIME_LIMIT > 0: # Time limit enabled
t = threading.Timer(vars.DAY_TIME_LIMIT, hurry_up, [cli])
vars.TIMERS[1] = t
t.start()
def chk_nightdone(cli): def chk_nightdone(cli):
@ -310,10 +360,10 @@ def vote(cli, nick, chan, rest):
if rest in pl_l: if rest in pl_l:
voted = pl[pl_l.index(rest)] voted = pl[pl_l.index(rest)]
candidates = vars.VOTES.keys() candidates = vars.VOTES.keys()
for voters in candidates: # remove previous vote for voters in list(candidates): # remove previous vote
if nick in vars.VOTES[voters]: if nick in vars.VOTES[voters]:
vars.VOTES[voters].remove(nick) vars.VOTES[voters].remove(nick)
if not vars.VOTES[voters]: if not vars.VOTES[voters] and voters != voted:
del vars.VOTES[voters] del vars.VOTES[voters]
if voted not in vars.VOTES.keys(): if voted not in vars.VOTES.keys():
vars.VOTES[voted] = [nick] vars.VOTES[voted] = [nick]
@ -321,12 +371,14 @@ def vote(cli, nick, chan, rest):
vars.VOTES[voted].append(nick) vars.VOTES[voted].append(nick)
cli.msg(chan, ("\u0002{0}\u0002 votes for "+ cli.msg(chan, ("\u0002{0}\u0002 votes for "+
"\u0002{1}\u0002.").format(nick, rest)) "\u0002{1}\u0002.").format(nick, rest))
chk_decision(cli)
elif not rest: elif not rest:
cli.notice(nick, "Not enough parameters.") cli.notice(nick, "Not enough parameters.")
else: else:
cli.notice(nick, "\u0002{0}\u0002 is currently not playing.".format(rest)) cli.notice(nick, "\u0002{0}\u0002 is currently not playing.".format(rest))
@checks @checks
@pmcmd("!kill", "kill") @pmcmd("!kill", "kill")
def kill(cli, nick, rest): def kill(cli, nick, rest):
@ -399,6 +451,15 @@ def relay(cli, nick, rest):
def transition_night(cli): def transition_night(cli):
vars.PHASE = "night" vars.PHASE = "night"
# Reset daytime variables
vars.VOTES = {}
if vars.TIMERS[1]: # cancel daytime-limit timer
vars.TIMERS[1].cancel()
vars.TIMERS[1] = None
vars.WOUNDED = ""
# Reset nighttime variables
vars.VICTIM = "" # nickname of cursed villager vars.VICTIM = "" # nickname of cursed villager
vars.SEEN = [] # list of seers that have had visions vars.SEEN = [] # list of seers that have had visions
vars.NIGHT_START_TIME = datetime.now() vars.NIGHT_START_TIME = datetime.now()
@ -409,9 +470,10 @@ def transition_night(cli):
"If you did not receive one, simply sit back, "+ "If you did not receive one, simply sit back, "+
"relax, and wait patiently for morning.")) "relax, and wait patiently for morning."))
t = threading.Timer(vars.NIGHT_TIME_LIMIT, transition_day, [cli]) if vars.NIGHT_TIME_LIMIT > 0:
vars.TIMERS[0] = t t = threading.Timer(vars.NIGHT_TIME_LIMIT, transition_day, [cli])
t.start() vars.TIMERS[0] = t
t.start()
# send PMs # send PMs
ps = vars.list_players() ps = vars.list_players()

Loading…
Cancel
Save