Multiple chairs and a fire bugfix
This commit is contained in:
parent
8c9f89c92e
commit
af1655fadb
3 changed files with 100 additions and 11 deletions
|
|
@ -9,6 +9,7 @@ Each level of pet requires more aspects for interaction.
|
|||
|
||||
from typeclasses.objects import Object
|
||||
from commands.feedables import CmdFeed, CmdFeedSet
|
||||
from utils.word_list import squish
|
||||
|
||||
from evennia import (
|
||||
TICKER_HANDLER,
|
||||
|
|
@ -119,8 +120,9 @@ class Pet(Object):
|
|||
"""
|
||||
curr = self.hunger()
|
||||
amount = kwargs.get('amount', self.hungry_rate)
|
||||
|
||||
self.db.hunger_level = self.db.hunger_level + amount
|
||||
if self.db.hunger_level < 0:
|
||||
self.db.hunger_level = 0
|
||||
if self.hunger() != curr:
|
||||
self.location.msg_contents("|w%s|n\n" % self.hunger_appearance())
|
||||
|
||||
|
|
@ -162,7 +164,7 @@ class Fire(Pet):
|
|||
}
|
||||
|
||||
def feed(self, feeder, args):
|
||||
super().update_hunger(feeder, amount=300)
|
||||
self.update_hunger(feeder=feeder, amount=300)
|
||||
|
||||
now = time()
|
||||
last_fed = feeder.ndb.fire_last_fed # could be None
|
||||
|
|
@ -173,6 +175,12 @@ class Fire(Pet):
|
|||
|
||||
feeder.ndb.fire_last_fed = now
|
||||
|
||||
feeder.msg(f"You put some {adj} wood on the fire in the fireplace.")
|
||||
self.location.msg_contents(f"{feeder.name} gets up and puts {adj} wood on the fire.",
|
||||
get_up = ""
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -2,11 +2,24 @@
|
|||
|
||||
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.
|
||||
|
|
@ -16,17 +29,24 @@ class Sittable(Object):
|
|||
|
||||
"""
|
||||
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} {self.key}.")
|
||||
else:
|
||||
sitter.msg(f"You can't sit {adjective} {self.key} "
|
||||
f"- {current.key} is already sitting there!")
|
||||
return
|
||||
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(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):
|
||||
"""
|
||||
|
|
@ -43,4 +63,25 @@ class Sittable(Object):
|
|||
else:
|
||||
self.db.sitter = None
|
||||
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
40
utils/word_list.py
Executable 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))
|
||||
Loading…
Reference in a new issue