"""
Exits

Exits are connectors between Rooms. An exit always has a destination property
set and has a single command defined on itself with the same name as its key,
for allowing Characters to traverse the exit to its destination.

"""

from evennia.objects.objects import DefaultExit

from .objects import ObjectParent
from commands.take import CmdSetKnock

class Exit(ObjectParent, DefaultExit):
    """
    Exits are connectors between rooms. Exits are normal Objects except
    they defines the `destination` property and overrides some hooks
    and methods to represent the exits.

    See mygame/typeclasses/objects.py for a list of
    properties and methods available on all Objects child classes like this.

    """
    def at_traverse(self, traveler, destination):
        pre_check = traveler.at_pre_move(destination)
        if pre_check:
            if self.db.traverse_msg:
                traveler.msg(f"\n{self.db.traverse_msg}\n\n")
            return super().at_traverse(traveler, destination)
        else:
            return False

class KnockableExit(Exit):
    def at_object_creation(self):
        self.cmdset.add_default(CmdSetKnock)

    def do_knock(self, knocker):
        knocker.msg("You knock.")
        self.location.msg_contents(f"{knocker.name} knocks on {self.key}.",
                                   exclude=knocker)
