moss-n-puddles/typeclasses/rooms.py
Howard Abrams 6b8a9e946b Create new dynamic say command
This also includes a 'gm' command that should make GMing a game
better.
2025-04-25 16:00:39 -07:00

111 lines
3.3 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)
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):
num_chars = len(self.contents_get(content_type="character"))
char_list = super().get_display_characters(looker, pose=True)
if len(self.filter_visible(self.contents_get(content_type="object"), looker, **kwargs)) > 0:
also = 'also '
else:
also = ''
if num_chars > 2:
return f"You {also}see the following characters:\n" + char_list
if num_chars > 1:
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