def print_object_location(player, obj, container, print_parentheses=True):
    if not container:
        if print_parentheses:
            player.tell("(It's not clear where %s is)." % obj.name)
        else:
            player.tell("It's not clear where %s is." % obj.name)
        return
    if container in player:
        if print_parentheses:
            player.tell("(%s was found in %s, in your inventory)." %
                        (obj.name, container.title))
        else:
            player.tell("%s was found in %s, in your inventory." %
                        (Lang.capital(obj.name), container.title))
    elif container is player.location:
        if print_parentheses:
            player.tell("(%s was found in your current location)." % obj.name)
        else:
            player.tell("%s was found in your current location." %
                        Lang.capital(obj.name))
    elif container is player:
        if print_parentheses:
            player.tell("(%s was found in your inventory)." % obj.name)
        else:
            player.tell("%s was found in your inventory." %
                        Lang.capital(obj.name))
    else:
        if print_parentheses:
            player.tell("(%s was found in %s)." % (obj.name, container.name))
        else:
            player.tell("%s was found in %s." %
                        (Lang.capital(obj.name), container.name))
    def unlock(self, actor, item=None):

        if not self.locked:
            raise ActionRefused("It is not locked.")

        if item:

            if self.check_key(item):
                key = item
            else:
                raise ActionRefused("You can't use that to unlock it.")

        else:

            key = self.search_key(actor)
            if not key:
                raise ActionRefused(
                    "You don't seem to have the key necessary to unlock it.")

        self.locked = False
        actor.tell("You unlock the %s with %s." %
                   (self.name, Lang.a(key.title)))
        actor.tell_others("{Title} unlocked the %s with %s." %
                          (self.name, Lang.a(key.title)))

        if self.linked_door:
            self.linked_door.door.locked = False
    def lock(self, actor, item=None):

        if self.locked:
            raise ActionRefused("It is already locked.")

        if item:

            if self.check_key(item):
                key = item
            else:
                raise ActionRefused("That can not be used to lock it.")

        else:

            key = self.search_key(actor)
            if not key:
                raise ActionRefused(
                    "You don't seem to have the key necessary to lock it.")

        self.locked = True
        actor.tell("You lock the %s with %s." % (self.name, Lang.a(key.title)))
        actor.tell_others("{Title} locked the %s with %s." %
                          (self.name, Lang.a(key.title)))

        if self.linked_door:
            self.linked_door.door.locked = True
