Phase one of a hint system
This commit is contained in:
parent
61bec79397
commit
87277b3a0d
5 changed files with 91 additions and 4 deletions
|
|
@ -24,10 +24,11 @@ from commands.everyone import (CmdTake, CmdThink, CmdSay,
|
||||||
CmdWhisper, CmdRead, CmdEat, CmdDrink,
|
CmdWhisper, CmdRead, CmdEat, CmdDrink,
|
||||||
CmdUse, CmdPush, CmdPull,
|
CmdUse, CmdPush, CmdPull,
|
||||||
CmdOpen, CmdClose)
|
CmdOpen, CmdClose)
|
||||||
|
from commands.hint import CmdHint
|
||||||
from commands.misc import CmdLight
|
from commands.misc import CmdLight
|
||||||
from typeclasses.tutorial import CmdTutorial
|
|
||||||
from commands.wizards import (CmdGM, CmdSpell, CmdGMTrigger,
|
from commands.wizards import (CmdGM, CmdSpell, CmdGMTrigger,
|
||||||
CmdMakeCocktail, CmdGift)
|
CmdMakeCocktail, CmdGift)
|
||||||
|
from typeclasses.tutorial import CmdTutorial
|
||||||
|
|
||||||
|
|
||||||
class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||||
|
|
@ -45,6 +46,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||||
"""
|
"""
|
||||||
super().at_cmdset_creation()
|
super().at_cmdset_creation()
|
||||||
self.add(CmdTutorial)
|
self.add(CmdTutorial)
|
||||||
|
self.add(CmdHint)
|
||||||
self.add(CmdNoSitStand)
|
self.add(CmdNoSitStand)
|
||||||
self.add(CmdEat)
|
self.add(CmdEat)
|
||||||
self.add(CmdDrink)
|
self.add(CmdDrink)
|
||||||
|
|
|
||||||
81
commands/hint.py
Executable file
81
commands/hint.py
Executable file
|
|
@ -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)
|
||||||
|
|
@ -48,15 +48,17 @@ MSGS = {
|
||||||
"\"A shortcut to |gsay|n is to type either a double or single quote, and then your message.\"",
|
"\"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\"",
|
"\"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.",
|
"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 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.\"",
|
"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.",
|
"\"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.",
|
"\"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.\"",
|
"\"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…\"",
|
"\"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.",
|
"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?\"",
|
"\"What do you say?\" says the bird. \"Think you got the hang of playing this?\"",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ def squish(text):
|
||||||
"Remove series of spaces from the text."
|
"Remove series of spaces from the text."
|
||||||
no_start = sub(r"\( +", "(", text)
|
no_start = sub(r"\( +", "(", text)
|
||||||
no_after = sub(r" +\)", ")", no_start)
|
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):
|
def _routput_choose(text):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
1
world/hints.yaml
Symbolic link
1
world/hints.yaml
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
/Users/howard/projects/mud-hints.yaml
|
||||||
Loading…
Reference in a new issue