Create a functioning, magical pipe

This fixes an issue for using the RP system with the built-in
funcparser, and the "actor stance".
This commit is contained in:
Howard Abrams 2025-05-18 00:39:09 -07:00
parent bd745e999b
commit 166bfed218
8 changed files with 132 additions and 36 deletions

View file

@ -1,9 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
from .command import Command from evennia.commands.default.muxcommand import MuxCommand
from evennia import CmdSet from evennia import CmdSet
from evennia.utils import logger from evennia.utils import logger
from .command import Command
class CmdKnock(Command): class CmdKnock(Command):
""" """
@ -70,3 +72,56 @@ class CmdThrow(Command):
class CmdSetStick(CmdSet): class CmdSetStick(CmdSet):
def at_cmdset_creation(self): def at_cmdset_creation(self):
self.add(CmdThrow) self.add(CmdThrow)
class CmdLight(Command):
"""
Light something on fire, preferably a pipe.
Usage:
light [ object ]
"""
key = "light"
locks = "cmd:holds()"
def func(self):
self.obj.do_light(self.caller)
class CmdSmoke(MuxCommand):
"""
Smoke and blow a shape with your magical pipe.
Usage:
smoke [ options [= description]]
Where 'options' can be:
- ring : a traditional or multicolored smoke ring
- dragon : a dragon shape
If an 'option' is not given, then resorts to the attribute,
'smoke_msg'.
"""
key = "smoke"
aliases = ['puff', 'blow']
locks = "cmd:holds()"
def func(self):
if self.lhs:
if self.lhs == 'ring':
self.obj.do_ring(self.caller, self.rhs)
elif self.lhs == 'dragon':
self.obj.do_dragon(self.caller, self.rhs)
else:
self.caller.msg(f"The option, '{self.lhs}' isn't available.")
else:
self.obj.do_smoke(self.caller)
class CmdSetSmoke(CmdSet):
def at_cmdset_creation(self):
self.add(CmdLight)
self.add(CmdSmoke)

View file

@ -274,12 +274,14 @@ class Character(Object, GenderCharacter, ContribRPCharacter):
# function call. # function call.
return super().at_look(target) return super().at_look(target)
def announce_action(self, message): def announce_action(self, message, exclude=None):
""" """
Replaces a location's 'msg_contents' with an emote. Replaces a location's 'msg_contents' with an emote.
""" """
targets = [item for item in self.location.contents if item != self] # All this does is add the character's gender to the message:
send_emote(self, targets, f"/Me {message}", msg_type="say", anonymous_add=None, quiet=True) newmsg = sub(r"\$pron\((.*?)\)", f"$pron(\\1, {self.db.gender})", message)
choose = choices(newmsg)
self.location.msg_contents(f"{choose}", from_obj=self, exclude=exclude)
def spell_sequence(self, location, messages, time_delay=1): def spell_sequence(self, location, messages, time_delay=1):
""" """

View file

@ -110,8 +110,7 @@ class Teapot(Object):
desc = routput(TEA_TYPES[self.db.tea_type]) desc = routput(TEA_TYPES[self.db.tea_type])
self.db.desc = f"A large, brown teapot full of {desc}." self.db.desc = f"A large, brown teapot full of {desc}."
drinker.msg(f"You make a teapot of {desc}.") drinker.announce_action(f"$You() $conj(make) a teapot of {desc}.")
drinker.announce_action(f"makes a teapot of {desc}.")
def do_fill(self, drinker): def do_fill(self, drinker):
teatype = self.db.tea_type teatype = self.db.tea_type

View file

@ -162,17 +162,12 @@ class Fire(Pet):
get_up = "" get_up = ""
gets_up = "" gets_up = ""
if giver.db.is_sitting: if giver.db.is_sitting:
get_up = "get up and" get_up = "$conj(get) up and"
gets_up = "gets up and"
if self.db.hunger_level < 5: if self.db.hunger_level < 5:
giver.msg(squish(f"You {get_up} put {adj} wood in the " giver.announce_action(f"$You() {get_up} $conj(start) a fire.")
f"fireplace, and start a fire."))
giver.announce_action(f"{gets_up} starts a fire.")
else: else:
giver.msg(squish(f"You {get_up} put {adj} wood on the " giver.announce_action(f"$You() {get_up} << $conj(feed) ^ put {adj} wood on >> the fire << in the fireplace ^ >>.")
f"fire in the fireplace."))
giver.announce_action(f"{gets_up} put wood on the fire.")
def feed(self, giver, obj=None): def feed(self, giver, obj=None):
""" """

