Multiple chairs and a fire bugfix

This commit is contained in:
Howard Abrams 2025-01-30 21:35:38 -08:00
parent 8c9f89c92e
commit af1655fadb
3 changed files with 100 additions and 11 deletions

View file

@ -9,6 +9,7 @@ Each level of pet requires more aspects for interaction.
from typeclasses.objects import Object from typeclasses.objects import Object
from commands.feedables import CmdFeed, CmdFeedSet from commands.feedables import CmdFeed, CmdFeedSet
from utils.word_list import squish
from evennia import ( from evennia import (
TICKER_HANDLER, TICKER_HANDLER,
@ -119,8 +120,9 @@ class Pet(Object):
""" """
curr = self.hunger() curr = self.hunger()
amount = kwargs.get('amount', self.hungry_rate) amount = kwargs.get('amount', self.hungry_rate)
self.db.hunger_level = self.db.hunger_level + amount self.db.hunger_level = self.db.hunger_level + amount
if self.db.hunger_level < 0:
self.db.hunger_level = 0
if self.hunger() != curr: if self.hunger() != curr:
self.location.msg_contents("|w%s|n\n" % self.hunger_appearance()) self.location.msg_contents("|w%s|n\n" % self.hunger_appearance())
@ -162,7 +164,7 @@ class Fire(Pet):
} }
def feed(self, feeder, args): def feed(self, feeder, args):
super().update_hunger(feeder, amount=300) self.update_hunger(feeder=feeder, amount=300)
now = time() now = time()
last_fed = feeder.ndb.fire_last_fed # could be None last_fed = feeder.ndb.fire_last_fed # could be None
@ -173,6 +175,12 @@ class Fire(Pet):
feeder.ndb.fire_last_fed = now feeder.ndb.fire_last_fed = now
feeder.msg(f"You put some {adj} wood on the fire in the fireplace.") get_up = ""
self.location.msg_contents(f"{feeder.name} gets up and puts {adj} wood on the fire.", gets_up = ""
if feeder.db.is_sitting:
get_up = "get up and"
gets_up = "gets up and"
feeder.msg(squish(f"You {get_up} put some {adj} wood on the fire in the fireplace."))
self.location.msg_contents(squish(f"{feeder.name} {gets_up} puts {adj} wood on the fire."),
exclude=feeder) exclude=feeder)

View file

@ -2,11 +2,24 @@
from typeclasses.objects import Object from typeclasses.objects import Object
from commands.sittables import CmdSetSit from commands.sittables import CmdSetSit
from utils.word_list import routput
class Sittable(Object): class Sittable(Object):
multiple = False
def at_object_creation(self): def at_object_creation(self):
self.cmdset.add_default(CmdSetSit) 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): def do_sit(self, sitter):
""" """
Called when trying to sit on/in this object. Called when trying to sit on/in this object.
@ -16,17 +29,24 @@ class Sittable(Object):
""" """
adjective = self.db.adjective or "on" adjective = self.db.adjective or "on"
article = self.db.article or "the"
current = self.db.sitter current = self.db.sitter
if current: if current:
if current == sitter: if current == sitter:
sitter.msg(f"You are already sitting {adjective} {self.key}.") sitter.msg(f"You are already sitting {adjective} {article} {self.key}.")
else: return
sitter.msg(f"You can't sit {adjective} {self.key} " elif not self.multiple:
sitter.msg(f"You can't sit {adjective} {article} {self.key} "
f"- {current.key} is already sitting there!") f"- {current.key} is already sitting there!")
return return
self.db.sitter = sitter self.db.sitter = sitter
sitter.db.is_sitting = self sitter.db.is_sitting = self
sitter.msg(f"You sit {adjective} {self.key}") sitter.msg(self.sit_msg())
self.location.msg_contents(f"{sitter.name} sits {adjective} {article} {self.key}.",
exclude=sitter)
def do_stand(self, stander): def do_stand(self, stander):
""" """
@ -43,4 +63,25 @@ class Sittable(Object):
else: else:
self.db.sitter = None self.db.sitter = None
del stander.db.is_sitting del stander.db.is_sitting
stander.msg(f"You stand up from {self.key}.") stander.msg(self.stand_msg())
class Sittables(Sittable):
multiple = True
def sit_msg(self):
adjective = self.db.adjective or "on"
article = self.db.article or "the"
default = f"{article} {self.db.name}"
singular = self.db.singular or default
extra = self.db.extra or ""
aliases = self.aliases.all()
name = aliases[1] # Second alias is singular
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}."

40
utils/word_list.py Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
import random
import re
import string
class Token():
def __init__(self, string):
self.words = ''.join(ch for ch in string if ch not in string.punctuation).split()
def contains(self, word):
if len(self.words) > 0:
return [True for w in self.words if w == word][0]
else:
return False
def squish(text):
"Remove series of spaces from the text."
return re.sub(' *', ' ', text)
def routput(string):
"""
Return string with internal word choices replaced randomly.
For instance, the string:
'This feels [|very|quite] [nice|cozy|comfortable].'
Could return any of the following strings:
'This feels quite nice.'
'This feels cozy.'
'This feels very comfortable.'
"""
# string =
acc = []
for s in string.split("["):
choices, *rest = s.split("]")
choice = random.choice(choices.split('|'))
acc = acc + [choice] + rest
return squish(''.join(acc))