Add the /object switch to examine to allow one to search for Objects when OOC. Also updated player.search() to account for this functionality.

This commit is contained in:
Griatch 2016-08-31 20:27:31 +02:00
parent e66020f369
commit 6e89c708d2
2 changed files with 19 additions and 8 deletions

View file

@ -1819,6 +1819,7 @@ class CmdExamine(ObjManipCommand):
Switch: Switch:
player - examine a Player (same as adding *) player - examine a Player (same as adding *)
object - examine an Object (useful when OOC)
The examine command shows detailed game info about an The examine command shows detailed game info about an
object and optionally a specific attribute on it. object and optionally a specific attribute on it.
@ -2038,14 +2039,14 @@ class CmdExamine(ObjManipCommand):
obj_name = objdef['name'] obj_name = objdef['name']
obj_attrs = objdef['attrs'] obj_attrs = objdef['attrs']
self.player_mode = utils.inherits_from(caller, "evennia.players.players.Player") or \ self.player_mode = utils.inherits_from(caller, "evennia.players.players.DefaultPlayer") or \
"player" in self.switches or obj_name.startswith('*') "player" in self.switches or obj_name.startswith('*')
if self.player_mode: if self.player_mode:
try: try:
obj = caller.search_player(obj_name.lstrip('*')) obj = caller.search_player(obj_name.lstrip('*'))
except AttributeError: except AttributeError:
# this means we are calling examine from a player object # this means we are calling examine from a player object
obj = caller.search(obj_name.lstrip('*')) obj = caller.search(obj_name.lstrip('*'), search_object = 'object' in self.switches)
else: else:
obj = caller.search(obj_name) obj = caller.search(obj_name)
if not obj: if not obj:

View file

@ -17,10 +17,11 @@ from django.utils import timezone
from evennia.typeclasses.models import TypeclassBase from evennia.typeclasses.models import TypeclassBase
from evennia.players.manager import PlayerManager from evennia.players.manager import PlayerManager
from evennia.players.models import PlayerDB from evennia.players.models import PlayerDB
from evennia.objects.models import ObjectDB
from evennia.comms.models import ChannelDB from evennia.comms.models import ChannelDB
from evennia.commands import cmdhandler from evennia.commands import cmdhandler
from evennia.utils import logger from evennia.utils import logger
from evennia.utils.utils import (lazy_property, to_str, from evennia.utils.utils import (lazy_property,
make_iter, to_unicode, is_iter, make_iter, to_unicode, is_iter,
variable_from_module) variable_from_module)
from evennia.typeclasses.attributes import NickHandler from evennia.typeclasses.attributes import NickHandler
@ -454,11 +455,11 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
return cmdhandler.cmdhandler(self, raw_string, return cmdhandler.cmdhandler(self, raw_string,
callertype="player", session=session, **kwargs) callertype="player", session=session, **kwargs)
def search(self, searchdata, return_puppet=False, def search(self, searchdata, return_puppet=False, search_object=False,
nofound_string=None, multimatch_string=None, **kwargs): nofound_string=None, multimatch_string=None, **kwargs):
""" """
This is similar to `DefaultObject.search` but will search for This is similar to `DefaultObject.search` but defaults to searching
Players only. for Players only.
Args: Args:
searchdata (str or int): Search criterion, the Player's searchdata (str or int): Search criterion, the Player's
@ -466,12 +467,18 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
return_puppet (bool, optional): Instructs the method to return_puppet (bool, optional): Instructs the method to
return matches as the object the Player controls rather return matches as the object the Player controls rather
than the Player itself (or None) if nothing is puppeted). than the Player itself (or None) if nothing is puppeted).
search_object (bool, optional): Search for Objects instead of
Players. This is used by e.g. the @examine command when
wanting to examine Objects while OOC.
nofound_string (str, optional): A one-time error message nofound_string (str, optional): A one-time error message
to echo if `searchdata` leads to no matches. If not given, to echo if `searchdata` leads to no matches. If not given,
will fall back to the default handler. will fall back to the default handler.
multimatch_string (str, optional): A one-time error multimatch_string (str, optional): A one-time error
message to echo if `searchdata` leads to multiple matches. message to echo if `searchdata` leads to multiple matches.
If not given, will fall back to the default handler. If not given, will fall back to the default handler.
Return:
match (Player, Object or None): A single Player or Object match.
Notes: Notes:
Extra keywords are ignored, but are allowed in call in Extra keywords are ignored, but are allowed in call in
order to make API more consistent with order to make API more consistent with
@ -483,6 +490,9 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
# handle wrapping of common terms # handle wrapping of common terms
if searchdata.lower() in ("me", "*me", "self", "*self",): if searchdata.lower() in ("me", "*me", "self", "*self",):
return self return self
if search_object:
matches = ObjectDB.objects.object_search(searchdata)
else:
matches = self.__class__.objects.player_search(searchdata) matches = self.__class__.objects.player_search(searchdata)
matches = _AT_SEARCH_RESULT(matches, self, query=searchdata, matches = _AT_SEARCH_RESULT(matches, self, query=searchdata,
nofound_string=nofound_string, nofound_string=nofound_string,