Extract the shrub's chalkboard writing

This should allow any GM-puppeted account to control the shrub without
puppeting it.
This commit is contained in:
Howard Abrams 2025-06-05 22:01:01 -07:00
parent 45d591403c
commit fb45aa44a3
2 changed files with 41 additions and 33 deletions

View file

@ -558,14 +558,14 @@ class BHB(Friendly):
""" """
match self.friendly_reaction(thrower): match self.friendly_reaction(thrower):
case Reaction.SCARED: case Reaction.SCARED:
msg = "The beast runs away when you throw the stick." msg = "The beast runs away when $you() throw the stick."
case Reaction.CONCERNED: case Reaction.CONCERNED:
msg = "The beast walks over to the stick, sniffs it, and backs away." msg = "The beast walks over to the stick, sniffs it, and backs away."
self.adjust_character(thrower, 5) self.adjust_character(thrower, 5)
case Reaction.INTERESTED: case Reaction.INTERESTED:
msg = choices(""" msg = choices("""
The beast <<runs ^ hurries>> at the stick, then looks at $you(), <<wondering ^ curious as to ^ pondering>> what to do with a stick the flies back to its owner. ;; The beast <<runs ^ hurries>> at the stick, then looks at $you(), <<wondering ^ curious as to ^ pondering>> what to do with a stick the flies back to its owner. ;;
The beast <<rushes ^ runs at>> the stick, and then veers off, thundering around the <<field ^ meadow>>. The stick returns to your hand. The beast <<rushes ^ runs at>> the stick, and then veers off, thundering around the <<field ^ meadow>>. The stick returns to $your() hand.
""") """)
self.adjust_character(thrower, 30) self.adjust_character(thrower, 30)

View file

@ -145,11 +145,7 @@ class CmdShrubSay(Command):
aliases = ["write"] aliases = ["write"]
def func(self): def func(self):
here = self.caller.location self.obj.write(self.args.strip())
msg = routput("The shrub uses a branch to << brush ^ wipe >> << off ^ >> << the chalk from ^ >> its << small ^ >> chalkboard, and with another branch, << slowly ^ carefully ^ deliberately ^ >> starts to write << something ^ a message ^ >>.")
here.msg_contents(msg)
self.caller.db.inside = self.args.strip()
self.caller.record_msg(f"The chalkboard reads: |w{self.args}|n")
class CmdSetShrubSay(CmdSet): class CmdSetShrubSay(CmdSet):
@ -169,54 +165,66 @@ class Shrub(Puppet):
"Called when a character is first created." "Called when a character is first created."
self.cmdset.add(CmdSetShrubSay, persistent=True) self.cmdset.add(CmdSetShrubSay, persistent=True)
def find_actor(self, msg, default=None): def write(self, new_text):
"""
Change the readable message on the chalkboard.
This will also record the new message in the log.
"""
here = self.location
msg = routput("The shrub uses a branch to << brush ^ wipe >> << off ^ >> << the chalk from ^ >> its << small ^ >> chalkboard, and with another branch, << slowly ^ carefully ^ deliberately ^ >> starts to write << something ^ a message ^ >>.")
here.msg_contents(msg)
self.db.inside = f"The chalkboard reads: |w{new_text}|n"
self.record_msg(self.db.inside)
def find_actor(self, text, default=None):
""" """
Extract the character performing the action from the text. Extract the character performing the action from the text.
""" """
if default: if default:
return default return default
m = match(r".*\|b(.*?)\|n.*", msg) m = match(r".*\|b(.*?)\|n.*", text)
if m: if m:
return m.group(1) return m.group(1)
def capitalize_msg(self, msg, msg_type=None): def capitalize_msg(self, text, msg_type=None):
""" """
If msg is lowercase, capitalize it. If text is lowercase, capitalize it.
Maybe prepend a 'The' to the front. Maybe prepend a 'The' to the front.
""" """
if msg_type == 'traverse' or msg_type == 'teleport': if msg_type and msg_type in ('traverse', 'teleport'):
if match(r"^(\|[A-z])?[aeiou]", msg): if match(r"^(\|[A-z])?[aeiou]", text):
return "An " + msg return "An " + text
else: else:
return "A " + msg return "A " + text
elif msg_type == 'say' and match(r"^\|b[a-z]", msg): elif msg_type and msg_type == 'say' and match(r"^\|b[a-z]", text):
return "The " + msg return "The " + text
elif match(r"^(\|[A-z])[a-z]", msg) and len(msg) > 2: elif match(r"^(\|[A-z])[a-z]", text) and len(text) > 2:
return msg[0:1] + msg[2].upper() + msg[3:] return text[0:1] + text[2].upper() + text[3:]
elif match(r"^(\|[A-z])?[a-z]", msg) and len(msg) > 2: elif match(r"^(\|[A-z])?[a-z]", text) and len(text) > 2:
return msg[0].upper() + msg[1:] return text[0].upper() + text[1:]
return msg return text
def to_html(self, msg, msg_type=None): def to_html(self, text, msg_type=None):
""" """
Convert the 'msg' to an HTML formatted string. Convert the 'text' to an HTML formatted string.
""" """
# Bold anything white: # Bold anything white:
msg = sub(r"\|w(.*?)\|n", '<b>\\1</b>', msg) text = sub(r"\|w(.*?)\|n", '<b>\\1</b>', text)
# Remove the rest: # Remove the rest:
msg = sub(r"\|[A-z]", '', msg) text = sub(r"\|[A-z]", '', text)
# Remove initial or final carriage returns: # Remove initial or final carriage returns:
msg = sub(r"^\n", '', msg) text = sub(r"^\n", '', text)
msg = sub(r"\n$", '', msg) text = sub(r"\n$", '', text)
# Convert the carriage returns: # Convert the carriage returns:
msg = sub(r"\n", ' <br/>\n', msg) text = sub(r"\n", ' <br/>\n', text)
if msg_type == 'look': if msg_type and msg_type == 'look':
msg = msg[0].upper + msg[1:] text = text[0].upper + text[1:]
return f"<div class=\"special\"><p>{msg}</p></div>\n" return f"<div class=\"special\"><p>{text}</p></div>\n"
return f"<p>{msg}</p>\n" return f"<p>{text}</p>\n"
def record_msg(self, text, actor=None): def record_msg(self, text, actor=None):
msg_type = None msg_type = None