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 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))
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 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 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 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.")
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))
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))
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()
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 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)
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." )
def look(self, exclude_creature=None, short=False): paragraphs = ["<location>[" + self.name + "]</location>"] # Construct the short version of a location description. if short: if self.exits and context.config.show_exits_in_look: paragraphs.append("<exit>Exits</exit>: " + ", ".join(sorted(set(self.exits.keys())))) if self.items: item_names = sorted(item.name for item in self.items) paragraphs.append("<item>You see</item>: " + Lang.join(item_names)) if self.creatures: creature_names = sorted(creature.name for creature in self.creatures if creature != exclude_creature) if creature_names: paragraphs.append("<creature>Present</creature>: " + Lang.join(creature_names)) return paragraphs # # Construct the long version of a location description. # if self.description: paragraphs.append(self.description) if self.exits and context.config.show_exits_in_look: # Keep track of exits we've already described exits_seen = set() exit_paragraph = [] for exit_name in sorted(self.exits): exit = self.exits[exit_name] if exit not in exits_seen: exits_seen.add(exit) exit_paragraph.append(exit.short_description) paragraphs.append(" ".join(exit_paragraph)) items_and_creatures = [] # We'll preferentially use item short descriptions if provided and resort to the item's title if necessary items_with_short_descr = [item for item in self.items if item.short_description] items_without_short_descr = [item for item in self.items if not item.short_description] uniq_descriptions = set() # If there's a short description for an item use it preferentially if items_with_short_descr: for item in items_with_short_descr: uniq_descriptions.add(item.short_description) # Add unique item description to our running list of things to describe items_and_creatures.extend(uniq_descriptions) # If there's no short description for an item we'll just use the item's title if items_without_short_descr: titles = sorted([Lang.a(item.title) for item in items_without_short_descr]) items_and_creatures.append("You see " + Lang.join(titles) + ".") # We'll preferentially use creature short descriptions if provided and resort to the title if necessary creatures_with_short_descr = [creature for creature in self.creatures if creature != exclude_creature and creature.short_description] creatures_without_short_descr = [creature for creature in self.creatures if creature != exclude_creature and not creature.short_description] # If there's a short descriptions for a creature use it preferentially if creatures_without_short_descr: titles = sorted(creature.title for creature in creatures_without_short_descr) if titles: titles_str = Lang.join(titles) if len(titles) > 1: titles_str += " are here." else: titles_str += " is here." items_and_creatures.append(Lang.capital(titles_str)) uniq_descriptions = set() # If there's no short description for a creature we'll just use the item's title if creatures_with_short_descr: for creature in creatures_with_short_descr: uniq_descriptions.add(creature.short_description) # Add unique creature descriptions to our running list of things to describe items_and_creatures.extend(uniq_descriptions) if items_and_creatures: paragraphs.append(" ".join(items_and_creatures)) return paragraphs
def parse(self, player, action, external_verbs=frozenset()): # Does the verb expect a message to follow? message_verb = False # Are we dealing with a custom verb (action)? external_verb = False message = [] arg_words = [] unrecognized_words = [] obj_info = defaultdict(ObjectInfo) obj_order = [] obj_sequence = 0 unparsed = action # A quoted substring will be considered a message m = Parser._quoted_message_regex.search(action) if m: message = [(m.group("msg1") or m.group("msg2")).strip()] action = action[:m.start()] + action[m.end():] # Could we determine an action? if not action: raise ParseError("What?") # Ignore skip words words = action.split() if words and words[0] in Parser._skip_words: skipword = words.pop(0) unparsed = unparsed[len(skipword):].lstrip() # Anything here we understand? if not words: raise ParseError("What?") verb = None # Give custom verbs (actions) priority if words[0] in external_verbs: verb = words.pop(0) external_verb = True # Let's deal with exits? elif player.location.exits: # Look for a movement verb move_action = None if words[0] in Parser.MOVEMENT_VERBS: move_action = words.pop(0) # If we found a movement verb but no indication of where the player would like to move # we'll remind them to supply this bit of information. if not words: raise ParseError("%s where?" % Lang.capital(move_action)) exit, exit_name, wordcount = Parser.check_name_with_spaces( words, 0, player.location.exits, {}) # Has the user mentioned an exit? if exit: # If we just have the name of the exit we need to ask the player what they want to do with/about it. if wordcount != len(words): raise ParseError("What about it?") unparsed = unparsed[len(exit_name):].lstrip() raise NotDefaultVerb( ParseResult(verb=exit_name, obj_order=[exit], unparsed=unparsed)) elif move_action: raise ParseError("You can not %s there." % move_action) else: # can't determine verb at this point, just continue with verb=None pass else: # can't determine verb at this point, just continue with verb=None pass if verb: unparsed = unparsed[len(verb):].lstrip() include_flag = True collect_message = False # Contains all creatures in the location including name and aliases all_creatures = {} # Contains all items in the location and the player's inventory including name and aliases all_items = {} # Gather all creatures in the location including the players for creature in player.location.creatures: all_creatures[creature.name] = creature for alias in creature.aliases: all_creatures[alias] = creature # Gather all items in the location for item in player.location.items: all_items[item.name] = item for alias in item.aliases: all_items[alias] = item # Gather all items in the player's inventory for item in player.inventory: all_items[item.name] = item for alias in item.aliases: all_items[alias] = item previous_word = None words_enumerator = enumerate(words) for index, word in words_enumerator: if collect_message: message.append(word) arg_words.append(word) previous_word = word continue if not message_verb and not collect_message: word = word.rstrip(",") # Handle special case where player is referring to something using a pronoun. # This will work to match a previously parsed word used by the player if word in ("them", "him", "her", "it"): # Try to associated the pronoun to a previously parsed item or creature if self.previously_parsed: obj_list = self.match_previously_parsed(player, word) if obj_list: for obj, name in obj_list: if include_flag: obj_info[obj].sequence = obj_sequence obj_info[obj].previous_word = previous_word obj_sequence += 1 obj_order.append(obj) else: del obj_info[obj] obj_order.remove(obj) # If we found a match substitute the name for the pronoun in the list of arguments arg_words.append(name) previous_word = None continue # Let the player know we can't figure out what the pronoun is referring to raise ParseError("I am not certain to whom you are referring.") # Is the player referring to themselves? if word in ("me", "myself", "self"): if include_flag: obj_info[player].sequence = obj_sequence obj_info[player].previous_word = previous_word obj_sequence += 1 obj_order.append(player) elif player in obj_info: del obj_info[player] obj_order.remove(player) arg_words.append(word) previous_word = None continue # Is the player referring to every creature in the room? if word in ("everyone", "everybody", "all"): if include_flag: if not all_creatures: raise ParseError( "There doesn't appear to be anyone here.") # Include every visible creature and exclude the player for creature in player.location.creatures: if creature is not player: obj_info[creature].sequence = obj_sequence obj_info[creature].previous_word = previous_word obj_sequence += 1 obj_order.append(creature) else: obj_info = {} obj_order = [] obj_sequence = 0 arg_words.append(word) previous_word = None continue # If the player is trying to refer to all items we tell them we can't handle that if word == "everything": raise ParseError( "You can not do something to everything around you. Please be more specific." ) # Player wants to exclude an item or creature if word in ("except", "but"): include_flag = not include_flag arg_words.append(word) continue # Player has referred to a creature? if word in all_creatures: creature = all_creatures[word] if include_flag: obj_info[creature].sequence = obj_sequence obj_info[creature].previous_word = previous_word obj_sequence += 1 obj_order.append(creature) elif creature in obj_info: del obj_info[creature] obj_order.remove(creature) arg_words.append(word) previous_word = None continue # Player has referred to an item? if word in all_items: item = all_items[word] if include_flag: obj_info[item].sequence = obj_sequence obj_info[item].previous_word = previous_word obj_sequence += 1 obj_order.append(item) elif item in obj_info: del obj_info[item] obj_order.remove(item) arg_words.append(word) previous_word = None continue # Just in case the player is not in a location. Not sure how this could happen. if player.location: exit, exit_name, wordcount = Parser.check_name_with_spaces( words, index, player.location.exits, {}) # If exits were mentioned let's deal with that if exit: obj_info[exit].sequence = obj_sequence obj_info[exit].previous_word = previous_word previous_word = None obj_sequence += 1 obj_order.append(exit) arg_words.append(exit_name) while wordcount > 1: Parser.next_iter(words_enumerator) wordcount -= 1 continue item, full_name, wordcount = Parser.check_name_with_spaces( words, index, all_creatures, all_items) # If an item was mentioned then let's deal with that if item: while wordcount > 1: Parser.next_iter(words_enumerator) wordcount -= 1 if include_flag: obj_info[item].sequence = obj_sequence obj_info[item].previous_word = previous_word obj_sequence += 1 obj_order.append(item) elif item in obj_info: del obj_info[item] obj_order.remove(item) arg_words.append(full_name) previous_word = None continue # Are we dealing with a message verb? if message_verb and not message: collect_message = True message.append(word) arg_words.append(word) continue # If we are dealing with a word not in skip words list then let's deal with that. if word not in Parser._skip_words: if not obj_order: for name in all_creatures: if name.startswith(word): raise ParseError("Did you mean %s?" % name) for name in all_items: if name.startswith(word): raise ParseError("Did you mean %s?" % name) # If we're not dealing with an external or internal verb we give up if not external_verb: # We just have no idea what they hell they're talking about and can't even provide hints. if not verb: raise UnknownVerbException(word, words) # If we are dealing with an external verb we'll pass off interpretation to the action modules if external_verb: arg_words.append(word) unrecognized_words.append(word) # Otherwise we're again at the end of our rope else: message = "I am not sure what you mean by '%s'." % word if word[0].isupper(): message += " Please always just user lowercase (e.g., '%s')." % word.lower( ) raise ParseError(message) previous_word = word message = " ".join(message) # There appears to be no verb but it's possible the user is referring to an item or creature. # In that case we can check the object or creature to determine a default verb to apply. if not verb: if len(obj_order) == 1: try: verb = obj_order[0].default_verb # Our last resort is to use the "examine" action to provide detailed information on the object except AttributeError: verb = "examine" else: raise UnknownVerbException(words[0], words) # We're done parsing. Let's pass a parse result object back to the caller so that the various action # modules have a chance to pick the sentence apart and respond appropriately. return ParseResult(verb, obj_info=obj_info, obj_order=obj_order, message=message, args=arg_words, unrecognized=unrecognized_words, unparsed=unparsed)
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 func(player, parsed, ctx): if not parsed.args: raise ParseError("Who or what are you trying to find?") if len(parsed.args) > 1 or len(parsed.obj_order) > 1: raise ParseError("You can only search for one thing at a time.") name = parsed.args[0] player.tell("You search your surroundings to try to find %s." % name) player.tell_others( "{Title} appears to be looking for something or someone.") if parsed.obj_order: thing = parsed.obj_order[0] if thing is player: player.tell("You are in the <location>%s</location>." % player.location.name) return if thing.name.lower() != name.lower() and name.lower( ) in thing.aliases: player.tell("Maybe you meant %s?" % thing.name) if thing in player.location: if isinstance(thing, Creature): player.tell( "<creature>%s</creature> is right here with you." % Lang.capital(thing.title)) else: Actions.print_object_location(player, thing, player.location, False) elif thing in player: Actions.print_object_location(player, thing, player, False) else: player.tell("You can't seem to find that here.") # The default parser checks inventory and location, but it didn't find anything. # Check inside containers in the player's inventory instead. else: item, container = player.locate_item(name, include_inventory=False, include_location=False, include_containers=True) if item: if item.name.lower() != name.lower() and name.lower( ) in item.aliases: player.tell("Maybe you meant %s?" % item.name) Actions.print_object_location(player, item, container, False) else: otherplayer = ctx.engine.search_player(name) if otherplayer: player.tell( "You look about but don't see <player>%s</player>. Yelling might help if %s is nearby." % (Lang.capital( otherplayer.title), otherplayer.subjective)) else: player.tell("You can't seem to find that here.")
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))