From 95efce558714bc487c485930bd144e13d1da16e4 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Thu, 26 Apr 2018 16:08:07 -0400 Subject: [PATCH] Mystic tweaks --- messages/en.json | 21 ++++++++---------- src/roles/_mystic_helper.py | 43 ++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/messages/en.json b/messages/en.json index bd53edb..550b8fb 100644 --- a/messages/en.json +++ b/messages/en.json @@ -310,18 +310,15 @@ "clone_target": "You are cloning \u0002{0}\u0002.", "shaman_totem": "You have a \u0002{0}\u0002 totem.", "players_exchanged_roles": "\u0002{0}\u0002 and \u0002{1}\u0002 have exchanged roles!", - "mystic_info_singular": "There is \u00021\u0002 evil villager still alive.", - "mystic_info_plural": "There are \u0002{0}\u0002 evil villagers still alive.", - "mystic_info_night_singular": "There was \u00021\u0002 evil villager alive at the beginning of the night.", - "mystic_info_night_plural": "There were \u0002{0}\u0002 evil villagers alive at the beginning of the night.", - "mystic_info_day_singular": "There was \u00021\u0002 evil villager alive at the beginning of last night.", - "mystic_info_day_plural": "There were \u0002{0}\u0002 evil villagers alive at the beginning of last night.", - "wolf_mystic_info_singular": "There is \u00021\u0002 special villager still alive.", - "wolf_mystic_info_plural": "There are \u0002{0}\u0002 special villagers still alive.", - "wolf_mystic_info_night_singular": "There was \u00021\u0002 special villager alive at the beginning of the night.", - "wolf_mystic_info_night_plural": "There were \u0002{0}\u0002 special villagers alive at the beginning of the night.", - "wolf_mystic_info_day_singular": "There was \u00021\u0002 special villager alive at the beginning of last night.", - "wolf_mystic_info_day_plural": "There were \u0002{0}\u0002 special villagers alive at the beginning of last night.", + + "mystic_villagers": "special villager", + "mystic_wolves": "evil villager", + "mystic_neutrals": "neutral player", + "mystic_win_stealers": "win stealer", + "mystic_night_num": " at the beginning of the night", + "mystic_day_num": " at the beginning of last night", + "mystic_info" : "There {0} {1}{2} alive{3}.", + "ill_wolves": "You are feeling ill tonight, and are unable to kill anyone.", "angry_wolves": "You are \u0002angry\u0002 tonight, and may kill two targets by using \"kill and \".", "wolf_bite": "You may use \"bite \" tonight in order to turn that person into a wolf.", diff --git a/src/roles/_mystic_helper.py b/src/roles/_mystic_helper.py index 005659b..74728a5 100644 --- a/src/roles/_mystic_helper.py +++ b/src/roles/_mystic_helper.py @@ -10,7 +10,7 @@ from src.messages import messages from src.events import Event def setup_variables(rolename, *, send_role, types): - LAST_COUNT = UserDict() # type: Dict[users.User, int] + LAST_COUNT = UserDict() # type: Dict[users.User, Tuple[str, bool]] role = rolename.replace(" ", "_") @@ -23,33 +23,44 @@ def setup_variables(rolename, *, send_role, types): special_evt = Event("get_special", {"villagers": villagers, "wolves": set(), "win_stealers": win_stealers, "neutrals": neutrals}) special_evt.dispatch(var) + bold = "\u0002{0}\u0002".format + targets = set() + values = [] + plural = True for name in types: targets.update(special_evt.data[name]) + l = len(special_evt.data[name]) + if l: + if not values and l == 1: + plural = False + values.append("{0} {1}{2}".format(bold(l), messages["mystic_{0}".format(name)], "" if l == 1 else "s")) - count = len(targets) - key = "{0}_info_{1}".format(role, ("singular" if count == 1 else "plural")) + value = " and ".join(", ".join(*values[:-1]), values[-1]) + msg = messages["mystic_info"].format("are" if plural else "is", value, " still", "") for mystic in get_all_players((rolename,)): - LAST_COUNT[mystic] = count + LAST_COUNT[mystic] = (value, plural) if send_role: to_send = "{0}_{1}".format(role, ("simple" if mystic.prefers_simple() else "notify")) mystic.send(messages[to_send]) - mystic.send(messages[key].format(count)) + mystic.send(msg) @event_listener("exchange_roles") def on_exchange_roles(evt, var, actor, target, actor_role, target_role): if actor_role == rolename and target_role != rolename: - count = LAST_COUNT.pop(actor) - LAST_COUNT[target] = count - key = "{0}_info_{1}_{2}".format(role, var.PHASE, ("singular" if count == 1 else "plural")) - evt.data["target_messages"].append(messages[key].format(count)) + value, plural = LAST_COUNT.pop(actor) + LAST_COUNT[target] = (value, plural) + key = "were" if plural else "was" + msg = messages["mystic_info"].format(key, value, "", messages["mystic_{0}_num".format(var.PHASE)]) + evt.data["target_messages"].append(msg) if target_role == rolename and actor_role != rolename: - count = LAST_COUNT.pop(target) - LAST_COUNT[actor] = count - key = "{0}_info_{1}_{2}".format(role, var.PHASE, ("singular" if count == 1 else "plural")) - evt.data["actor_messages"].append(messages[key].format(count)) + value, plural = LAST_COUNT.pop(target) + LAST_COUNT[actor] = (value, plural) + key = "were" if plural else "was" + msg = messages["mystic_info"].format(key, value, "", messages["mystic_{0}_num".format(var.PHASE)]) + evt.data["actor_messages"].append(msg) @event_listener("reset") def on_reset(evt, var): @@ -58,8 +69,10 @@ def setup_variables(rolename, *, send_role, types): @event_listener("myrole") def on_myrole(evt, var, user): if user in get_all_players((rolename,)): - key = "{0}_info_{1}_{2}".format(role, var.PHASE, ("singular" if LAST_COUNT[user] == 1 else "plural")) - evt.data["messages"].append(messages[key].format(LAST_COUNT[user])) + value, plural = LAST_COUNT[user] + key = "were" if plural else "was" + msg = messages["mystic_info"].format(key, value, "", messages["mystic_{0}_num".format(var.PHASE)]) + evt.data["messages"].append(mag) return LAST_COUNT