Exemple #4
0
    def give_all(player, items, target_name, target=None):

        if not target:
            target = player.location.search_creature(target_name)
        if not target:
            raise ActionRefused("%s isn't here with you." % target_name)
        if target is player:
            raise ActionRefused("Giving something to yourself doesn't make much sense.")

        # Actually try to give the items...
        items = list(items)
        refused = []
        for item in items:
            try:
                item.move(target, player)
            except ActionRefused as x:
                refused.append((item, str(x)))

        # Let the player know why giving a particular item failed
        for item, message in refused:
            player.tell(message)
            items.remove(item)

        if items:
            items_str = Lang.join(Lang.a(item.title) for item in items)
            player_str = Lang.capital(player.title)
            room_msg = "<player>%s</player> gives <item>%s</item> to <creature>%s</creature>." % (player_str, items_str, target.title)
            target_msg = "<player>%s</player> gives you <item>%s</item>." % (player_str, items_str)
            player.location.tell(room_msg, exclude_creature=player, specific_targets=[target], specific_target_msg=target_msg)
            player.tell("You give <creature>%s</creature> <item>%s</item>." % (target.title, items_str))

        else:
            player.tell("You weren't able to give <creature>%s</creature> anything." % target.title)
    def match_previously_parsed(self, player, pronoun):

        # Plural that can match any items or creatures
        if pronoun == "them":

            matches = list(self.previously_parsed.obj_order)

            for obj in matches:

                if not player.search_item(
                        obj.name) and obj not in player.location.creatures:
                    player.tell("(By '%s' I assume you mean %s.)" %
                                (pronoun, obj.title))
                    raise ParseError("%s is no longer nearby." %
                                     Lang.capital(obj.subjective))

            if matches:

                player.tell("(By '%s' I assume you mean %s.)" %
                            (pronoun, Lang.join(who.title for who in matches)))
                return [(who, who.name) for who in matches]

            else:

                raise ParseError("It is not clear to whom you are referring.")

        for obj in self.previously_parsed.obj_order:

            # Are we dealing with an exit?
            if pronoun == "it":

                for direction, exit in player.location.exits.items():

                    if exit is obj:
                        player.tell("(By '%s' I assume you mean '%s'.)" %
                                    (pronoun, direction))
                        return [(obj, direction)]

            # If not, are we dealing with an item or creature?
            if pronoun == obj.objective:

                if player.search_item(
                        obj.name) or obj in player.location.creatures:
                    player.tell("(By '%s' I assume you mean %s.)" %
                                (pronoun, obj.title))
                    return [(obj, obj.name)]

                player.tell("(By '%s' I assume you mean %s.)" %
                            (pronoun, obj.title))

                raise ParseError("%s is no longer nearby." %
                                 Lang.capital(obj.subjective))

        raise ParseError("It is not clear who you're referring to.")
    def move(self,
             target,
             actor=None,
             silent=False,
             is_player=False,
             verb="move"):

        actor = actor or self
        original_location = None

        if self.location:

            original_location = self.location
            self.location.remove(self, actor)

            # If the transaction fails roll it back
            try:
                target.insert(self, actor)
            except:
                original_location.insert(self, actor)
                raise

            # Allow for the scneario where a creature silently disappears.
            if not silent:
                original_location.tell("%s leaves." % Lang.capital(self.title),
                                       exclude_creature=self)

            if is_player:
                ObjectBase.pending_actions.send(
                    lambda who=self, where=target: original_location.
                    notify_player_left(who, where))
            else:
                ObjectBase.pending_actions.send(
                    lambda who=self, where=target: original_location.
                    notify_npc_left(who, where))

        else:

            target.insert(self, actor)

        if not silent:
            target.tell("%s arrives." % Lang.capital(self.title),
                        exclude_creature=self)

        # queue event
        if is_player:
            ObjectBase.pending_actions.send(
                lambda who=self, where=original_location: target.
                notify_player_arrived(who, where))
        else:
            ObjectBase.pending_actions.send(
                lambda who=self, where=original_location: target.
                notify_npc_arrived(who, where))
