Added @mvattr command as per MUX (Issue 25). Cleaned up @set to give better feedback. Some minor cleanups.
This commit is contained in:
parent
5a3d901b5c
commit
bd2f7a845c
7 changed files with 111 additions and 39 deletions
0
ABOUT
Executable file → Normal file
0
ABOUT
Executable file → Normal file
2
INSTALL
2
INSTALL
|
|
@ -31,7 +31,7 @@ in development, we'll make sure to update this. But for the really determined
|
||||||
* If you want to use anything other than the default SQLite setup, copy and
|
* If you want to use anything other than the default SQLite setup, copy and
|
||||||
modify the DATABASE_* variables from src/config_defaults.py.
|
modify the DATABASE_* variables from src/config_defaults.py.
|
||||||
* Run 'python manage.py syncdb'
|
* Run 'python manage.py syncdb'
|
||||||
* Run 'python evennia.py start'. This will start the MU* server on port 4000
|
* Run 'python evennia.py -i start'. This will start the MU* server on port 4000
|
||||||
by default. You may change this via the web interface or by editing the
|
by default. You may change this via the web interface or by editing the
|
||||||
config table in SQL.
|
config table in SQL.
|
||||||
* Login with the email address and password you provided to the syncdb script.
|
* Login with the email address and password you provided to the syncdb script.
|
||||||
|
|
|
||||||
0
README
Executable file → Normal file
0
README
Executable file → Normal file
0
__init__.py
Executable file → Normal file
0
__init__.py
Executable file → Normal file
|
|
@ -171,24 +171,25 @@ def cmd_set(command):
|
||||||
Sets flags or attributes on objects.
|
Sets flags or attributes on objects.
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
|
args = command.command_argument
|
||||||
if not command.command_argument:
|
if not args:
|
||||||
source_object.emit_to("Set what?")
|
source_object.emit_to("Usage: @set obj=attr:value or @set obj=flag. Use empty value or !flag to clear.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Break into target and value by the equal sign.
|
# Break into target and value by the equal sign.
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = args.split('=')
|
||||||
if len(eq_args) < 2:
|
if len(eq_args) < 2 or not eq_args[1]:
|
||||||
# Equal signs are not optional for @set.
|
# Equal signs are not optional for @set.
|
||||||
source_object.emit_to("Set what?")
|
source_object.emit_to("Set what?")
|
||||||
return
|
return
|
||||||
|
target_name = eq_args[0]
|
||||||
victim = source_object.search_for_object(eq_args[0])
|
target = source_object.search_for_object(eq_args[0])
|
||||||
# Use search_for_object to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not victim:
|
if not target:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not source_object.controls_other(victim):
|
#check permission.
|
||||||
|
if not source_object.controls_other(target):
|
||||||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -199,48 +200,118 @@ def cmd_set(command):
|
||||||
splicenum = eq_args[1].find(':') + 1
|
splicenum = eq_args[1].find(':') + 1
|
||||||
attrib_value = (eq_args[1][splicenum:]).strip()
|
attrib_value = (eq_args[1][splicenum:]).strip()
|
||||||
|
|
||||||
# In global_defines.py, see NOSET_ATTRIBS for protected attribute names.
|
if not attrib_name:
|
||||||
|
source_object.emit_to("Cannot set an empty attribute name.")
|
||||||
|
return
|
||||||
if not Attribute.objects.is_modifiable_attrib(attrib_name):
|
if not Attribute.objects.is_modifiable_attrib(attrib_name):
|
||||||
|
# In global_defines.py, see NOSET_ATTRIBS for protected attribute names.
|
||||||
source_object.emit_to("You can't modify that attribute.")
|
source_object.emit_to("You can't modify that attribute.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if attrib_value:
|
if attrib_value:
|
||||||
# An attribute value was specified, create or set the attribute.
|
# An attribute value was specified, create or set the attribute.
|
||||||
verb = 'set'
|
target.set_attribute(attrib_name, attrib_value)
|
||||||
victim.set_attribute(attrib_name, attrib_value)
|
s = "Attribute %s=%s set to %s." % (target_name, attrib_name, attrib_value)
|
||||||
else:
|
else:
|
||||||
# No value was given, this means we delete the attribute.
|
# No value was given, this means we delete the attribute.
|
||||||
ok = victim.clear_attribute(attrib_name)
|
ok = target.clear_attribute(attrib_name)
|
||||||
if ok: verb = 'attribute cleared'
|
if ok:
|
||||||
else: verb = 'is not a known attribute. If it is a flag, use !flag to clear it'
|
s = 'Attribute %s=%s deleted.' % (target_name,attrib_name)
|
||||||
|
else:
|
||||||
victim.clear_attribute(attrib_name)
|
s = "Attribute %s=%s not found, so not cleared. \nIf it is a flag, use '@set %s:!%s' to clear it." % \
|
||||||
source_object.emit_to("%s - %s %s." % (victim.get_name(), attrib_name, verb))
|
(target_name, attrib_name, target_name, attrib_name)
|
||||||
|
source_object.emit_to(s)
|
||||||
else:
|
else:
|
||||||
# Flag manipulation form.
|
# Flag manipulation form.
|
||||||
flag_list = eq_args[1].split()
|
flag_list = eq_args[1].split()
|
||||||
|
s = ""
|
||||||
for flag in flag_list:
|
for flag in flag_list:
|
||||||
flag = flag.upper()
|
flag = flag.upper()
|
||||||
if flag[0] == '!':
|
if flag[0] == '!':
|
||||||
# We're un-setting the flag.
|
# We're un-setting the flag.
|
||||||
flag = flag[1:]
|
flag = flag[1:]
|
||||||
if not src.flags.is_modifiable_flag(flag):
|
if not src.flags.is_modifiable_flag(flag):
|
||||||
source_object.emit_to("You can't set/unset the flag - %s." % (flag,))
|
s += "\nYou can't set/unset the flag %s." % flag
|
||||||
else:
|
continue
|
||||||
source_object.emit_to('%s - %s cleared.' % (victim.get_name(),
|
if not target.has_flag(flag):
|
||||||
flag.upper(),))
|
s += "\nFlag %s=%s already cleared." % (target_name,flag)
|
||||||
victim.set_flag(flag, False)
|
continue
|
||||||
|
s += "\nFlag %s=%s cleared." % (target_name, flag.upper())
|
||||||
|
target.unset_flag(flag)
|
||||||
else:
|
else:
|
||||||
# We're setting the flag.
|
# We're setting the flag.
|
||||||
if not src.flags.is_modifiable_flag(flag):
|
if not src.flags.is_modifiable_flag(flag):
|
||||||
source_object.emit_to("You can't set/unset the flag - %s." % flag)
|
s += "\nYou can't set/unset the flag %s." % flag
|
||||||
|
continue
|
||||||
|
if target.has_flag(flag):
|
||||||
|
s += "\nFlag %s=%s already set." % (target_name, flag)
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
source_object.emit_to('%s - %s set.' % (victim.get_name(),
|
s += '\nFlag %s=%s set.' % (target_name, flag.upper())
|
||||||
flag.upper(),))
|
target.set_flag(flag, True)
|
||||||
victim.set_flag(flag, True)
|
source_object.emit_to(s[1:])
|
||||||
GLOBAL_CMD_TABLE.add_command("@set", cmd_set)
|
GLOBAL_CMD_TABLE.add_command("@set", cmd_set)
|
||||||
|
|
||||||
|
def cmd_mvattr(command):
|
||||||
|
"""
|
||||||
|
@mvattr <object>=<old>,<new>[,<copy1>]...
|
||||||
|
|
||||||
|
Move attributes around on an object
|
||||||
|
"""
|
||||||
|
source_object = command.source_object
|
||||||
|
arg = command.command_argument
|
||||||
|
#split arguments
|
||||||
|
if not arg or not '=' in arg:
|
||||||
|
source_object.emit_to("Usage: @mvattr <object>=<old>,<new>[,<copy1>]...")
|
||||||
|
return
|
||||||
|
objname,attrs = arg.split('=')
|
||||||
|
attrs = attrs.split(",")
|
||||||
|
oldattr = attrs[0]
|
||||||
|
if len(attrs)<2:
|
||||||
|
source_object.emit_to("You must give both the old- and new name of the attribute.")
|
||||||
|
return
|
||||||
|
#find target object
|
||||||
|
target_obj = source_object.search_for_object(objname)
|
||||||
|
if not target_obj:
|
||||||
|
source_object.emit_to("Object '%s' not found." % objname)
|
||||||
|
return
|
||||||
|
#check so old attribute exists.
|
||||||
|
value = target_obj.get_attribute_value(oldattr)
|
||||||
|
if value == None:
|
||||||
|
source_object.emit_to("Attribute '%s' does not exist." % oldattr)
|
||||||
|
return
|
||||||
|
#check permission to modify object
|
||||||
|
if not source_object.controls_other(target_obj):
|
||||||
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
|
return
|
||||||
|
#we should now be good to go. Start the copying.
|
||||||
|
s = "Moving %s (with value %s) ..." % (oldattr,value)
|
||||||
|
delete_original = True
|
||||||
|
for attr in attrs[1:]:
|
||||||
|
if not attr:
|
||||||
|
s += "\nCan not copy to empty attribute name."
|
||||||
|
continue
|
||||||
|
if not Attribute.objects.is_modifiable_attrib(attr):
|
||||||
|
s += "\nDid not copy to '%s' (cannot be modified)" % attr
|
||||||
|
continue
|
||||||
|
if attr == oldattr:
|
||||||
|
s += "\nKept '%s' (moved into itself)" % attr
|
||||||
|
delete_original = False
|
||||||
|
continue
|
||||||
|
target_obj.set_attribute(attr, value)
|
||||||
|
s += "\nCopied %s -> %s" % (oldattr,attr)
|
||||||
|
#if we can, delete the old attribute
|
||||||
|
if not Attribute.objects.is_modifiable_attrib(oldattr):
|
||||||
|
s += "\nCould not remove old attribute '%s' (cannot be modified)" % oldattr
|
||||||
|
elif delete_original:
|
||||||
|
target_obj.clear_attribute(oldattr)
|
||||||
|
s += "\nRemoved '%s'." % (oldattr)
|
||||||
|
|
||||||
|
source_object.emit_to(s)
|
||||||
|
|
||||||
|
GLOBAL_CMD_TABLE.add_command("@mvattr", cmd_mvattr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_find(command):
|
def cmd_find(command):
|
||||||
"""
|
"""
|
||||||
Searches for an object of a particular name.
|
Searches for an object of a particular name.
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ class ConfigValueManager(models.Manager):
|
||||||
try:
|
try:
|
||||||
return self.get(conf_key__iexact=configname).conf_value
|
return self.get(conf_key__iexact=configname).conf_value
|
||||||
except self.model.DoesNotExist:
|
except self.model.DoesNotExist:
|
||||||
logger.log_errmsg("Unable to get config value for %s (does not exist).\n" % (
|
if configname not in ["game_firstrun"]:
|
||||||
|
logger.log_errmsg("Unable to get config value for %s (does not exist).\n" % (
|
||||||
configname))
|
configname))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue