mirror of
https://github.com/evennia/evennia.git
synced 2026-03-19 22:36:31 +01:00
We now have get/drop and a vastly improved object searching function. Some misc. improvements to other utility tfunctions as well.
This commit is contained in:
parent
18994e4ca0
commit
0e1e2ed1b0
4 changed files with 100 additions and 8 deletions
|
|
@ -493,10 +493,14 @@ class Object(models.Model):
|
|||
|
||||
target: (Object) Reference to the object to move to.
|
||||
"""
|
||||
self.get_location().emit_to_contents("%s has left." % (self.get_name(),), exclude=self)
|
||||
if not quiet:
|
||||
self.get_location().emit_to_contents("%s has left." % (self.get_ansiname(),), exclude=self)
|
||||
|
||||
self.location = target
|
||||
self.save()
|
||||
self.get_location().emit_to_contents("%s has arrived." % (self.get_name(),), exclude=self)
|
||||
|
||||
if not quiet:
|
||||
self.get_location().emit_to_contents("%s has arrived." % (self.get_ansiname(),), exclude=self)
|
||||
|
||||
def dbref_match(self, oname):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ def cmd_inventory(cdat):
|
|||
session.msg("You are carrying:")
|
||||
|
||||
for item in pobject.get_contents():
|
||||
session.msg(" %s" % (item,))
|
||||
session.msg(" %s" % (item.get_ansiname(),))
|
||||
|
||||
money = pobject.get_attribute_value("MONEY", default=0)
|
||||
if money > 0:
|
||||
|
|
@ -93,6 +93,84 @@ def cmd_look(cdat):
|
|||
for exit in con_exits:
|
||||
session.msg('%s' %(exit.get_ansiname(),))
|
||||
|
||||
def cmd_get(cdat):
|
||||
"""
|
||||
Get an object and put it in a player's inventory.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
plr_is_staff = pobject.is_staff()
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Get what?")
|
||||
return
|
||||
else:
|
||||
results = functions_db.local_and_global_search(pobject, ' '.join(args), search_contents=False)
|
||||
|
||||
if len(results) > 1:
|
||||
session.msg("More than one match found (please narrow target):")
|
||||
for result in results:
|
||||
session.msg(" %s" % (result.get_ansiname(),))
|
||||
return
|
||||
elif len(results) == 0:
|
||||
session.msg("I don't see that here.")
|
||||
return
|
||||
else:
|
||||
# We've got a victim to get now.
|
||||
target_obj = results[0]
|
||||
|
||||
if pobject == target_obj:
|
||||
session.msg("You can't get yourself.")
|
||||
return
|
||||
|
||||
if not plr_is_staff and (target_obj.is_player() or target_obj.is_exit()):
|
||||
session.msg("You can't get that.")
|
||||
return
|
||||
|
||||
if target_obj.is_room() or target_obj.is_garbage() or target_obj.is_going():
|
||||
session.msg("You can't get that.")
|
||||
return
|
||||
|
||||
target_obj.move_to(pobject, quiet=True)
|
||||
session.msg("You pick up %s." % (target_obj.get_ansiname(),))
|
||||
pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_ansiname(), target_obj.get_ansiname()), exclude=pobject)
|
||||
|
||||
def cmd_drop(cdat):
|
||||
"""
|
||||
Drop an object from a player's inventory into their current location.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
plr_is_staff = pobject.is_staff()
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Drop what?")
|
||||
return
|
||||
else:
|
||||
results = functions_db.local_and_global_search(pobject, ' '.join(args), search_location=False)
|
||||
|
||||
if len(results) > 1:
|
||||
session.msg("More than one match found (please narrow target):")
|
||||
for result in results:
|
||||
session.msg(" %s" % (result.get_ansiname(),))
|
||||
return
|
||||
elif len(results) == 0:
|
||||
session.msg("You don't appear to be carrying that.")
|
||||
return
|
||||
else:
|
||||
# We've got a victim to get now.
|
||||
target_obj = results[0]
|
||||
|
||||
if not pobject == target_obj.get_location():
|
||||
session.msg("You don't appear to be carrying that.")
|
||||
return
|
||||
|
||||
target_obj.move_to(pobject.get_location(), quiet=True)
|
||||
session.msg("You drop %s." % (target_obj.get_ansiname(),))
|
||||
pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_ansiname(), target_obj.get_ansiname()), exclude=pobject)
|
||||
|
||||
def cmd_examine(cdat):
|
||||
"""
|
||||
Detailed object examine command
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -73,20 +73,30 @@ def list_search_object_namestr(searchlist, ostring, dbref_only=False):
|
|||
else:
|
||||
return [prospect for prospect in searchlist if prospect.name_match(ostring)]
|
||||
|
||||
def local_and_global_search(searcher, ostring, local_only=False, dbref_only=False):
|
||||
def local_and_global_search(searcher, ostring, search_contents=True, search_location=True, dbref_only=False):
|
||||
"""
|
||||
Searches an object's location then globally for a dbref or name match.
|
||||
local_only: Only compare the objects in the player's location if True.
|
||||
search_contents: (bool) While true, check the contents of the searcher.
|
||||
search_location: (bool) While true, check the searcher's surroundings.
|
||||
"""
|
||||
search_query = ''.join(ostring)
|
||||
|
||||
if is_dbref(ostring) and not local_only:
|
||||
# This is a global dbref search. Not applicable if we're only searching
|
||||
# searcher's contents/locations, dbref comparisons for location/contents
|
||||
# searches are handled by list_search_object_namestr() below.
|
||||
if is_dbref(ostring) and search_contents and search_location:
|
||||
search_num = search_query[1:]
|
||||
dbref_match = list(Object.objects.filter(id=search_num).exclude(type=6))
|
||||
if len(dbref_match) > 0:
|
||||
return dbref_match
|
||||
|
||||
local_matches = list_search_object_namestr(searcher.get_location().get_contents(), search_query) + list_search_object_namestr(searcher.get_contents(), search_query)
|
||||
|
||||
local_matches = []
|
||||
# Handle our location/contents searches. list_search_object_namestr() does
|
||||
# name and dbref comparisons against search_query.
|
||||
if search_contents:
|
||||
local_matches += list_search_object_namestr(searcher.get_contents(), search_query)
|
||||
if search_location:
|
||||
local_matches += list_search_object_namestr(searcher.get_location().get_contents(), search_query)
|
||||
|
||||
# If the object the invoker is in matches, add it as well.
|
||||
if searcher.get_location().dbref_match(ostring) or ostring == 'here':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue