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:
parent
45d591403c
commit
fb45aa44a3
2 changed files with 41 additions and 33 deletions
|
|
@ -558,14 +558,14 @@ class BHB(Friendly):
|
|||
"""
|
||||
match self.friendly_reaction(thrower):
|
||||
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:
|
||||
msg = "The beast walks over to the stick, sniffs it, and backs away."
|
||||
self.adjust_character(thrower, 5)
|
||||
case Reaction.INTERESTED:
|
||||
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 <<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)
|
||||
|
||||
|
|
|
|||
|
|
@ -145,11 +145,7 @@ class CmdShrubSay(Command):
|
|||
aliases = ["write"]
|
||||
|
||||
def func(self):
|
||||
here = self.caller.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.caller.db.inside = self.args.strip()
|
||||
self.caller.record_msg(f"The chalkboard reads: |w{self.args}|n")
|
||||
self.obj.write(self.args.strip())
|
||||
|
||||
|
||||
class CmdSetShrubSay(CmdSet):
|
||||
|
|
@ -169,54 +165,66 @@ class Shrub(Puppet):
|
|||
"Called when a character is first created."
|
||||
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.
|
||||
"""
|
||||
if default:
|
||||
return default
|
||||
|
||||
m = match(r".*\|b(.*?)\|n.*", msg)
|
||||
m = match(r".*\|b(.*?)\|n.*", text)
|
||||
if m:
|
||||
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.
|
||||
"""
|
||||
if msg_type == 'traverse' or msg_type == 'teleport':
|
||||
if match(r"^(\|[A-z])?[aeiou]", msg):
|
||||
return "An " + msg
|
||||
if msg_type and msg_type in ('traverse', 'teleport'):
|
||||
if match(r"^(\|[A-z])?[aeiou]", text):
|
||||
return "An " + text
|
||||
else:
|
||||
return "A " + msg
|
||||
elif msg_type == 'say' and match(r"^\|b[a-z]", msg):
|
||||
return "The " + msg
|
||||
elif match(r"^(\|[A-z])[a-z]", msg) and len(msg) > 2:
|
||||
return msg[0:1] + msg[2].upper() + msg[3:]
|
||||
elif match(r"^(\|[A-z])?[a-z]", msg) and len(msg) > 2:
|
||||
return msg[0].upper() + msg[1:]
|
||||
return msg
|
||||
return "A " + text
|
||||
elif msg_type and msg_type == 'say' and match(r"^\|b[a-z]", text):
|
||||
return "The " + text
|
||||
elif match(r"^(\|[A-z])[a-z]", text) and len(text) > 2:
|
||||
return text[0:1] + text[2].upper() + text[3:]
|
||||
elif match(r"^(\|[A-z])?[a-z]", text) and len(text) > 2:
|
||||
return text[0].upper() + text[1:]
|
||||
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:
|
||||
msg = sub(r"\|w(.*?)\|n", '<b>\\1</b>', msg)
|
||||
text = sub(r"\|w(.*?)\|n", '<b>\\1</b>', text)
|
||||
# Remove the rest:
|
||||
msg = sub(r"\|[A-z]", '', msg)
|
||||
text = sub(r"\|[A-z]", '', text)
|
||||
# Remove initial or final carriage returns:
|
||||
msg = sub(r"^\n", '', msg)
|
||||
msg = sub(r"\n$", '', msg)
|
||||
text = sub(r"^\n", '', text)
|
||||
text = sub(r"\n$", '', text)
|
||||
# Convert the carriage returns:
|
||||
msg = sub(r"\n", ' <br/>\n', msg)
|
||||
text = sub(r"\n", ' <br/>\n', text)
|
||||
|
||||
if msg_type == 'look':
|
||||
msg = msg[0].upper + msg[1:]
|
||||
return f"<div class=\"special\"><p>{msg}</p></div>\n"
|
||||
return f"<p>{msg}</p>\n"
|
||||
if msg_type and msg_type == 'look':
|
||||
text = text[0].upper + text[1:]
|
||||
return f"<div class=\"special\"><p>{text}</p></div>\n"
|
||||
return f"<p>{text}</p>\n"
|
||||
|
||||
def record_msg(self, text, actor=None):
|
||||
msg_type = None
|
||||
|
|
|
|||
Loading…
Reference in a new issue