moss-n-puddles/typeclasses/sittables.py
Howard Abrams 66cabcc1a2 Animate the Wee Beastie and scrying into rooms
This commit gives an "AI" capability to any object (still
triggered by the 'say' command), so now the Wee Beastie can do more
than purr.

Also fixes the Witch and the Dragon's movements throughout the Realm.

We can also Scry into rooms in order to watch the behavior of the Chatbots.
2026-04-16 17:09:15 -07:00

108 lines
3.3 KiB
Python
Executable file

#!/usr/bin/env python
from typeclasses.objects import Object
from commands.sittables import CmdSetSit
from utils.scoring import Scores
from utils.word_list import routput
class Sittable(Object):
multiple = False
def at_object_creation(self):
self.cmdset.add_default(CmdSetSit)
def sit_msg(self):
adjective = self.db.adjective or "on"
article = self.db.article or "the"
extra = self.db.extra or ""
if self.multiple:
return routput(f"You sit {adjective} one of {article} {self.key}. {extra}")
else:
return routput(f"You sit {adjective} {article} {self.key}. {extra}")
def stand_msg(self):
return f"You stand up from {self.key}."
def do_sit(self, sitter):
"""
Called when trying to sit on/in this object.
Args:
sitter (Object): The one trying to sit down.
"""
adjective = self.db.adjective or "on"
article = self.db.article or "the"
current = self.db.sitter
if sitter.db.is_sitting:
sitter.msg(f"You are already sitting {adjective} {article} {self.key}.")
return
# Clean up an issue that sometimes someone logs off or leaves
# a room without standing first.
if self.db.sitter:
if self.db.sitter not in self.location.contents:
self.db.sitter = None
if self.db.sitter and not self.multiple:
sitter.msg(f"You can't sit {adjective} {article} {self.key} "
f"- {current.get_display_name(sitter)} is already sitting there!")
return
self.db.sitter = sitter
sitter.db.is_sitting = self
sitter.score(Scores.moss_sit)
if self.multiple:
sitter.announce_action(f"$You() $conj(sit) {adjective} one of {article} {self.key}.")
else:
sitter.announce_action(f"$You() $conj(sit) {adjective} {article} {self.key}.")
sitter.location.other_sit(sitter)
for puppet in sitter.puppets_here("other_sit"):
puppet.other_sit(sitter)
def do_stand(self, stander):
"""
Called when trying to stand from this object.
Args:
stander (Object): The one trying to stand up.
"""
adjective = self.db.adjective or "on"
current = self.db.sitter
if not stander == current:
stander.msg(f"You are not sitting {adjective} {self.key}.")
else:
self.db.sitter = None
del stander.db.is_sitting
stander.msg(self.stand_msg())
stander.location.other_stand(stander)
for puppet in stander.puppets_here():
puppet.other_stand(stander)
class Sittables(Sittable):
multiple = True
def sit_msg(self):
aliases = self.aliases.all()
adjective = self.db.adjective or "on"
article = self.db.article or "the"
name = aliases[-1] # Last alias is singular
default = f"{article} {name}"
singular = self.db.singular or default
extra = self.db.extra or ""
return routput(f"You sit {adjective} {singular}. {extra}")
def stand_msg(self):
article = self.db.article or "the"
default = f"{article} {self.db.name}"
singular = self.db.singular or default
return f"You stand up from {singular}."