Exemple #7
0
    def func(player, parsed, ctx):

        if len(parsed.obj_order) != 2:
            raise ParseError("What would you like to show and to whom?")

        shown = parsed.obj_order[0]
        if shown not in player:
            raise ActionRefused("You do not have <item>%s</item> to show." % Lang.a(shown.title))

        target = parsed.obj_order[1]
        player.tell("You reveal the <item>%s</item> to <creature>%s</creature>." % (shown.title, target.title))
        room_msg = "%s shows something to %s." % (Lang.capital(player.title), target.title)
        target_msg = "%s reveals the %s to you." % (Lang.capital(player.title), Lang.a(shown.title))
        player.location.tell(room_msg, exclude_creature=player, specific_target_msg=target_msg, specific_targets=[target])
    def sys_clone(self, actor):

        duplicate = ObjectBase.clone(self)
        actor.tell("Creature cloned to " + repr(duplicate))
        actor.location.insert(duplicate, actor)
        actor.location.tell("%s appears." % Lang.capital(duplicate.title))
        return duplicate
    def insert(self, item, actor):

        if actor is self or actor is not None and actor.isSysOp:
            super(NPC, self).insert(item, self)
        else:
            raise ActionRefused("%s does not accept %s." %
                                (Lang.capital(self.title), item.title))
    def func(player, parsed, ctx):

        if not parsed.unparsed:
            raise ParseError("What feeling are you trying to express?")

        message = Lang.capital(player.title) + " " + parsed.unparsed
        player.tell("%s" % message)
        player.tell_others(message)
    def func(player, parsed, ctx):

        if len(parsed.args) not in (1, 2) or parsed.unrecognized:
            raise ParseError("What are you trying to %s?" %
                             Lang.capital(parsed.verb))

        if parsed.obj_order:
            if isinstance(parsed.obj_order[0], Creature):
                raise ActionRefused(
                    "You can't do that to other living creatures.")

        obj_name = parsed.args[0]

        # Is the player using something to try to manipulate the object?
        with_item_name = None
        with_item = None
        if len(parsed.args) == 2:
            with_item_name = parsed.args[1]

        what = player.search_item(obj_name,
                                  include_inventory=True,
                                  include_location=True,
                                  include_containers=False)
        # Are we dealing with an exit?
        if not what:
            if obj_name in player.location.exits:
                what = player.location.exits[obj_name]

        # Are we dealing with an item?
        if what:
            # If so, are they using an item to accomplish the manipulation?
            if with_item_name:
                with_item = player.search_item(with_item_name,
                                               include_inventory=True,
                                               include_location=False,
                                               include_containers=False)
                if not with_item:
                    raise ActionRefused(
                        "You don't seem to have <item>%s</item>." %
                        Lang.a(with_item_name))

            getattr(what, parsed.verb)(player, with_item)

        else:
            raise ActionRefused("You don't see that here.")
    def show_inventory(self, actor, ctx):

        name = Lang.capital(self.title)

        if self.inventory:
            actor.tell(name, "is carrying the following items:")
            for item in self.inventory:
                actor.tell("  " + item.title)
        else:
            actor.tell(name, "does not appear to have anything on them.")
Exemple #13
0
    def func(player, parsed, ctx):

        if not parsed.args:
            raise ParseError(
                "What would you like to drop? You can also 'drop all' or 'drop everything'."
            )

        def drop(items, container):

            items = list(items)
            refused = []
            for item in items:
                try:
                    item.move(player.location, player, verb="drop")
                    if container is not player and container in player:
                        Drop.notify_item_removal(player, item, container)
                except ActionRefused as x:
                    refused.append((item, str(x)))

            for item, message in refused:
                items.remove(item)
                player.tell(message)

            if items:
                strItems = Lang.join(Lang.a(item.title) for item in items)
                player.tell("You discard <item>%s</item>." % strItems)
                player.tell_others("{Title} drops %s." % strItems)
            else:
                player.tell("Nothing was dropped.")

        arg = parsed.args[0]
        # drop all items?
        if arg == "all" or arg == "everything":
            drop(player.inventory, player)
        else:
            # drop a single item from inventory
            if parsed.obj_order:
                item = parsed.obj_order[0]
                if item in player:
                    drop([item], player)
                else:
                    raise ActionRefused("You can't seem to drop that!")
            # drop a container from inventory
            else:
                item, container = player.locate_item(arg,
                                                     include_location=False)
                if item:
                    if container is not player:
                        Actions.print_object_location(player, item, container)
                    drop([item], container)
                else:
                    raise ActionRefused("You don't have <item>%s</item>." %
                                        Lang.a(arg))