View file

@ -165,8 +165,7 @@ class Book(Readable):
self.cmdset.add_default(CmdSetBook) self.cmdset.add_default(CmdSetBook)
def do_read(self, reader): def do_read(self, reader):
super().do_read(reader) reader.announce_action("$You() $conj(read) $pron(your) book.")
reader.announce_action("reads |p book.")
def at_pre_drop(self, reader): def at_pre_drop(self, reader):
if reader.location.key == "Dabbler's House": if reader.location.key == "Dabbler's House":

View file

@ -88,9 +88,15 @@ class Room(ObjectParent, ExtendedRoom, ContribRPRoom):
return "|n" return "|n"
def get_display_characters(self, looker, *args, **kwargs): def get_display_characters(self, looker, *args, **kwargs):
num_chars = len(self.contents_get(content_type="character")) chars = self.contents_get(content_type="character")
vchars = self.filter_visible(chars, looker, **kwargs)
num_chars = len(vchars)
char_list = super().get_display_characters(looker, pose=True) char_list = super().get_display_characters(looker, pose=True)
if len(self.filter_visible(self.contents_get(content_type="object"), looker, **kwargs)) > 0:
# We add the word 'also' in case we showed there were objects:
objs = self.contents_get(content_type="object")
if len(objs) > 0:
also = 'also ' also = 'also '
else: else:
also = '' also = ''

View file

@ -44,8 +44,7 @@ class Sittable(Object):
self.db.sitter = sitter self.db.sitter = sitter
sitter.db.is_sitting = self sitter.db.is_sitting = self
sitter.msg(self.sit_msg()) sitter.announce_action(f"$You() $conj(sit) {adjective} {article} {self.key}.")
sitter.announce_action(f"sits {adjective} {article} {self.key}.")
def do_stand(self, stander): def do_stand(self, stander):
""" """

View file

