Create a cat as a player-pupppetable NPC
This commit is contained in:
parent
5a1f8d8b56
commit
e3e87f3ec9
3 changed files with 73 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 <phrase>
|
||||
|
||||
Or:
|
||||
|
||||
cat's <phrase>
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
Loading…
Reference in a new issue