Add event framework to allow for injecting phases

This commit is contained in:
skizzerz 2016-02-19 15:39:32 -06:00
parent f0663d7aa4
commit 6fff851350

View File

@ -2105,6 +2105,7 @@ def chk_decision(cli, force = ""):
votesneeded = avail // 2 + 1 votesneeded = avail // 2 + 1
not_lynching = list(var.NO_LYNCH) not_lynching = list(var.NO_LYNCH)
deadlist = [] deadlist = []
votelist = copy.deepcopy(var.VOTES)
for p in var.PACIFISTS: for p in var.PACIFISTS:
if p in pl and p not in (var.WOUNDED | var.ASLEEP | var.CONSECRATING | var.SICK): if p in pl and p not in (var.WOUNDED | var.ASLEEP | var.CONSECRATING | var.SICK):
not_lynching.append(p) not_lynching.append(p)
@ -2117,6 +2118,20 @@ def chk_decision(cli, force = ""):
# remove duplicates # remove duplicates
not_lynching = set(not_lynching) not_lynching = set(not_lynching)
# fire off an event (right now if people want to mess with votes, they need to reimplement all the impatience/pacifism stuff)
event = Event("chk_decision", {
"avail": avail,
"votesneeded": votesneeded,
"not_lynching": not_lynching,
"votelist": votelist,
"transition_night": transition_night
})
event.dispatch(cli, var, force)
avail = event.data["avail"]
votesneeded = event.data["votesneeded"]
not_lynching = event.data["not_lynching"]
votelist = event.data["votelist"]
# we only need 50%+ to not lynch, instead of an actual majority, because a tie would time out day anyway # we only need 50%+ to not lynch, instead of an actual majority, because a tie would time out day anyway
# don't check for ABSTAIN_ENABLED here since we may have a case where the majority of people have pacifism totems or something # don't check for ABSTAIN_ENABLED here since we may have a case where the majority of people have pacifism totems or something
if len(not_lynching) >= math.ceil(avail / 2): if len(not_lynching) >= math.ceil(avail / 2):
@ -2129,10 +2144,9 @@ def chk_decision(cli, force = ""):
else: else:
var.ENTRANCED_DYING.update(var.ENTRANCED & var.NO_LYNCH) var.ENTRANCED_DYING.update(var.ENTRANCED & var.NO_LYNCH)
var.ABSTAINED = True var.ABSTAINED = True
transition_night(cli) event.data["transition_night"](cli)
return return
aftermessage = None aftermessage = None
votelist = copy.deepcopy(var.VOTES)
for votee, voters in votelist.items(): for votee, voters in votelist.items():
if votee in var.ROLES["succubus"]: if votee in var.ROLES["succubus"]:
for vtr in var.ENTRANCED: for vtr in var.ENTRANCED:
@ -2254,7 +2268,7 @@ def chk_decision(cli, force = ""):
if aftermessage != None: if aftermessage != None:
cli.msg(botconfig.CHANNEL, aftermessage) cli.msg(botconfig.CHANNEL, aftermessage)
if del_player(cli, votee, True, killer_role="villager", deadlist=deadlist, original=votee): if del_player(cli, votee, True, killer_role="villager", deadlist=deadlist, original=votee):
transition_night(cli) event.data["transition_night"](cli)
break break
@cmd("votes", pm=True, phases=("join", "day", "night")) @cmd("votes", pm=True, phases=("join", "day", "night"))
@ -3865,7 +3879,7 @@ def night_warn(cli, gameid):
if gameid != var.NIGHT_ID: if gameid != var.NIGHT_ID:
return return
if var.PHASE == "day": if var.PHASE != "night":
return return
cli.msg(botconfig.CHANNEL, (messages["twilight_warning"])) cli.msg(botconfig.CHANNEL, (messages["twilight_warning"]))
@ -4641,13 +4655,13 @@ def transition_day(cli, gameid=0):
message.append(messages["totem_broken"].format(brokentotem)) message.append(messages["totem_broken"].format(brokentotem))
cli.msg(chan, "\n".join(message)) cli.msg(chan, "\n".join(message))
event_end = Event("transition_day_end", {}) event_end = Event("transition_day_end", {"begin_day": begin_day})
event_end.dispatch(cli, var) event_end.dispatch(cli, var)
if chk_win(cli): # if after the last person is killed, one side wins, then actually end the game here if chk_win(cli): # if after the last person is killed, one side wins, then actually end the game here
return return
begin_day(cli) event_end.data["begin_day"](cli)
@proxy.impl @proxy.impl
def chk_nightdone(cli): def chk_nightdone(cli):
@ -4720,7 +4734,7 @@ def chk_nightdone(cli):
elif tu[1] < var.NIGHT_COUNT - 1: elif tu[1] < var.NIGHT_COUNT - 1:
nightroles.append(tc) nightroles.append(tc)
event = Event("chk_nightdone", {"actedcount": actedcount, "nightroles": nightroles}) event = Event("chk_nightdone", {"actedcount": actedcount, "nightroles": nightroles, "transition_day": transition_day})
event.dispatch(cli, var) event.dispatch(cli, var)
actedcount = event.data["actedcount"] actedcount = event.data["actedcount"]
@ -4753,7 +4767,7 @@ def chk_nightdone(cli):
var.TIMERS = {} var.TIMERS = {}
if var.PHASE == "night": # Double check if var.PHASE == "night": # Double check
transition_day(cli) event.data["transition_day"](cli)
@cmd("nolynch", "nl", "novote", "nv", "abstain", "abs", playing=True, phases=("day",)) @cmd("nolynch", "nl", "novote", "nv", "abstain", "abs", playing=True, phases=("day",))
def no_lynch(cli, nick, chan, rest): def no_lynch(cli, nick, chan, rest):