Exemple #14
0
    def take_all(player, items, container, where_str=None):

        # No items were specified
        if not items:
            return 0

        # Is player taking something from a container?
        if where_str:
            player_msg = "You take <item>{items}</item> from the <item>%s</item>" % where_str
            room_msg = "<player>{{Title}}</player> takes <item>{items}</item> from the <item>%s</item>" % where_str

        # If not, they must be taking it from the room
        else:
            player_msg = "You take <item>{items}</item>"
            room_msg = "<player>{{Title}}</player> takes <item>{items}</item>"

        items = list(items)
        refused = []
        # Try to move items one by one. If there are special rules against taking them the item should
        # raise an ActionRefused exception.
        for item in items:
            try:
                item.move(player, player, verb="take")
            except ActionRefused as x:
                refused.append((item, str(x)))

        # Tell player if any items refused to budge
        for item, message in refused:
            player.tell(message)
            items.remove(item)

        # Tell player about any items that were moved into their inventory
        # and tell nearby players and NPCs abou it too!
        if items:
            items_str = Lang.join(Lang.a(item.title) for item in items)
            player.tell(player_msg.format(items=items_str))
            player.tell_others(room_msg.format(items=items_str))
            return len(items)
        else:
            return 0
    def print_object_location(player, obj, container, print_parentheses=True):

        if not container:

            if print_parentheses:
                player.tell("(I am not sure where %s is)" % obj.name)
            else:
                player.tell("I am not sure where %s is." % obj.name)
            return

        if container in player:

            if print_parentheses:
                player.tell("(You are carrying %s.)" % obj.name)
            else:
                player.tell("You are carrying %s." % Lang.capital(obj.name))

        elif container is player.location:

            if print_parentheses:
                player.tell("(%s is here with you.)" % obj.name)
            else:
                player.tell("%s is here with you." % Lang.capital(obj.name))

        elif container is player:

            if print_parentheses:
                player.tell("(You are carrying %s)" % obj.name)
            else:
                player.tell("You are carrying %s" % Lang.capital(obj.name))

        else:

            if print_parentheses:
                player.tell("(%s was located in %s)." %
                            (obj.name, container.name))
            else:
                player.tell("%s was located in %s." %
                            (Lang.capital(obj.name), container.name))
Exemple #16
0
        def drop(items, container):

            items = list(items)
            refused = []
            for item in items:
                try:
                    item.move(player.location, player, verb="drop")
                    if container is not player and container in player:
                        Drop.notify_item_removal(player, item, container)
                except ActionRefused as x:
                    refused.append((item, str(x)))

            for item, message in refused:
                items.remove(item)
                player.tell(message)

            if items:
                strItems = Lang.join(Lang.a(item.title) for item in items)
                player.tell("You discard <item>%s</item>." % strItems)
                player.tell_others("{Title} drops %s." % strItems)
            else:
                player.tell("Nothing was dropped.")
Exemple #17
0
    def func(player, parsed, ctx):

        # Player wants to examine themselves apparently
        if parsed.args == ["am", "i"]:
            raise RetryParse("examine myself")

        if parsed.args:
            Actions.parse_is_are(parsed.args)
            name = parsed.args[0].rstrip("?")

            # Perform a global search and work from there
            otherplayer = ctx.engine.search_player(name)

            found = False
            if otherplayer:
                found = True

                # Looks like we found them
                player.tell("<player>%s</player> is active and currently at '<location>%s</location>'." % (
                    Lang.capital(otherplayer.title), otherplayer.location.name))

            # Let's see if we can get any additional information about them...
            try:
                Examine.func(player, parsed, ctx)
            except ActionRefused:
                pass

            if not found:
                player.tell("That player does not appear to be online.")

        # The player didn't specify a particular player so list them all
        else:
            player.tell("All players currently in the game:")
            player.tell("\n")
            for conn in ctx.engine.all_players.values():
                other = conn.player
                player.tell("<player>%s</player> (%s) is currently at <location>%s</location>" % (
                    Lang.capital(other.name), other.title, other.location.name))
    def func(player, parsed, ctx):

        # Poor man's autocomplete :)
        if parsed.verb == "manip":
            parsed.verb = "manipulate"

        if len(parsed.obj_order) == 1:
            what = parsed.obj_order[0]
            try:
                what.manipulate(parsed.verb, player)
                return
            except ActionRefused:
                raise

        raise ParseError("What would you like to %s?" % Lang.capital(parsed.verb))
