From 0e1e2ed1b0e99de12bce7fda170661f4693e57ad Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 2 Jan 2007 05:21:59 +0000 Subject: [PATCH] We now have get/drop and a vastly improved object searching function. Some misc. improvements to other utility tfunctions as well. --- evennia/trunk/apps/objects/models.py | 8 ++- evennia/trunk/commands_general.py | 80 ++++++++++++++++++++++++++- evennia/trunk/evennia.sql | Bin 52224 -> 52224 bytes evennia/trunk/functions_db.py | 20 +++++-- 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index fb52c7142e..66a21936e1 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -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): """ diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 0174a83ce1..339b645d81 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -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 diff --git a/evennia/trunk/evennia.sql b/evennia/trunk/evennia.sql index 68de633ddacb5ab0c39f42dd8b0799315b727f64..d1c27b0700688bf71d8f5a23421b5718beaf77b8 100755 GIT binary patch delta 82 zcmZpe!Q3!|d4e=!(nguu#jGC~*qE3n&s!YM$gug_VqqTUmyEkN^K8gt6lXSNa1>=^ mU<4utUPa%M)Z!8*CT6C|-kY^1vv1bhynCY$<7U&%rzHRxE*V?^ delta 80 zcmV-W0I&amm;->A1CSd5P_Z0+qXqT=1_c6>o}*U*1GDy{6AS~p0|&DVux 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':