moss-n-puddles/typeclasses/sittables.py
Howard Abrams 43a1aefb49 Add a Scoring system to character
As character do things, they can now get a "score" for everything I
think could be interesting/challenging.
2025-08-24 22:34:11 -07:00

102 lines
3.1 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 ""
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)
sitter.announce_action(f"$You() $conj(sit) {adjective} {article} {self.key}.")
sitter.location.other_sit(sitter)
for puppet in sitter.puppets_here():
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}."