Exemple #19
0
    def func(player, parsed, ctx):

        if len(parsed.obj_order) != 1:
            raise ParseError(
                "Who would you like to show affection or kindness to?")

        if len(parsed.obj_order) == 1:

            target = parsed.obj_order[0]
            if isinstance(target, Creature):
                player.tell("You %s <creature>%s</creature>." %
                            (parsed.verb, target.title))
                room_msg = "%s %ss %s." % (Lang.capital(
                    player.title), parsed.verb, target.title)
                target_msg = "%s %ss you." % (Lang.capital(
                    player.title), parsed.verb)
                player.location.tell(room_msg,
                                     exclude_creature=player,
                                     specific_target_msg=target_msg,
                                     specific_targets=[target])
            else:
                player.tell(
                    "Inanimate objects don't respond to that but it's very sweet of you."
                )
    def __init__(self, name, gender, description=None, short_description=None):

        title = Lang.capital(name)

        super(Player, self).__init__(name, gender, title, description, short_description)

        self.turns = 0

        # 0 = off
        # 1 = short descriptions for previously visited locations
        # 2 = short descriptions. for all locations
        self.brief = 0

        self.known_locations = set()
        self.game_complete = False
        self.last_input_time = time.time()
        self.init_nonserializables()
Exemple #21
0
    def func(player, parsed, ctx):

            if len(parsed.args) < 2:
                raise ParseError("You must specify what to give and whom to give it to.")

            if parsed.unrecognized or player.inventory_size == 0:
                raise ParseError("You don't have %s to give." % Lang.join(parsed.unrecognized))

            # Does the player want to give everything they have?
            if "all" in parsed.args:

                if len(parsed.args) != 2:
                    raise ParseError("You must specify who you want to give the items to.")

                what = player.inventory

                if parsed.args[0] == "all":
                    Give.give_all(player, what, parsed.args[1])
                    return
                else:
                    Give.give_all(player, what, parsed.args[0])
                    return

            # Player wants to give just a single item
            if len([who for who in parsed.obj_order if isinstance(who, Creature)]) > 1:
                # if there's more than one creature, it's not clear who to give stuff to
                raise ActionRefused("It's not clear who you want to give things to.")

            # if the first parsed word is a creature assume the syntax "give creature [the] thing(s)"
            if isinstance(parsed.obj_order[0], Creature):
                what = parsed.obj_order[1:]
                Give.give_all(player, what, None, target=parsed.obj_order[0])
                return

            # if the last parsed word is a creature assume the syntax "give thing(s) [to] creature"
            elif isinstance(parsed.obj_order[-1], Creature):
                what = parsed.obj_order[:-1]
                Give.give_all(player, what, None, target=parsed.obj_order[-1])
                return

            else:
                raise ActionRefused("It's not clear to who you want to give the item.")
def duration_display(duration):
    secs = duration.total_seconds()
    if secs == 0:
        return "no time at all"
    hours, secs = divmod(secs, 3600)
    minutes, secs = divmod(secs, 60)
    result = []
    if hours == 1:
        result.append("1 hour")
    elif hours > 1:
        result.append("%d hours" % hours)
    if minutes == 1:
        result.append("1 minute")
    elif minutes > 1:
        result.append("%d minutes" % minutes)
    if secs == 1:
        result.append("1 second")
    elif secs > 1:
        result.append("%d seconds" % secs)
    return Lang.join(result)
