def on_transition_day_begin(evt, var): # Select random totem recipients if shamans didn't act pl = get_players() for shaman in get_all_players(("wolf shaman",)): if is_silent(var, shaman): continue ps = pl[:] for given in itertools.chain.from_iterable(LASTGIVEN[shaman].values()): if given in ps: ps.remove(given) for given in itertools.chain.from_iterable(SHAMANS[shaman].values()): if given in ps: ps.remove(given) for totem, count in TOTEMS[shaman].items(): mustgive = count - len(SHAMANS[shaman][totem]) for i in range(mustgive): if ps: target = random.choice(ps) ps.remove(target) dispatcher = MessageDispatcher(shaman, shaman) given = give_totem(var, dispatcher, target, totem, key="shaman_success_random_known", role="wolf shaman") if given: send_wolfchat_message(var, shaman, messages["shaman_wolfchat"].format(shaman, target), ("wolf shaman",), role="wolf shaman", command="totem") SHAMANS[shaman][totem].append(given[0])
def wolf_shaman_totem(var, wrapper, message): """Give a totem to a player.""" totem_types = list(TOTEMS[wrapper.source].keys()) totem, target = get_totem_target(var, wrapper, message, LASTGIVEN, totem_types) if not target: return if not totem: totem_types = list(TOTEMS[wrapper.source].keys()) if len(totem_types) == 1: totem = totem_types[0] else: wrapper.send(messages["shaman_ambiguous_give"]) return orig_target = target target = RETARGET[wrapper.source].get(target, target) if target in itertools.chain.from_iterable(SHAMANS[wrapper.source].values()): wrapper.send(messages["shaman_no_stacking"].format(orig_target)) return given = give_totem(var, wrapper, target, totem, key="shaman_success_night_known", role="wolf shaman") if given: victim, target = given if victim is not target: RETARGET[wrapper.source][target] = victim SHAMANS[wrapper.source][totem].append(victim) if len(SHAMANS[wrapper.source][totem]) > TOTEMS[wrapper.source][totem]: SHAMANS[wrapper.source][totem].pop(0) send_wolfchat_message(var, wrapper.source, messages["shaman_wolfchat"].format(wrapper.source, target), ("wolf shaman",), role="wolf shaman", command="totem")
def curse(var, wrapper, message): target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if target in get_all_players(("cursed villager",)): wrapper.pm(messages["target_already_cursed"].format(target)) return # There may actually be valid strategy in cursing other wolfteam members, # but for now it is not allowed. If someone seems suspicious and shows as # villager across multiple nights, safes can use that as a tell that the # person is likely wolf-aligned. if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_curse_wolf"]) return orig = target target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return CURSED[wrapper.source] = target PASSED.discard(wrapper.source) wrapper.pm(messages["curse_success"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["curse_success_wolfchat"].format(wrapper.source, orig), {"warlock"}, role="warlock", command="curse") debuglog("{0} (warlock) CURSE: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def retract(var, wrapper, message): """Retract your bite.""" if wrapper.source in BITTEN: del BITTEN[wrapper.source] wrapper.pm(messages["no_bite"]) send_wolfchat_message(var, wrapper.source, messages["wolfchat_no_bite"].format(wrapper.source), {"alpha wolf"}, role="alpha wolf", command="retract") debuglog("{0} (alpha wolf) RETRACT BITE".format(wrapper.source))
def hex_cmd(var, wrapper, message): """Hex someone, preventing them from acting the next day and night.""" if wrapper.source in HEXED: wrapper.pm(messages["already_hexed"]) return target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if LASTHEXED.get(wrapper.source) is target: wrapper.pm(messages["no_multiple_hex"].format(target)) return target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_hex_wolf"]) return HEXED[wrapper.source] = target wrapper.pm(messages["hex_success"].format(target)) send_wolfchat_message(var, wrapper.source, messages["hex_success_wolfchat"].format( wrapper.source, target), {"hag"}, role="hag", command="hex") debuglog("{0} (hag) HEX: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def curse(var, wrapper, message): target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if target in get_all_players(("cursed villager", )): wrapper.pm(messages["target_already_cursed"].format(target)) return # There may actually be valid strategy in cursing other wolfteam members, # but for now it is not allowed. If someone seems suspicious and shows as # villager across multiple nights, safes can use that as a tell that the # person is likely wolf-aligned. if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_curse_wolf"]) return orig = target target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return CURSED[wrapper.source] = target PASSED.discard(wrapper.source) wrapper.pm(messages["curse_success"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["curse_success_wolfchat"].format( wrapper.source, orig), {"warlock"}, role="warlock", command="curse") debuglog("{0} (warlock) CURSE: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def observe(var, wrapper, message): """Observe a player to obtain various information.""" target = get_target(var, wrapper, re.split(" +", message)[0], not_self_message="no_observe_self") if not target: return if wrapper.source in OBSERVED: wrapper.pm(messages["already_observed"]) return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_observe_wolf"]) return target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return OBSERVED.add(wrapper.source) targrole = get_main_role(target) if targrole == "amnesiac": from src.roles.amnesiac import ROLES as amn_roles targrole = amn_roles[target] key = "sorcerer_fail" if targrole in Spy: key = "sorcerer_success" wrapper.pm(messages[key].format(target, targrole)) send_wolfchat_message(var, wrapper.source, messages["sorcerer_success_wolfchat"].format(wrapper.source, target), {"sorcerer"}, role="sorcerer", command="observe") debuglog("{0} (sorcerer) OBSERVE: {1} ({2})".format(wrapper.source, target, targrole))
def observe(var, wrapper, message): """Observe a player to obtain various information.""" target = get_target(var, wrapper, re.split(" +", message)[0], not_self_message="no_observe_self") if not target: return if wrapper.source in OBSERVED: wrapper.pm(messages["already_observed"]) return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_observe_wolf"]) return target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return OBSERVED.add(wrapper.source) targrole = get_main_role(target) if targrole == "amnesiac": from src.roles.amnesiac import ROLES as amn_roles targrole = amn_roles[target] an = "" key = "sorcerer_fail" if targrole in Spy: if targrole.startswith(("a", "e", "i", "o", "u")): an = "n" key = "sorcerer_success" wrapper.pm(messages[key].format(target, an, targrole)) send_wolfchat_message(var, wrapper.source, messages["sorcerer_success_wolfchat"].format(wrapper.source, target), {"sorcerer"}, role="sorcerer", command="observe") debuglog("{0} (sorcerer) OBSERVE: {1} ({2})".format(wrapper.source, target, targrole))
def observe(var, wrapper, message): """Observe a player to see whether they are able to act at night.""" if wrapper.source in OBSERVED: wrapper.pm(messages["werecrow_already_observing"].format( OBSERVED[wrapper.source])) return target = get_target(var, wrapper, re.split(" +", message)[0], not_self_message="werecrow_no_observe_self") if not target: return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["werecrow_no_target_wolf"]) return orig = target target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return OBSERVED[wrapper.source] = target wrapper.pm(messages["werecrow_observe_success"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["wolfchat_observe"].format( wrapper.source, target), {"werecrow"}, role="werecrow", command="observe") debuglog("{0} (werecrow) OBSERVE: {1} ({2})".format( wrapper.source, target, get_main_role(target)))
def hex_cmd(var, wrapper, message): """Hex someone, preventing them from acting the next day and night.""" if wrapper.source in HEXED: wrapper.pm(messages["already_hexed"]) return target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if LASTHEXED.get(wrapper.source) is target: wrapper.pm(messages["no_multiple_hex"].format(target)) return target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_hex_wolf"]) return HEXED[wrapper.source] = target wrapper.pm(messages["hex_success"].format(target)) send_wolfchat_message(var, wrapper.source, messages["hex_success_wolfchat"].format(wrapper.source, target), {"hag"}, role="hag", command="hex") debuglog("{0} (hag) HEX: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def observe(var, wrapper, message): """Turn a player into a wolf!""" if not ENABLED: wrapper.pm(messages["alpha_no_bite"]) return if wrapper.source in ALPHAS: wrapper.pm(messages["alpha_already_bit"]) return target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["alpha_no_bite_wolf"]) return orig = target target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return BITTEN[wrapper.source] = target wrapper.pm(messages["alpha_bite_target"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["alpha_bite_wolfchat"].format( wrapper.source, target), {"alpha wolf"}, role="alpha wolf", command="bite") debuglog("{0} (alpha wolf) BITE: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def see(var, wrapper, message): """Use your paranormal senses to determine a player's doom.""" if wrapper.source in SEEN: wrapper.send(messages["seer_fail"]) return target = get_target(var, wrapper, re.split(" +", message)[0], not_self_message="no_see_self") if not target: return if is_known_wolf_ally(var, wrapper.source, target): wrapper.send(messages["no_see_wolf"]) return target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return targrole = get_main_role(target) mode, mapping = random.choice(_mappings) wrapper.send(messages["doomsayer_{0}".format(mode)].format(target)) mapping[wrapper.source] = target debuglog("{0} (doomsayer) SEE: {1} ({2}) - {3}".format(wrapper.source, target, targrole, mode.upper())) send_wolfchat_message(var, wrapper.source, messages["doomsayer_wolfchat"].format(wrapper.source, target), ("doomsayer",), role="doomsayer", command="see") SEEN.add(wrapper.source)
def pass_cmd(var, wrapper, message): """Decline to use your special power for that night.""" del CURSED[:wrapper.source:] PASSED.add(wrapper.source) wrapper.pm(messages["warlock_pass"]) send_wolfchat_message(var, wrapper.source, messages["warlock_pass_wolfchat"].format(wrapper.source), {"warlock"}, role="warlock", command="pass") debuglog("{0} (warlock) PASS".format(wrapper.source))
def retract(var, wrapper, message): """Retract your curse or pass.""" del CURSED[:wrapper.source:] PASSED.discard(wrapper.source) wrapper.pm(messages["warlock_retract"]) send_wolfchat_message(var, wrapper.source, messages["warlock_retract_wolfchat"].format(wrapper.source), {"warlock"}, role="warlock", command="retract") debuglog("{0} (warlock) RETRACT".format(wrapper.source))
def observe(var, wrapper, message): """Observe a player to obtain various information.""" target = get_target(var, wrapper, re.split(" +", message)[0], not_self_message="no_observe_self") if not target: return if wrapper.source in OBSERVED: wrapper.pm(messages["already_observed"]) return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["no_observe_wolf"]) return evt = Event("targeted_command", { "target": target, "exchange": True, "misdirection": True }) if not evt.dispatch(var, wrapper.source, target): return target = evt.data["target"] OBSERVED.add(wrapper.source) targrole = get_main_role(target) if targrole == "amnesiac": from src.roles.amnesiac import ROLES as amn_roles targrole = amn_roles[target] an = "" key = "sorcerer_fail" if targrole in Spy: if targrole.startswith(("a", "e", "i", "o", "u")): an = "n" key = "sorcerer_success" wrapper.pm(messages[key].format(target, an, targrole)) send_wolfchat_message(var, wrapper.source, messages["sorcerer_success_wolfchat"].format( wrapper.source, target), {"sorcerer"}, role="sorcerer", command="observe") debuglog("{0} (sorcerer) OBSERVE: {1} ({2})".format( wrapper.source, target, targrole))
def feed(self, var, wrapper, message): """Give your totem to the tribe members.""" from src.roles.shaman import TOTEMS as s_totems, SHAMANS as s_shamans from src.roles.wolfshaman import TOTEMS as ws_totems, SHAMANS as ws_shamans pieces = re.split(" +", message) valid = ("sustenance", "hunger") state_vars = ((s_totems, s_shamans), (ws_totems, ws_shamans)) for TOTEMS, SHAMANS in state_vars: if wrapper.source not in TOTEMS: continue totem_types = list(TOTEMS[wrapper.source].keys()) given = complete_one_match(pieces[0], totem_types) if not given and TOTEMS[wrapper.source].get( "sustenance", 0) + TOTEMS[wrapper.source].get("hunger", 0) > 1: wrapper.send(messages["boreal_ambiguous_feed"]) return for totem in valid: if (given and totem != given) or TOTEMS[wrapper.source].get( totem, 0) == 0: continue # doesn't have a totem that can be used to feed tribe SHAMANS[wrapper.source][totem].append(users.Bot) if len(SHAMANS[wrapper.source][totem]) > TOTEMS[ wrapper.source][totem]: SHAMANS[wrapper.source][totem].pop(0) nick = wrapper.source role = get_main_role(nick) wrapper.pm(messages["boreal_feed_success"].format(totem)) if role == "wolf shaman": wolves.send_wolfchat_message( var=var, user=wrapper.source, message=messages["boreal_wolf_feed_success"].format( nick, totem), roles="wolf shaman") return
def feed(self, var, wrapper, message): """Give your totem to the tribe members.""" from src.roles.shaman import TOTEMS as s_totems, SHAMANS as s_shamans from src.roles.wolfshaman import TOTEMS as ws_totems, SHAMANS as ws_shamans pieces = re.split(" +", message) valid = ("sustenance", "hunger") state_vars = ((s_totems, s_shamans), (ws_totems, ws_shamans)) for TOTEMS, SHAMANS in state_vars: if wrapper.source not in TOTEMS: continue totem_types = list(TOTEMS[wrapper.source].keys()) given = complete_one_match(pieces[0], totem_types) if not given and TOTEMS[wrapper.source].get( "sustenance", 0) + TOTEMS[wrapper.source].get("hunger", 0) > 1: wrapper.send(messages["boreal_ambiguous_feed"]) return for totem in valid: if (given and totem != given) or TOTEMS[wrapper.source].get( totem, 0) == 0: continue # doesn't have a totem that can be used to feed tribe SHAMANS[wrapper.source][totem].append(users.Bot) if len(SHAMANS[wrapper.source][totem]) > TOTEMS[ wrapper.source][totem]: SHAMANS[wrapper.source][totem].pop(0) wrapper.pm(messages["boreal_feed_success"].format(totem)) # send_wolfchat_message already takes care of checking whether the player has access to wolfchat, so this will only be sent for wolf shamans send_wolfchat_message(var, wrapper.source, messages["boreal_wolfchat_feed"].format( wrapper.source), {"wolf shaman"}, role="wolf shaman", command="feed") return
def observe(var, wrapper, message): """Observe a player to see whether they are able to act at night.""" if wrapper.source in OBSERVED: wrapper.pm(messages["werecrow_already_observing"].format(OBSERVED[wrapper.source])) return target = get_target(var, wrapper, re.split(" +", message)[0], not_self_message="werecrow_no_observe_self") if not target: return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["werecrow_no_target_wolf"]) return orig = target evt = Event("targeted_command", {"target": target, "misdirection": True, "exchange": True}) evt.dispatch(var, wrapper.source, target) if evt.prevent_default: return target = evt.data["target"] OBSERVED[wrapper.source] = target wrapper.pm(messages["werecrow_observe_success"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["wolfchat_observe"].format(wrapper.source, target), {"werecrow"}, role="werecrow", command="observe") debuglog("{0} (werecrow) OBSERVE: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def observe(var, wrapper, message): """Turn a player into a wolf!""" if not ENABLED: wrapper.pm(messages["alpha_no_bite"]) return if wrapper.source in ALPHAS: wrapper.pm(messages["alpha_already_bit"]) return target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["alpha_no_bite_wolf"]) return orig = target target = try_misdirection(var, wrapper.source, target) if try_exchange(var, wrapper.source, target): return BITTEN[wrapper.source] = target wrapper.pm(messages["alpha_bite_target"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["alpha_bite_wolfchat"].format(wrapper.source, target), {"alpha wolf"}, role="alpha wolf", command="bite") debuglog("{0} (alpha wolf) BITE: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def observe(var, wrapper, message): """Turn a player into a wolf!""" if not ENABLED: wrapper.pm(messages["alpha_no_bite"]) return if wrapper.source in ALPHAS: wrapper.pm(messages["alpha_already_bit"]) return target = get_target(var, wrapper, re.split(" +", message)[0]) if not target: return if is_known_wolf_ally(var, wrapper.source, target): wrapper.pm(messages["alpha_no_bite_wolf"]) return orig = target evt = Event("targeted_command", { "target": target, "misdirection": True, "exchange": True }) evt.dispatch(var, wrapper.source, target) if evt.prevent_default: return target = evt.data["target"] BITTEN[wrapper.source] = target wrapper.pm(messages["alpha_bite_target"].format(orig)) send_wolfchat_message(var, wrapper.source, messages["alpha_bite_wolfchat"].format( wrapper.source, target), {"alpha wolf"}, role="alpha wolf", command="bite") debuglog("{0} (alpha wolf) BITE: {1} ({2})".format(wrapper.source, target, get_main_role(target)))
def relay_wolfchat_command(cli, nick, message, roles, is_wolf_command=False, is_kill_command=False): from src.roles.helper.wolves import send_wolfchat_message from src import users role = "wolf" if is_wolf_command else None command = "kill" if is_kill_command else None send_wolfchat_message(var, users._get(nick), message, roles, role=role, command=command)