Convert harlot

This commit is contained in:
Vgr E. Barry 2017-10-27 17:05:22 -04:00
parent 1408ab9c4a
commit bfc5e6a9dd
4 changed files with 68 additions and 78 deletions

View File

@ -238,9 +238,10 @@ class VillagergameMode(GameMode):
if len(var.ROLES["harlot"]) == 1:
hlt = list(var.ROLES["harlot"])[0]
from src.roles import harlot
hvst = harlot.VISITED.get(hlt)
if hvst:
hvst = harlot.VISITED.get(users._get(hlt)) # FIXME
if hvst is not None:
pl.remove(hlt)
hvst = hvst.nick # FIXME
if len(var.ROLES["shaman"]) == 1:
shmn = list(var.ROLES["shaman"])[0]
if random.random() < 0.3:

View File

@ -8,69 +8,70 @@ import botconfig
import src.settings as var
from src.utilities import *
from src import channels, users, debuglog, errlog, plog
from src.functions import get_players, get_all_players, get_main_role
from src.functions import get_players, get_all_players, get_main_role, get_target
from src.decorators import cmd, event_listener
from src.messages import messages
from src.events import Event
VISITED = {}
PASSED = set()
@cmd("visit", chan=False, pm=True, playing=True, silenced=True, phases=("night",), roles=("harlot",))
def hvisit(cli, nick, chan, rest):
@command("visit", chan=False, pm=True, playing=True, silenced=True, phases=("night",), roles=("harlot",))
def hvisit(var, wrapper, message):
"""Visit a player. You will die if you visit a wolf or a target of the wolves."""
if VISITED.get(nick):
pm(cli, nick, messages["harlot_already_visited"].format(VISITED[nick]))
if VISITED.get(wrapper.source):
wrapper.pm(messages["harlot_already_visited"].format(VISITED[wrapper.source]))
return
victim = get_victim(cli, nick, re.split(" +",rest)[0], False, True)
if not victim:
target = get_target(var, wrapper, re.split(" +", message)[0], allow_bot=True)
if not target:
return
if nick == victim:
pm(cli, nick, messages["harlot_not_self"])
if target is wrapper.source:
wrapper.pm(messages["harlot_not_self"])
return
evt = Event("targeted_command", {"target": victim, "misdirection": True, "exchange": True})
evt.dispatch(cli, var, "visit", nick, victim, frozenset({"immediate"}))
evt = Event("targeted_command", {"target": target.nick, "misdirection": True, "exchange": True})
evt.dispatch(wrapper.client, var, "visit", wrapper.source.nick, target.nick, frozenset({"immediate"}))
if evt.prevent_default:
return
victim = evt.data["target"]
vrole = get_role(victim)
target = users._get(evt.data["target"]) # FIXME
vrole = get_main_role(target)
VISITED[nick] = victim
pm(cli, nick, messages["harlot_success"].format(victim))
if nick != victim:
pm(cli, victim, messages["harlot_success"].format(nick))
VISITED[wrapper.source] = target
PASSED.discard(wrapper.source)
wrapper.pm(messages["harlot_success"].format(target))
if target is not wrapper.source:
wrapper.pm(messages["harlot_success"].format(wrapper.source))
revt = Event("harlot_visit", {})
revt.dispatch(cli, var, nick, victim)
revt.dispatch(var, wrapper.source, target)
debuglog("{0} ({1}) VISIT: {2} ({3})".format(nick, get_role(nick), victim, vrole))
chk_nightdone(cli)
debuglog("{0} (harlot) VISIT: {1} ({2})".format(wrapper.source, target, vrole))
chk_nightdone(wrapper.client)
@cmd("pass", chan=False, pm=True, playing=True, silenced=True, phases=("night",), roles=("harlot",))
def pass_cmd(cli, nick, chan, rest):
@command("pass", chan=False, pm=True, playing=True, silenced=True, phases=("night",), roles=("harlot",))
def pass_cmd(var, wrapper, message):
"""Do not visit someone tonight."""
if VISITED.get(nick):
pm(cli, nick, messages["harlot_already_visited"].format(VISITED[nick]))
if VISITED.get(wrapper.source):
wrapper.pm(messages["harlot_already_visited"].format(VISITED[wrapper.source]))
return
VISITED[nick] = None
pm(cli, nick, messages["no_visit"])
debuglog("{0} ({1}) PASS".format(nick, get_role(nick)))
chk_nightdone(cli)
PASSED.add(wrapper.source)
wrapper.pm(messages["no_visit"])
debuglog("{0} (harlot) PASS".format(wrapper.source))
chk_nightdone(wrapper.client)
@event_listener("bite")
def on_bite(evt, var, alpha, target):
if target.nick not in var.ROLES["harlot"] or target.nick not in VISITED:
if target.nick not in var.ROLES["harlot"] or target not in VISITED:
return
hvisit = VISITED[target.nick]
if hvisit is not None:
visited = users._get(hvisit) # FIXME
if get_main_role(visited) not in var.WOLFCHAT_ROLES and (visited not in evt.params.bywolves or visited in evt.params.protected):
evt.data["can_bite"] = False
hvisit = VISITED[target]
if get_main_role(hvisit) not in var.WOLFCHAT_ROLES and (hvisit not in evt.params.bywolves or hvisit in evt.params.protected):
evt.data["can_bite"] = False
@event_listener("transition_day_resolve", priority=1)
def on_transition_day_resolve(evt, var, victim):
if victim.nick in var.ROLES["harlot"] and VISITED.get(victim.nick) and victim not in evt.data["dead"] and victim in evt.data["onlybywolves"]:
if victim.nick in var.ROLES["harlot"] and VISITED.get(victim) and victim not in evt.data["dead"] and victim in evt.data["onlybywolves"]:
if victim not in evt.data["bitten"]:
evt.data["message"].append(messages["target_not_home"])
evt.data["novictmsg"] = False
@ -80,22 +81,21 @@ def on_transition_day_resolve(evt, var, victim):
@event_listener("transition_day_resolve_end", priority=1)
def on_transition_day_resolve_end(evt, var, victims):
for victim in victims + evt.data["bitten"]:
if victim in evt.data["dead"] and victim.nick in VISITED.values() and (victim in evt.data["bywolves"] or victim in evt.data["bitten"]):
if victim in evt.data["dead"] and victim in VISITED.values() and (victim in evt.data["bywolves"] or victim in evt.data["bitten"]):
for hlt in VISITED:
user = users._get(hlt) # FIXME
if VISITED[hlt] == victim.nick and user not in evt.data["bitten"] and user not in evt.data["dead"]:
if VISITED[hlt] is victim and hlt not in evt.data["bitten"] and hlt not in evt.data["dead"]:
if var.ROLE_REVEAL in ("on", "team"):
evt.data["message"].append(messages["visited_victim"].format(hlt, get_reveal_role(hlt)))
evt.data["message"].append(messages["visited_victim"].format(hlt, get_reveal_role(hlt.nick)))
else:
evt.data["message"].append(messages["visited_victim_noreveal"].format(hlt))
evt.data["bywolves"].add(user)
evt.data["onlybywolves"].add(user)
evt.data["dead"].append(user)
evt.data["bywolves"].add(hlt)
evt.data["onlybywolves"].add(hlt)
evt.data["dead"].append(hlt)
@event_listener("transition_day_resolve_end", priority=3)
def on_transition_day_resolve_end3(evt, var, victims):
for harlot in get_all_players(("harlot",)):
if VISITED.get(harlot.nick) in list_players(var.WOLF_ROLES) and harlot not in evt.data["dead"] and harlot not in evt.data["bitten"]:
if VISITED.get(harlot) in get_players(var.WOLF_ROLES) and harlot not in evt.data["dead"] and harlot not in evt.data["bitten"]:
evt.data["message"].append(messages["harlot_visited_wolf"].format(harlot))
evt.data["bywolves"].add(harlot)
evt.data["onlybywolves"].add(harlot)
@ -103,28 +103,26 @@ def on_transition_day_resolve_end3(evt, var, victims):
@event_listener("night_acted")
def on_night_acted(evt, var, user, actor):
if VISITED.get(user.nick):
if VISITED.get(user):
evt.data["acted"] = True
@event_listener("chk_nightdone")
def on_chk_nightdone(evt, var):
evt.data["actedcount"] += len(VISITED)
evt.data["actedcount"] += len(VISITED) + len(PASSED)
evt.data["nightroles"].extend(get_all_players(("harlot",)))
@event_listener("exchange_roles")
def on_exchange_roles(evt, var, actor, target, actor_role, target_role):
if actor_role == "harlot":
if actor.nick in VISITED:
if VISITED[actor.nick] is not None:
visited = users._get(VISITED[actor.nick]) # FIXME
visited.send(messages["harlot_disappeared"].format(actor))
del VISITED[actor.nick]
if actor in VISITED:
VISITED[actor].send(messages["harlot_disappeared"].format(actor))
del VISITED[actor]
PASSED.discard(actor)
if target_role == "harlot":
if target.nick in VISITED:
if VISITED[target.nick] is not None:
visited = users._get(VISITED[target.nick]) # FIXME
visited.send(messages["harlot_disappeared"].format(target))
del VISITED[target.nick]
if target in VISITED:
VISITED[target].send(messages["harlot_disappeared"].format(target))
del VISITED[target]
PASSED.discard(target)
@event_listener("transition_night_end", priority=2)
def on_transition_night_end(evt, var):
@ -140,6 +138,7 @@ def on_transition_night_end(evt, var):
@event_listener("begin_day")
def on_begin_day(evt, var):
VISITED.clear()
PASSED.clear()
@event_listener("get_special")
def on_get_special(evt, var):
@ -149,21 +148,12 @@ def on_get_special(evt, var):
def on_del_player(evt, var, user, mainrole, allroles, death_triggers):
if "harlot" not in allroles:
return
VISITED.pop(user.nick, None)
@event_listener("rename_player")
def on_rename(evt, cli, var, prefix, nick):
kvp = {}
for a,b in VISITED.items():
s = nick if a == prefix else a
t = nick if b == prefix else b
kvp[s] = t
VISITED.update(kvp)
if prefix in VISITED:
del VISITED[prefix]
VISITED.pop(user, None)
PASSED.discard(user)
@event_listener("reset")
def on_reset(evt, var):
VISITED.clear()
PASSED.clear()
# vim: set sw=4 expandtab:

