From e3e87f3ec9907bef19e5192b05d09531bc9dbf73 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Thu, 29 May 2025 22:23:19 -0700 Subject: [PATCH] Create a cat as a player-pupppetable NPC --- commands/everyone.py | 2 +- commands/misc.py | 27 ++++++++++++++++++++++++++ typeclasses/npcs.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/commands/everyone.py b/commands/everyone.py index 5690ef6..879481c 100755 --- a/commands/everyone.py +++ b/commands/everyone.py @@ -134,7 +134,7 @@ class CmdSay(MuxCommand): When attempting to say something to one or more characters, use the '=' character to identify what you want to say. - """)) + For instance, |gsay/to elf = Hi there.|n """)) return if self.rhs: diff --git a/commands/misc.py b/commands/misc.py index 358bc2c..6dceeb4 100755 --- a/commands/misc.py +++ b/commands/misc.py @@ -165,3 +165,30 @@ class CmdSetRummage(CmdSet): def at_cmdset_creation(self): self.add(CmdRummage) self.add(CmdKeep) + + +class CmdCat(Command): + """Have you cat do some antic. + + Usage: + + cat + + Or: + + cat's + + Will announce your cat's antics to the room. + + You can target another character by preceding the character's + description with a |w/|n, as in |w/elf|n or |w/blonde elf|n. + """ + key = "cat" + + def func(self): + self.obj.at_do(self.caller, self.args.strip()) + + +class CmdSetCat(CmdSet): + def at_cmdset_creation(self): + self.add(CmdCat) diff --git a/typeclasses/npcs.py b/typeclasses/npcs.py index 2cddfc2..7d06278 100755 --- a/typeclasses/npcs.py +++ b/typeclasses/npcs.py @@ -1,8 +1,13 @@ #!/usr/bin/env python +from random import randint +from re import split + from typeclasses.objects import Object +from commands.misc import CmdSetCat from utils.word_list import routput + class NPC(Object): """ An NPC is an NPC because it can react to what it _hears_. @@ -68,3 +73,43 @@ class CarriableNPC(NPC): f"The {self.name}, you are carrying, says, \"{message}\"") owner.location.msg( f"The {self.name}, carried by {self.location.name}, says, \"{message}\"", exclude=owner) + + +class Cat(NPC): + """ + A puppetable 'cat' that acts based on that 'command'. + """ + def at_object_creation(self): + "Called when a cat is first created." + self.cmdset.add(CmdSetCat, persistent=True) + + def at_do(self, owner, antics): + """ + Issue a 'send_emote' into the room with a antic. + """ + def new_name(name): + """ + Take a long name, like: fat, black cat + And return _part_ of the name, like: + + - fat, black cat + - black cat + - cat + """ + + parts = list(filter(lambda s: s != "", split(r"[, ]+", name))) + + num_adjs = len(parts)-1 + lst_adjs = parts[randint(0, num_adjs):num_adjs] + + noun = parts[-1] + adjs = ', '.join(lst_adjs) + return f"{adjs} {noun}" if len(adjs) > 0 else noun + + # The cat's name: + name = self.db._sdesc or self.name + + if antics.startswith("'"): + owner.announce_action(f"$Your() {new_name(name)}{antics}") + else: + owner.announce_action(f"$Your() {new_name(name)} {antics}")