From daace6e98345d4e248b525847b800f17e88bfc8f Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Mon, 26 May 2025 14:45:43 -0700 Subject: [PATCH] Triggers now work with |p and {0} for a target. Fixed some bugs, including the trailing period when looking at something. --- commands/wizards.py | 28 +++++++++++++++++++++------- typeclasses/characters.py | 25 +++++++++++++++++-------- world/version2.ev | 26 ++++++++++++++++++++------ 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/commands/wizards.py b/commands/wizards.py index 286c60f..b7fa70f 100755 --- a/commands/wizards.py +++ b/commands/wizards.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from random import choice from re import match from evennia import CmdSet, create_script @@ -19,7 +20,9 @@ class CmdFly(Command): Make sure you set the following properties, for instance: @set self/disappear_msg = "The wizard disappears in a puff of smoke." - @set self/reappear_msg = "A plume of <> smoke appears... ;; When the smoke clears, a wizard <>." + @set self/reappear_msg = "A plume of <> + smoke appears... ;; When the smoke clears, a + wizard <>." @set self/appear_delay = 3 The last setting is the number of seconds between message segments @@ -30,6 +33,9 @@ class CmdFly(Command): locks = "cmd:holds()" def func(self): + """ + Call the 'do_fly' method on the caller. + """ self.caller.do_fly(self.args.strip()) @@ -93,12 +99,13 @@ class CmdGM(MuxCommand): me = self.caller + msg = routput(self.args) for o in send_to: if o.is_typeclass('typeclasses.rooms.Room'): chars = o.contents_get(None, 'character') - send_emote(me, chars, self.args, 'say', None) + send_emote(me, chars, msg, 'say', None) elif o.is_typeclass('typeclasses.characters.Character'): - o.msg(self.args) + o.msg(msg) class CmdSpell(Command): @@ -211,7 +218,7 @@ class CmdGMTrigger(Command): if not self.name: npc.msg("What event do you want to trigger?") - for name,details in triggers.items(): + for name, details in triggers.items(): npc.msg(f" - {name} : {details['desc']}") return @@ -231,14 +238,21 @@ class CmdGMTrigger(Command): element goes to 'dests' and the second goes to the room (based on the caller's location). """ + if len(self.send_to) > 0: + target = self.send_to[0] + else: + target = choice(self.caller.characters_here()) + name = target.db._sdesc or target.key or "" + for idx, event in enumerate(events): if isinstance(event, str): + msg = target.gendered_text(routput(event, name)) delay(time_delay * idx, self.caller.location.msg_contents, - "\n" + routput(event)) + "\n" + msg) else: - char = event[0] - room = event[1] + char = target.gendered_text(routput(event[0], name)) + room = target.gendered_text(routput(event[1], name)) if room: delay(time_delay * idx, diff --git a/typeclasses/characters.py b/typeclasses/characters.py index 19fff03..5218896 100644 --- a/typeclasses/characters.py +++ b/typeclasses/characters.py @@ -211,18 +211,18 @@ class Character(Object, GenderCharacter, ContribRPCharacter): key="post_desc") or "" reg_desc = super().return_appearance(looker) - pronoun = self.pronoun_subjective(True) - return self.gendered_text(pre_desc + \ + # pronoun = self.pronoun_subjective(True) + return self.gendered_text(pre_desc + reg_desc.replace('|wYou see:|n', - '|S has') + \ - post_desc + '.') + '|S has') + + post_desc) def at_pre_move(self, destination, *args, **kwargs): """ Called by self.move_to when trying to move somewhere. If this returns False, the move is immediately canceled. """ - self.db.tutorstate = self.db.tutorstate | TutorialState.MOVE.value + self.db.tutorstate = (self.db.tutorstate or 0) | TutorialState.MOVE.value if self.db.is_sitting: self.msg("You stand up first...") @@ -250,7 +250,7 @@ class Character(Object, GenderCharacter, ContribRPCharacter): def at_pre_say(self, message, **kwargs): "While we could/should do 'at_say', this should be easier." - self.db.tutorstate = self.db.tutorstate | TutorialState.SAY.value + self.db.tutorstate = (self.db.tutorstate or 0) | TutorialState.SAY.value return super().at_pre_say(message) def at_look(self, target, **kwargs): @@ -278,9 +278,9 @@ class Character(Object, GenderCharacter, ContribRPCharacter): self.tags.add(hidden_tag) if target.is_typeclass("typeclasses.rooms.Room"): - self.db.tutorstate = self.db.tutorstate | TutorialState.LOOK.value + self.db.tutorstate = (self.db.tutorstate or 0) | TutorialState.LOOK.value else: - self.db.tutorstate = self.db.tutorstate | TutorialState.LOOKAT.value + self.db.tutorstate = (self.db.tutorstate or 0) | TutorialState.LOOKAT.value # Regardless of what happened before, we return the normal # function call. @@ -329,6 +329,15 @@ class Character(Object, GenderCharacter, ContribRPCharacter): self.db.reappear_msg.split(';;'), self.db.appear_delay or 2) + def characters_here(self): + """ + Return a list of characters in the current location. + """ + return [char for char in + self.search("", typeclass="typeclasses.characters.Character", + location=self.location, quiet=True) + if char != self] + # Hooks to the puppets: def puppets_here(self): diff --git a/world/version2.ev b/world/version2.ev index 6cd86b9..84e3b66 100644 --- a/world/version2.ev +++ b/world/version2.ev @@ -153,7 +153,7 @@ py bt = self.search('Bartender'); bt.db.gender = 'male'; bt.db._sdesc = 'blonde # [[file:../../../projects/mud-rpg.org::*Or a Mushroom Bartender][Or a Mushroom Bartender:4]] -@detail mushroom;mushroom man = A stubby mushroom with an enormous red cap and a friendly looking face. Amazing how he can balance cocktails on its head. +@detail mushroom person;mushroom man = A stubby mushroom with an enormous red cap and a friendly looking face. Amazing how he can balance cocktails on its head. # Or a Mushroom Bartender:4 ends here # Pixie Quartet @@ -177,14 +177,27 @@ py bt = self.search('pixies'); bt.db.pose_default = 'playing music atop a giant @desc pixies = Atop a giant fieldcap mushroom, a quartet of pixies playing the strangest instruments you've never seen, fill the room with music. # Pixie Quartet:3 ends here +# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:4]] +@detail mushroom = A giant, beige-colored mushroom grows on the side of this room providing a perfect stage for the pixie musicians. +# Pixie Quartet:4 ends here + # And give him the powers he deserves: -# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:4]] +# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:5]] @perm pixies = Admin -# Pixie Quartet:4 ends here +# Pixie Quartet:5 ends here + + + +# And when Dabbler arrives … + + +# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:6]] +@set pixies/arrive:dabbler = "8 ;; gm The quartet on the mushroom start playing an << interesting ^ odd >> << composition ^ song ^ arrangment >>. ;; 20 ;; The pixie leader says, \"As you can tell, we're playing << a jazz standard ^ a jazz melody ^ something the Mudders call, jazz fusion >>. That's right, something we picked up from << our travels in ^ >> the Mud World." +# Pixie Quartet:6 ends here # Awakened Shrub # Next great NPC will a cameo from the Awakened Shrub. @@ -244,17 +257,18 @@ py bt = self.search('shrub'); bt.db.gender = 'neutral'; bt.db._sdesc = 'shrub'; # [[file:../../../projects/mud-rpg.org::*Dabbler][Dabbler:2]] @set/character #34/triggers:session1 = { "bubbles": {"desc": "Character blows bubbles", - "timer": 10, + "timer": 5, "events": [ + "The old gnome hits his staff on the floor.", ("You notice bubbles coming out every time you open your mouth to speak.", - "Every time |s speaks, you notice bubbles coming from the mouth of /target." + "Every time |s speaks, you notice bubbles coming from the mouth of the {0}." ) ] }, "dark": {"desc": "Make the room go black", "timer": 5, "events": [ - "The /gnome slams his staff against the floor. The room goes completely dark.", + "The old gnome slams his staff against the floor. The room goes completely dark.", "The music stops.", "In the darkness, you see a pair of large red eyes, and a low gutteral growl.", ("You can't help it, but scream!",