moss-n-puddles/typeclasses/rooms.py
2025-06-21 10:57:21 -07:00

146 lines
4.2 KiB
Python

"""
Room
Rooms are simple containers that has no location of their own.
"""
from datetime import datetime
from re import match
from evennia import utils
from evennia.utils import gametime, logger
from evennia.contrib.grid.extended_room import ExtendedRoom
from evennia.contrib.rpg.rpsystem import ContribRPRoom
from django.conf import settings
# from .objects import LightSource
from .pets import Hunger
from .objects import ObjectParent
_SEARCH_AT_RESULT = utils.object_from_module(settings.SEARCH_AT_RESULT)
def articlize_character(character, capitalize=False):
"""
Return a simple character with article prefix.
"""
if capitalize:
article = "A"
else:
article = "a"
if character == "" or match(r"^\|[bm][A-Z]", character):
return character
elif match(r"^\|[bm][aeiou]", character):
return f"{article}n " + character
else:
return f"{article} " + character
def captialize_characters(characters):
"""
Capitalizes and prefixes an article on string of characters.
Assuming one per line.
"""
char_list = characters.split("\n")
updated = [articlize_character(ch, True) for ch in char_list]
return "\n".join(updated)
class Room(ObjectParent, ExtendedRoom, ContribRPRoom):
"""
Rooms are like any Object, except their location is None
(which is default). They also use basetype_setup() to
add locks so they cannot be puppeted or picked up.
(to change that, use at_object_creation instead)
See mygame/typeclasses/objects.py for a list of
properties and methods available on all Objects.
"""
is_dark = False
has_weather = False
appearance_template = """
{header}
|c{name}{extra_name_info}|n
{desc}
{exits}
{things}
{characters}
{footer}
"""
def get_time(self):
"""
Return tuple of current time of this location.
(Minute, Hour, Time of Day, Season)
"""
timestamp = gametime.gametime(absolute=True)
datestamp = datetime.fromtimestamp(timestamp)
return (datestamp.minute, datestamp.hour,
self.get_time_of_day(), self.get_season())
def get_display_header(self, looker, **kwargs):
return "|n"
def get_display_footer(self, looker, **kwargs):
return "|n"
def get_display_characters(self, looker, *args, **kwargs):
chars = self.contents_get(content_type="character")
vchars = self.filter_visible(chars, looker, **kwargs)
num_chars = len(vchars)
char_list = super().get_display_characters(looker, pose=True)
# We add the word 'also' in case we showed there were objects:
objs = self.contents_get(content_type="object")
if len(objs) > 0:
also = 'also '
else:
also = ''
if num_chars > 1:
return f"You {also}see the following characters:" + \
captialize_characters(char_list)
if num_chars > 0:
character = char_list.strip()
if character.startswith('|'):
comp_char = character[2:].lower()
else:
comp_char = character.lower()
if match(r"an? |the ", comp_char):
return f"You {also}see {character}."
elif match(r"[aeiou]", comp_char):
return f"You {also}see an {character}."
else:
return f"You {also}see a {character}."
return ''
def get_display_things(self, looker, *args, **kwargs):
std_msg = super().get_display_things(looker, pose=False)
if std_msg:
return std_msg.replace('|wYou see:|n', 'You notice') + '.'
else:
return ''
class DabblersRoom(Room):
def get_display_desc(self, looker):
fire = self.search("fire")
full_desc = self.db.initial_desc
if fire.hunger() == Hunger.RAVENOUS:
full_desc += " " + self.db.fire_out
elif fire.hunger() == Hunger.HUNGRY:
full_desc += " " + self.db.fire_dim
elif fire.hunger() == Hunger.FULL:
full_desc += " " + self.db.fire_full
else:
full_desc += " " + self.db.fire_on
full_desc += " " + self.db.final_desc
return full_desc