From b676bb74219b44d39dcbd878b234b5e4a7480797 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Sun, 1 Jun 2025 19:30:39 -0700 Subject: [PATCH] Replace split_party_msg with the announce_action Fixed some long standing inconsistencies. --- commands/everyone.py | 1 + typeclasses/characters.py | 16 +++++++++++++++- typeclasses/pets.py | 27 ++++++++++++++------------- utils/word_list.py | 24 ------------------------ 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/commands/everyone.py b/commands/everyone.py index e1cef8b..d59866a 100755 --- a/commands/everyone.py +++ b/commands/everyone.py @@ -277,6 +277,7 @@ class CmdRead(Command): key = "read" def find_readable(self, searcher, readable_str): + """Search the room for a readable item.""" targets = searcher.search(readable_str, quiet=True) if not targets: searcher.msg(f"You don't see {readable_str}.") diff --git a/typeclasses/characters.py b/typeclasses/characters.py index 476b01e..94906cb 100644 --- a/typeclasses/characters.py +++ b/typeclasses/characters.py @@ -15,7 +15,7 @@ from evennia.contrib.game_systems.gendersub import GenderCharacter from evennia.contrib.rpg.rpsystem import ContribRPCharacter from evennia.contrib.rpg.rpsystem import send_emote from evennia.prototypes.spawner import spawn -from evennia.utils import delay # , logger +from evennia.utils import delay, logger from utils.word_list import routput, choices from .objects import Object @@ -302,6 +302,7 @@ class Character(Object, GenderCharacter, ContribRPCharacter): # All this does is add the character's gender to the message: newmsg = sub(r"\$pron\((.*?)\)", f"$pron(\\1, {self.db.gender})", message) choose = choices(newmsg) + logger.info(choose) self.location.msg_contents(f"{choose}", from_obj=self, exclude=exclude) def spell_sequence(self, location, messages, time_delay=1): @@ -369,3 +370,16 @@ class Character(Object, GenderCharacter, ContribRPCharacter): for puppet in self.puppets_here(): puppet.other_leave(self) return True + + def deeper_search(self, item_str): + targets = self.search(item_str, quiet=True) + if len(targets) > 0: + return targets + + for target in self.location.contents: + logger.info(f"Looking for books at {target}") + inv_items = self.search(item_str, quiet=True, + location=target) + if len(inv_items) > 0: + return inv_items + return None diff --git a/typeclasses/pets.py b/typeclasses/pets.py index fb75bd4..441cddb 100755 --- a/typeclasses/pets.py +++ b/typeclasses/pets.py @@ -16,6 +16,7 @@ from time import time import random from evennia import TICKER_HANDLER +from evennia.utils import logger from evennia.utils.gametime import schedule from typeclasses.objects import Object @@ -23,7 +24,7 @@ from typeclasses.characters import Character # from typeclasses.lightables import LightSource from commands.feedables import CmdFeedSet from commands.pets import CmdPetSet -from utils.word_list import squish, choices, split_party_msg +from utils.word_list import squish, choices class Hunger(Enum): @@ -404,11 +405,11 @@ class Friendly(Pet): # grab the friendly: msg = choices(self.db.ecstatic_actions or self.db.friendly_actions) - if msg and msg not in self.db.last_actions: - self.db.last_actions.append(msg) - # Limit this list so it doesn't grow too large: - self.db.last_actions = self.db.last_actions[-5:] - split_party_msg(focus, msg) + if msg and msg not in self.db.last_actions: + self.db.last_actions.append(msg) + # Limit this list so it doesn't grow too large: + self.db.last_actions = self.db.last_actions[-5:] + focus.announce_action(msg) def pet_response(self, petter): """ @@ -432,9 +433,9 @@ class Friendly(Pet): msg = self.db.pet_ecstatic_response self.adjust_character(petter, self.db.pet_ecstatic_adjust or 10) if msg: - split_party_msg(petter, msg) + petter.announce_action(msg, self.name) else: - petter.msg(f"You pet {self.name}.") + petter.announce_action(f"$You() $conj(pet) {self.name}.") @@ -563,16 +564,16 @@ class BHB(Friendly): self.adjust_character(thrower, 5) case Reaction.INTERESTED: msg = choices(""" - The beast <> at the stick, then looks at , <> what to do with a stick the flies back to its owner. ;; + The beast <> at the stick, then looks at $you(), <> what to do with a stick the flies back to its owner. ;; The beast <> the stick, and then veers off, thundering around the <>. The stick returns to your hand. """) self.adjust_character(thrower, 30) case _: msg = choices(""" - The <> beast <> and <> the stick in midair, and drops it in front of . ;; - The <> beast <> over to the stick and <> around the stick before bringing it back to . ;; - The <> beast <> over to the stick and <> around the stick before bringing it back to .""") + The <> beast <> and <> the stick in midair, and drops it in front of $you(). ;; + The <> beast <> over to the stick and <> around the stick before bringing it back to $you(). ;; + The <> beast <> over to the stick and <> around the stick before bringing it back to $you().""") self.adjust_character(thrower, 10) if msg: - split_party_msg(thrower, msg) + thrower.announce_action(msg) diff --git a/utils/word_list.py b/utils/word_list.py index 2669fb4..66e01bf 100755 --- a/utils/word_list.py +++ b/utils/word_list.py @@ -119,27 +119,3 @@ def choices(text, *substitutions): if text: return routput(choice(text), *substitutions) - - -def split_party_msg(viewer, msg, *substitutions): - """ - Send a message to 'viewer' as well as all people in the area. - - Note that 'msg' could have choices separated by ;; - As well as random words, separated by << one ^ two ^ three >> - As well as one word for 'viewer' and other for rest, as in - <( You ^ {0} )> <( give ^ gives )> the ball. - """ - text = choices(msg, viewer.name.title()) - pattern = compile(r"\<\( *(.*?) *\^ *(.*?) *\)\>") - - # First a message for the view: - viewer.msg( pattern.sub("\\1", text) ) - - # Then the message for the rest of the area: - viewer.location.msg_contents( - pattern.sub("\\2", text), exclude=viewer) - -# def searsonal(text, **kwargs): -# season = kwargs['season'] or kwargs['location'].get_season() -# time_of_day = kwargs['time_of_day'] or kwargs['location'].get_time_of_day()