Exemple #23
0
    def func(player, parsed, ctx):

        if len(parsed.args) < 2:
            raise ParseError(
                "You need to tell me what to put and where you'd like to put it."
            )

        # If player specified all they want to put their entire inventory into the container
        if parsed.args[0] == "all":

            # Does the player have anything in their inventory
            if player.inventory_size == 0:
                raise ActionRefused("You don't seem to be carrying anything.")

            if len(parsed.args) != 2:
                raise ParseError(
                    "You need to tell me what to put and where you'd like to put it."
                )

            what = list(player.inventory)
            where = parsed.obj_order[
                -1]  # The last item represents the "where"

        elif parsed.unrecognized:
            raise ActionRefused("I don't see %s here." %
                                Lang.join(parsed.unrecognized))

        else:
            what = parsed.obj_order[:-1]
            where = parsed.obj_order[-1]

        if isinstance(where, Creature):
            raise ActionRefused(
                "You can't do that but you might be able to give it to them..."
            )

        inventory_items = []
        refused = []

        word_before = parsed.obj_info[where].previous_word or "in"
        if word_before != "in" and word_before != "into":
            raise ActionRefused(
                "You can only put an item 'in' or 'into' a container of some sort."
            )

        for item in what:
            if item is where:
                player.tell("You can't put something inside of itself.")
                continue

            try:
                # Are they using an item they are already carrying?
                if item in player:
                    item.move(where, player)
                    inventory_items.append(item)

                # If the item is in the room then we'll take it first and then put it into the container
                # TODO: We need to handle in a linguistic stylish way the situation where one part of this two-step operation fails
                elif item in player.location:
                    item.move(player, player)
                    item.move(where, player)
                    player.tell("You take %s and put it in the %s." %
                                (item.title, where.name))
                    player.tell_others(
                        "{Title} takes %s and puts it in the %s." %
                        (item.title, where.name))

            except ActionRefused as x:
                refused.append((item, str(x)))

        # The item refused to move at some point so inform the player
        for item, message in refused:
            player.tell(message)

        if inventory_items:
            items_msg = Lang.join(
                Lang.a(item.title) for item in inventory_items)
            player.tell_others("{Title} puts %s in the %s." %
                               (items_msg, where.name))
            player.tell(
                "You put <item>{items}</item> in the <item>{where}</item>.".
                format(items=items_msg, where=where.name))
Exemple #24
0
    def func(player, parsed, ctx):

        # Did the player specify something to be taken?
        if len(parsed.args) == 0:
            raise ParseError("What would you like to take?")

        # Player is taking a single item
        if len(parsed.args) == 1:
            obj_names = parsed.args
            where = None

        # Player wants to try something more complicated...
        else:

            if parsed.obj_order:

                last_obj = parsed.obj_order[-1]

                # Player is trying to take one or more (comma separated) items from something or someone
                if parsed.obj_info[last_obj].previous_word == "from":
                    obj_names = parsed.args[:-1]
                    where = last_obj

                # Player is trying to take one or more (comma separated) items
                else:
                    # take x[,y and z]
                    obj_names = parsed.args
                    where = None

            else:
                # take x[,y and z] - unrecognised names
                obj_names = parsed.args
                where = None

        # Basic sanity check
        if where is player:
            raise ActionRefused("You can't take items from yourself.")

        # Notify others in the room that something is creature taken
        if isinstance(where, Creature):
            player.tell_others("{Title} takes something from %s." %
                               where.title)

        # Player wants to take all teh things
        if obj_names == ["all"]:

            # Are we taking items from a container?
            if where:

                # Is the container on the player's person or in the room with the player?
                if where in player or where in player.location:

                    # Is there anything in it?
                    if where.inventory_size > 0:
                        Get.take_all(player, where.inventory, where,
                                     where.title)
                        return
                    else:
                        raise ActionRefused("It appears to be empty.")

                raise ActionRefused("What are you trying to take?")

            # We're taking items from the room the player is in
            else:

                # Anything here to take?
                if not player.location.items:
                    raise ActionRefused(
                        "There appears to be nothing here you can carry.")
                # Yes, so dump everything into the player's inventory.
                else:
                    Get.take_all(player, player.location.items,
                                 player.location)
                    return

        # Player is trying to take one or more specific items
        else:

            # Are we taking items from a container?
            if where:

                # Yes, is the container on the player's person or in the room?
                if where in player or where in player.location:

                    # Take each item from the specified container
                    items_by_name = {
                        item.name: item
                        for item in where.inventory
                    }
                    items_to_take = []

                    for name in obj_names:

                        # If it's there let's take it...
                        if name in items_by_name:
                            items_to_take.append(items_by_name[name])
                        # ...otherwise tell the player their action is misguided.
                        else:
                            player.tell("There's no %s in there." % name)

                    Get.take_all(player, items_to_take, where, where.title)
                    return
            else:

                # Looks like the player is trying to take items from the room itself
                if parsed.unrecognized:
                    player.tell("You don't see %s here." %
                                Lang.join(parsed.unrecognized))

                creatures = [
                    item for item in parsed.obj_order
                    if item in player.location.creatures
                ]
                for creature in creatures:
                    player.tell("You can not pick up other living creatures.")

                if not player.location.items:
                    raise ActionRefused(
                        "There appears to be nothing here you can carry.")

                else:

                    items_to_take = []
                    for item in parsed.obj_order:

                        # If item is here let the player take it!
                        if item in player.location.items:
                            items_to_take.append(item)

                        # If the item is an exit let's remind the user it can't be taken
                        elif isinstance(item, Exit):
                            raise ActionRefused(
                                "That is not something you can carry.")

                        elif item not in player.location.creatures:
                            if item in player:
                                player.tell("You already have that item.")
                            else:
                                player.tell(
                                    "There's no <item>%s</item> here." %
                                    item.name)

                    Get.take_all(player, items_to_take, player.location)
                    return
