Snippets

Paul Schuster traitroom

Created by Paul Schuster last modified
"""
TraitRoom

Allows for a (very simple) bool based expanded descriptions

This allows for scripts to place traits in the room, and if a trait is present
show the corresponding description stored in a dict.

Further things that you could add:
  A command to set/delete a trait
  A command to add/delete/edit the trait descriptions
  Simple functions as traits (ex $player_name)
  
Note the output is a complete mess and will have to be adjusted.
"""

from evennia import DefaultRoom

class TraitRoom(DefaultRoom):
    """
    """
    def at_object_creation(self):
        super(TraitRoom, self).at_object_creation()
        self.db.traits=[]
        self.db.trait_desc = {}

    def return_appearance(self, looker):
        """
        This is called when e.g. the look command wants to retrieve
        the description of this object.

        Args:
            looker (Object): The object looking at us.

        Returns:
            description (str): Our description
        """
        # all of the functions must be in the form f(looker)
        room_functions = {'$player_name': player_name}        

        # get the legacy desc
        reply = super(TraitRoom, self).return_appearance(looker)
        for trait in self.db.traits:
            if trait in room_functions:
                reply += room_functions[trait](looker)
            elif trait in self.db.trait_desc:
                reply += self.db.trait_desc[trait]
        return reply
        
def player_name(looker):
    """
    Return the name of the looker
    
    Args:
        looker (Object): The object looking
        
    Return:
        (str): the looker's name
    """
    return looker.name

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.