diff --git a/src/cmdtable.py b/src/cmdtable.py index 4198b100b9..b69ff1069b 100644 --- a/src/cmdtable.py +++ b/src/cmdtable.py @@ -76,6 +76,7 @@ GLOBAL_CMD_TABLE.add_command("@ccreate", commands.comsys.cmd_ccreate, GLOBAL_CMD_TABLE.add_command("@cdestroy", commands.comsys.cmd_cdestroy, priv_tuple=("objects.delete_commchannel")), GLOBAL_CMD_TABLE.add_command("@chown", commands.objmanip.cmd_chown), +GLOBAL_CMD_TABLE.add_command("@chzone", commands.objmanip.cmd_chzone), GLOBAL_CMD_TABLE.add_command("@cemit", commands.comsys.cmd_cemit), GLOBAL_CMD_TABLE.add_command("@clist", commands.comsys.cmd_clist), GLOBAL_CMD_TABLE.add_command("@create", commands.objmanip.cmd_create, diff --git a/src/commands/objmanip.py b/src/commands/objmanip.py index d8d94168c1..51bb7074ca 100644 --- a/src/commands/objmanip.py +++ b/src/commands/objmanip.py @@ -421,6 +421,58 @@ def cmd_chown(command): # We haven't provided a target. session.msg("Who should be the new owner of the object?") return + +def cmd_chzone(command): + """ + Changes an object's zone. The specified zone may be of any object type, but + will typically be a THING. + + Forms: + @chzone = + """ + session = command.session + pobject = session.get_pobject() + + if not command.command_argument: + session.msg("Change the zone of what?") + return + + eq_args = command.command_argument.split('=', 1) + target_name = eq_args[0] + zone_name = eq_args[1] + + if len(target_name) == 0: + session.msg("Change the zone of what?") + return + + if len(eq_args) > 1: + target_obj = Object.objects.standard_plr_objsearch(session, target_name) + # Use standard_plr_objsearch to handle duplicate/nonexistant results. + if not target_obj: + return + + if not pobject.controls_other(target_obj): + session.msg(defines_global.NOCONTROL_MSG) + return + + # Allow the clearing of a zone + if zone_name.lower() == "none": + target_obj.set_zone(None) + session.msg("%s is no longer zoned." % (target_obj)) + return + + zone_obj = Object.objects.standard_plr_objsearch(session, zone_name) + # Use standard_plr_objsearch to handle duplicate/nonexistant results. + if not zone_obj: + return + + target_obj.set_zone(zone_obj) + session.msg("%s is now in zone %s." % (target_obj, zone_obj)) + + else: + # We haven't provided a target zone. + session.msg("What should the object's zone be set to?") + return def cmd_link(command): """ diff --git a/src/objects/models.py b/src/objects/models.py index d2ba688fd8..b08d8682aa 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -752,6 +752,13 @@ class Object(models.Model): return self.zone except: return None + + def set_zone(self, new_zone): + """ + Sets an object's zone. + """ + self.zone = new_zone + self.save() def move_to(self, target, quiet=False, force_look=True): """