Exemple #25
0
 def sys_clone(self, actor):
     raise ActionRefused(
         Lang.a(self.__class__.__name__) + " can not be cloned")
Exemple #26
0
    def func(player, parsed, ctx):

        # If we're examining a creature let's get some info for it
        creature = None
        if parsed.obj_info and isinstance(parsed.obj_order[0], Creature):
            creature = parsed.obj_order[0]
            name = creature.name

        # If we're not examining a creature we'll get item info
        if not creature:

            # Handle the case where nothing to examine was specified
            if not parsed.args:
                raise ParseError("Who or what would you like to examine?")

            Actions.parse_is_are(parsed.args)
            name = parsed.args[0]
            creature = player.location.search_creature(name)

        # If we're trying to examine a creature we'll figure out
        # which creature we're dealing with
        if creature:

            # Player is trying to examine themselves. Sheesh.
            if creature is player:
                player.tell("You are <creature>%s</creature>." %
                            Lang.capital(creature.title))
                return

            if creature.name.lower() != name.lower() and name.lower(
            ) in creature.aliases:
                player.tell("(By %s you probably meant %s.)" %
                            (name, creature.name))

            # If the creature has a description show the player otherwise we'll just share their title
            if creature.description:
                player.tell(creature.description)
            else:
                player.tell("This is <creature>%s</creature>." %
                            creature.title)

            # If there is extended info about the creature we'll provide that as well
            if name in creature.extra_desc:
                player.tell(creature.extra_desc[name])

            if name in player.location.extra_desc:
                player.tell(player.location.extra_desc[name])

            return

        # Is the player trying to examine an item?
        item, container = player.locate_item(name)
        if item:

            if item.name.lower() != name.lower() and name.lower(
            ) in item.aliases:
                player.tell("Maybe you meant %s?" % item.name)

            # If there is an extended description we'll share that.
            if name in item.extra_desc:
                player.tell(item.extra_desc[name])
            # Otherwise we'll just share what basic info we have
            else:
                if item in player:
                    player.tell("You're carrying <item>%s</item>." %
                                Lang.a(item.title))
                elif container and container in player:
                    Actions.print_object_location(player, item, container)
                else:
                    player.tell("You see <item>%s</item>." %
                                Lang.a(item.title))
                if item.description:
                    player.tell(item.description)

            try:
                inventory = item.inventory
            except ActionRefused:
                pass
            else:
                if inventory:
                    msg = "It contains "
                    for item in inventory:
                        msg += "<item>%s</item>, " % item.title
                    msg = msg[:-2]
                    player.tell(msg)
                else:
                    player.tell("It's empty.")

        # Player is examining an exit?
        elif name in player.location.exits:
            player.tell(
                "<exit>" + player.location.exits[name].description +
                "</exit> represents a way you can travel to a different place."
            )

        # If nothing else we'll do a search for any extended descriptive info associated with
        # locations and items
        else:
            text = player.search_extradesc(name)
            if text:
                player.tell(text)
            else:
                raise ActionRefused("%s doesn't appear to be here." % name)
