moss-n-puddles/typeclasses/sittables.py
Howard Abrams 3d1ebfa3fc Adding a batchcommands file with descriptions
And fixed a number of bugs with starting from scratch.
2025-02-12 22:37:19 -08:00

88 lines
2.6 KiB
Python
Executable file

#!/usr/bin/env python
from typeclasses.objects import Object
from commands.sittables import CmdSetSit
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 ""
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 current:
if current == sitter:
sitter.msg(f"You are already sitting {adjective} {article} {self.key}.")
return
elif not self.multiple:
sitter.msg(f"You can't sit {adjective} {article} {self.key} "
f"- {current.key} is already sitting there!")
return
self.db.sitter = sitter
sitter.db.is_sitting = self
sitter.msg(self.sit_msg())
self.location.msg_contents(f"{sitter.name} sits {adjective} {article} {self.key}.",
exclude=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())
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}."