@ -1,12 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
from random import choice, random from random import choice, random, randint
from enum import Enum from enum import Enum
from evennia import create_script from evennia import create_script
from evennia.utils import logger, delay from evennia.utils import logger, delay
from commands.misc import CmdSetPuddle, CmdSetStick, CmdSetKnock from commands.misc import CmdSetPuddle, CmdSetStick, CmdSetKnock, CmdSetSmoke
from commands.wizards import CmdSetWand from commands.wizards import CmdSetWand
from utils.word_list import routput, choices from utils.word_list import routput, choices
from .scripts import KnockScript from .scripts import KnockScript
@ -111,7 +111,9 @@ class Pipe(Object):
Where the |p is a possessive gender, if set, e.g. his or her. Where the |p is a possessive gender, if set, e.g. his or her.
The random messages has available substitutions based on if the message is for the smoker or for the audience in the room. Specifically: The random messages has available substitutions based on if the
message is for the smoker or for the audience in the room.
Specifically:
- {0} :: either "you" or your name - {0} :: either "you" or your name
- {1} :: either "your" or your name with an apostrophe 's. - {1} :: either "your" or your name with an apostrophe 's.
@ -120,16 +122,54 @@ class Pipe(Object):
For instance: For instance:
@set pipe/random_msgs = "{0} blow{1} a <<large ^ small ^ >> smoke-ring followed by another that flies through the first. ;; {1} smoke collesce to form a <<dragon ^ large woodland beast ^ beholder ^ bugbear>> ... or @set pipe/random_msgs = "{0} blow{1} a <<large ^ small ^ >> smoke-ring followed by another that flies through the first. ;; {1} smoke collesce to form a <<dragon ^ large woodland beast ^ beholder ^ bugbear>> ... or
"""
def do_light(self, lighter):
you_msg = choices(self.db.light_msg or "You pack and light your pipe.")
lighter.msg(you_msg)
# desc = self.return_appearance()[:1].lower() + self.return_appearance()[1:]
other_msg = choices(self.db.light_msg_other or "packs and lights |p pipe.")
lighter.announce_action(other_msg)
def do_puff(self, smoker): """
pass def at_object_creation(self):
self.cmdset.add_default(CmdSetSmoke)
def do_light(self, lighter):
msg = choices(self.db.light_msg or "$You() $conj(pack) and $conj(light) $pron(your) pipe.")
lighter.announce_action(msg)
def do_smoke(self, smoker):
msg = choices(self.db.smoke_msg or "$You() << $conj(lean) back and ^ >> << $conj(puff) ^ $conj(smoke) >> $pron(your) pipe.")
smoker.announce_action(msg)
def do_ring(self, smoker, details=None):
self.db._last_option = 'ring'
self.db._last_detail = details
details = details or ""
msg = choices(f"$You() $conj(blow) a {details} << smoke ring ^ ring of smoke >>.")
smoker.announce_action(msg)
if randint(1, 10) < 5:
delay(randint(5, 15), self.do_ring_dissipate)
def do_ring_dissipate(self):
msg = choices("""
The smoke ring << flies around before it ^ shoots across the room before it ^ >> << eventually ^ finally >> << dissipates ^ disperses >>. ;;
The ring hovers, spinning in place, before << dissipating ^ dispersing >>. ;;
The smoke ring changes << colors ^ to purple ^ to blue ^ to pink>> before << dissipating ^ dispersing >>.
""")
self.location.location.msg_contents(msg)
def do_dragon(self, smoker, details=None):
self.db._last_option = 'dragon'
self.db._last_detail = details
details = details or ""
msg = choices(f"The smoke from $pron(your) pipe << coalesces ^ coheres >> << to form ^ into the shape of ^ and resembles ^ to look like >> a {details} dragon.")
smoker.announce_action(msg)
if randint(1, 10) < 8:
delay(randint(5, 15), self.do_dragon_dissipate)
def do_dragon_dissipate(self):
msg = choices("""
The smoke dragon << flies around ^ soars across the room ^ bellows >> before it << eventually ^ finally >> << dissipates ^ disperses >>. ;;
The smoke dragon changes << colors ^ to purple ^ to blue ^ to pink>> before << dissipating ^ dispersing >>.
""")
self.location.location.msg_contents(msg)
class Wood(Object): class Wood(Object):
@ -163,7 +203,8 @@ class Stick(Object):
"This is a <<fun ^ pleasant ^ nice>> <<past-time ^ game>>.", "This is a <<fun ^ pleasant ^ nice>> <<past-time ^ game>>.",
"Maybe we should get a pet <<or beast ^ beastie ^ >> in here who would love to play.", "Maybe we should get a pet <<or beast ^ beastie ^ >> in here who would love to play.",
], thrower.name.capitalize())) ], thrower.name.capitalize()))
thrower.announce_action("throws |p stick.") thrower.announce_action("$You() $conj(throw) $pron(your) stick.",
exclude=thrower)
else: else:
thrower.msg("I think you should be outside or a place with more room before you throw that stick around.") thrower.msg("I think you should be outside or a place with more room before you throw that stick around.")
@ -197,7 +238,8 @@ class Puddle(Object):
"happy.", "happy.",
"great.", "great.",
]))) ])))
player.announce_action("jumps in the puddle.") player.announce_action("$You() << $conj(jump) ^ $conj(splash) ^ $conj(play) >> in the puddle.",
exclude=player)
class Knocker_Convo(Enum): class Knocker_Convo(Enum):
@ -399,8 +441,7 @@ class Knocker(Object):
("waker", self), ("waker", self),
("room", self.db.room_to_msg) ("room", self.db.room_to_msg)
]) ])
knocker.msg("You grab the ring and knock firmly on the door.") knocker.announce_action("$You() $conj(grab) the ring and $conj(knock) << firmly ^ loudly ^ aggressively >> on the door.")
knocker.announce_action("grabs the ring and knocks firmly on the door.")
else: else:
knocker.msg("This door knocker is defective, as it doesn't have a ring to...er, do the knockin'.") knocker.msg("This door knocker is defective, as it doesn't have a ring to...er, do the knockin'.")