Exemple #27
0
    def func(player, parsed, ctx):

        if not parsed.args:
            raise ParseError("What are you asking about?")

        if parsed.args[0] == "are" and len(parsed.args) > 2:
            raise ActionRefused(
                "I can only tell you about one thing at a time.")

        if len(parsed.args) >= 2 and parsed.args[0] in ("is", "are"):
            del parsed.args[0]

        name = parsed.args[0].rstrip("?")

        if not name:
            raise ActionRefused("What are you asking about?")

        found = False

        # Is the player asking about an action?
        all_verbs = ctx.engine.current_verbs(player)
        if name in all_verbs:
            found = True
            doc = all_verbs[name].strip()

            if doc:
                player.tell(doc)
            else:
                player.tell(
                    "That is an action I understand but I can't tell you much more about it."
                )

        # Is the player asking about a particular exit from their current location?
        if name in player.location.exits:
            found = True
            player.tell(
                "That appears to be a way to leave your current location. Perhaps you should examine it?"
            )

        # Is the player asking about a creature in the room with them?
        creature = player.location.search_creature(name)
        if creature and creature.name.lower() != name.lower() and name.lower(
        ) in creature.aliases:
            player.tell("(By %s you probably meant %s.)" %
                        (name, creature.name))

        if creature:
            found = True

            # Is the player referring to themselves here?
            if creature is player:
                player.tell("Well, that's you isn't it?")

            # Or are they referring to someone else in the room?
            else:
                title = Lang.capital(creature.title)
                gender = Lang.GENDERS[creature.gender]
                subj = Lang.capital(creature.subjective)

                if type(creature) is type(player):
                    player.tell(
                        "Is another visitor like yourself. %s's here in the room with you."
                        % subj)
                else:
                    player.tell(
                        "<creature>%s</creature> is a %s character in our story."
                        % (title, gender))

        # Is the player referring to an item?
        item, container = player.locate_item(name,
                                             include_inventory=True,
                                             include_location=True,
                                             include_containers=True)
        if item:
            found = True
            if item.name.lower() != name.lower() and name.lower(
            ) in item.aliases:
                player.tell("Maybe you meant %s.)" % item.name)
            player.tell(
                "That's a nearby item you could try to examine for more information."
            )

        if name in ("that", "this", "they", "them", "it"):
            raise ActionRefused("Sorry, you need to be more specific.")

        # Shrug our virtual shoulders...
        if not found:
            player.tell(
                "Sorry, I can't figure out what you mean or there is no additional information I can provide."
            )
Exemple #28
0
 def sys_destroy(self, actor, ctx):
     raise ActionRefused(
         Lang.a(self.__class__.__name__) + " can not be destroyed")
    def tell_others(self, *messages):

        formats = {"title": self.title, "Title": Lang.capital(self.title)}
        for msg in messages:
            msg = msg.format(**formats)
            self.location.tell(msg, exclude_creature=self)
 def manipulate(self, verb, actor):
     actor.tell("%s the %s doesn't seem to have any affect." %
                (Lang.capital(Lang.progressive_tense(verb)), self.title))