From 87277b3a0d8a27ba71417581324f912e243ecbc1 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Mon, 28 Jul 2025 22:07:11 -0700 Subject: [PATCH] Phase one of a hint system --- commands/default_cmdsets.py | 4 +- commands/hint.py | 81 +++++++++++++++++++++++++++++++++++++ typeclasses/tutorial.py | 6 ++- utils/word_list.py | 3 +- world/hints.yaml | 1 + 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100755 commands/hint.py create mode 120000 world/hints.yaml diff --git a/commands/default_cmdsets.py b/commands/default_cmdsets.py index d92a8e5..7ddcb4b 100644 --- a/commands/default_cmdsets.py +++ b/commands/default_cmdsets.py @@ -24,10 +24,11 @@ from commands.everyone import (CmdTake, CmdThink, CmdSay, CmdWhisper, CmdRead, CmdEat, CmdDrink, CmdUse, CmdPush, CmdPull, CmdOpen, CmdClose) +from commands.hint import CmdHint from commands.misc import CmdLight -from typeclasses.tutorial import CmdTutorial from commands.wizards import (CmdGM, CmdSpell, CmdGMTrigger, CmdMakeCocktail, CmdGift) +from typeclasses.tutorial import CmdTutorial class CharacterCmdSet(default_cmds.CharacterCmdSet): @@ -45,6 +46,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): """ super().at_cmdset_creation() self.add(CmdTutorial) + self.add(CmdHint) self.add(CmdNoSitStand) self.add(CmdEat) self.add(CmdDrink) diff --git a/commands/hint.py b/commands/hint.py new file mode 100755 index 0000000..c879e81 --- /dev/null +++ b/commands/hint.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import yaml + +from re import sub + +from evennia.commands.default.muxcommand import MuxCommand +from evennia import CmdSet +from evennia.utils import logger + +from utils.word_list import choices, routput + + +class CmdHint(MuxCommand): + """ + Get a hint about an area or thing. + + Usage: + + |ghint [ thing or key ]|n + + To make this system more helpful, each message contains colored + text, like |Ythis|n. Call |ghint|n again, but with the |wkey|n as + a parameter, and you can get more direct hints. + + Keep in mind the hint tree is |warea specific|n, so getting a hint + with a key of |gjump|n will be different if you are in the Grove + or in the Marsh. + + This system tries to wrap the hint in the fiction. If that doesn't + work for you, use |ghint/x|n instead. + """ + key = "hint" + hints = None + + def hint_data(self): + if not self.hints: + with open("world/hints.yaml", "r") as yamlfile: + try: + self.hints = yaml.safe_load(yamlfile) + except yaml.YAMLError as e: + logger.info(f"Error parsing hints file: {e}") + return None + + return self.hints + + def get_hint(self, room, cleaned=False, search_string=None): + room_key = sub(r" ", "_", room.name).lower() + logger.info(f"Character: {self.caller.key} " + f"Room: {room_key} " + f"Hint: '{search_string}'") + + data = self.hint_data() + if data: + room_hints = data[room_key] + narrative = room_hints['narrative'] + hints = room_hints['hints'] + + if not search_string or search_string == "": + hint = hints['default'] + else: + hint = hints[search_string] + return self.display_hint(narrative, hint, cleaned) + + def display_hint(self, narrative, phrase, cleaned): + if phrase: + if cleaned: + self.caller.msg(routput(phrase)) + else: + self.caller.msg(choices(narrative, routput(phrase))) + else: + self.caller.msg("[This is a new system, and the hint system has nothing to offer here.]") + + def func(self): + cleaner = True if "x" in self.switches else False + self.get_hint(self.caller.location, cleaner, self.lhs) + + +class CmdSetHint(CmdSet): + def at_cmdset_creation(self): + self.add(CmdHint) diff --git a/typeclasses/tutorial.py b/typeclasses/tutorial.py index c537c4a..f39254f 100755 --- a/typeclasses/tutorial.py +++ b/typeclasses/tutorial.py @@ -48,15 +48,17 @@ MSGS = { "\"A shortcut to |gsay|n is to type either a double or single quote, and then your message.\"", "\"You can also use |gemote|n to state something about yourself, \" it says. \" For instance, type |gemote smiles.|n\"", "The bird stands on one leg.", - "Another useful command is |gpub|n which is a shortcut to sending messages to a public channel that everyone in the game receives |wout of character|n. That is, the message comes from your login account, not your character. The dad jokes go there without interrupting the role playing." + "Another useful command is |gpub|n which is a shortcut to sending messages to a public channel that everyone in the game receives |wout of character|n. That is, the message comes from your login account, not your character. The dad jokes go there without interrupting the role playing.", "The bird says, \"Typing |ghelp|n gives you a list of commands. That list changes depending on where you are and what you are carrying. For instance, you could type |gshoo|n for me to fly away, and then that command wouldn't be available again.\"", "The bird chirps, \"You can learn more about the individual commands. For instance, type |ghelp emote|n and you can see more options to that command. You can also see new commands, like |ghelp get|n.\"", + "\"If you get stuck solving a puzzle,\" it says, \"Check out |ghint|n, but type |ghelp hint|n first.\"" "\"Type |ghelp start|n for a repeat of much of what we've talked about,\" says the bird.", - "The bird says, \"The |ginv|n shows you what you are carrying. I see you picked up a letter. You can also type |gread letter|n.\"", + "The bird says, \"Hrm. What else? The |ginv|n shows you what you are carrying. I see you picked up a letter. You can also type |gread letter|n.\"", "\"Since this game hosts many users,\" says the bird, \"you can show them what they see when they look at you, using the |gsetdesc|n command. Check out the help on it as well as |gsdesc|n and |gpose|n.", "\"I'm guessing your last question,\" chirps the little bird on your shoulder, \"is the goal of this game.\"", "\"That is a good question,\" quips the bird, \"and I'm not sure what to say. You could look at this as a philosophical antidote for our existential apprehension of a post-modern world in the death throes of capitalism, but…\"", "The bird says, \"This is a cozy little game about role playing a storybook character in an alternate plane populated by the Faerie, so wander and look around. Find a cozy place to role play with others,\" says the bird.", + "\"If you can find the secret alchemy lab,\" it says, \"you can craft potions, and if you find the |wmist horn|n, you can cross the sea solving adventures.\"" "\"What do you say?\" says the bird. \"Think you got the hang of playing this?\"", ] } diff --git a/utils/word_list.py b/utils/word_list.py index a567244..ab688b3 100755 --- a/utils/word_list.py +++ b/utils/word_list.py @@ -44,7 +44,8 @@ def squish(text): "Remove series of spaces from the text." no_start = sub(r"\( +", "(", text) no_after = sub(r" +\)", ")", no_start) - return sub('[ \t]+', ' ', no_after).strip() + no_inside = sub(r"\" *(.*?) *\"", "\"\\1\"", no_after) + return sub('[ \t]+', ' ', no_inside).strip() def _routput_choose(text): """ diff --git a/world/hints.yaml b/world/hints.yaml new file mode 120000 index 0000000..e4c875a --- /dev/null +++ b/world/hints.yaml @@ -0,0 +1 @@ +/Users/howard/projects/mud-hints.yaml \ No newline at end of file