View File

@ -83,11 +83,11 @@ def pass_cmd(cli, nick, chan, rest):
chk_nightdone(cli)
@event_listener("harlot_visit")
def on_harlot_visit(evt, cli, var, nick, victim):
if victim in var.ROLES["succubus"]:
pm(cli, nick, messages["notify_succubus_target"].format(victim))
pm(cli, victim, messages["succubus_harlot_success"].format(nick))
ENTRANCED.add(nick)
def on_harlot_visit(evt, var, actor, victim):
if victim.nick in var.ROLES["succubus"]:
actor.send(messages["notify_succubus_target"].format(victim))
victim.send(messages["succubus_harlot_success"].format(actor))
ENTRANCED.add(actor.nick)
@event_listener("get_random_totem_targets")
def on_get_random_totem_targets(evt, var, shaman):

View File

@ -963,9 +963,8 @@ def join_player(var, wrapper, who=None, forced=False, *, sanity=True):
@handle_error
def kill_join(var, wrapper):
pl = list_players()
pl = [x.nick for x in get_players()]
pl.sort(key=lambda x: x.lower())
msg = "PING! " + break_long_message(pl).replace("\n", "\nPING! ")
reset_modes_timers(var)
reset()
wrapper.send(*pl, first="PING! ")
@ -3517,7 +3516,7 @@ def transition_day(cli, gameid=0):
victims.append(v)
elif v.nick in var.ROLES["bodyguard"] and v.nick in angel.GUARDED and users._get(angel.GUARDED[v.nick]) in victims_set: # FIXME
vappend.append(v)
elif v.nick in var.ROLES["harlot"] and harlot.VISITED.get(v.nick) is not None and users._get(harlot.VISITED[v.nick]) in victims_set: # FIXME
elif v.nick in var.ROLES["harlot"] and harlot.VISITED[v] in victims_set:
vappend.append(v)
else:
victims.append(v)
@ -3535,7 +3534,7 @@ def transition_day(cli, gameid=0):
if v.nick in var.ROLES["bodyguard"] and users._get(angel.GUARDED.get(v.nick)) not in vappend: # FIXME
vappend.remove(v)
victims.append(v)
elif v.nick in var.ROLES["harlot"] and users._get(harlot.VISITED.get(v.nick)) not in vappend: # FIXME
elif v.nick in var.ROLES["harlot"] and harlot.VISITED.get(v) not in vappend:
vappend.remove(v)
victims.append(v)