mirror of
https://github.com/evennia/evennia.git
synced 2026-04-04 23:17:17 +02:00
@cpattr now coded, please post reports if bugs found, appears to work as expected.
This commit is contained in:
parent
64b3a79282
commit
3d4ad07f9a
2 changed files with 85 additions and 1 deletions
|
|
@ -76,6 +76,8 @@ GLOBAL_CMD_TABLE.add_command("@ccreate", commands.comsys.cmd_ccreate,
|
|||
priv_tuple=("objects.add_commchannel")),
|
||||
GLOBAL_CMD_TABLE.add_command("@cdestroy", commands.comsys.cmd_cdestroy,
|
||||
priv_tuple=("objects.delete_commchannel")),
|
||||
GLOBAL_CMD_TABLE.add_command("@cpattr", commands.objmanip.cmd_cpattr,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@chown", commands.objmanip.cmd_chown),
|
||||
GLOBAL_CMD_TABLE.add_command("@cwho", commands.comsys.cmd_cwho),
|
||||
GLOBAL_CMD_TABLE.add_command("@chzone", commands.objmanip.cmd_chzone),
|
||||
|
|
@ -130,4 +132,4 @@ Global unconnected command table, for unauthenticated users.
|
|||
GLOBAL_UNCON_CMD_TABLE = CommandTable()
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("connect", commands.unloggedin.cmd_connect)
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("create", commands.unloggedin.cmd_create)
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("quit", commands.unloggedin.cmd_quit)
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("quit", commands.unloggedin.cmd_quit)
|
||||
|
|
|
|||
|
|
@ -289,6 +289,88 @@ def cmd_create(command):
|
|||
|
||||
session.msg("You create a new thing: %s" % (new_object,))
|
||||
|
||||
def cmd_cpattr(command):
|
||||
"""
|
||||
Copies a given attribute to another object.
|
||||
|
||||
@cpattr <source object>/<attribute> = <target1>/[<attrname>] <target n>/[<attrname n>]
|
||||
"""
|
||||
|
||||
session = command.session
|
||||
pobject = session.get_pobject()
|
||||
|
||||
if not command.command_argument:
|
||||
session.msg("What do you want to copy?")
|
||||
return
|
||||
|
||||
# Split up source and target[s] via the equals sign.
|
||||
eq_args = command.command_argument.split('=', 1)
|
||||
|
||||
if len(eq_args) < 2:
|
||||
# There must be both a source and a target pair for cpattr
|
||||
session.msg("You have not supplied both a source and a target[s]")
|
||||
return
|
||||
|
||||
# Check that the source object and attribute exists, by splitting the eq_args 'source' entry with '/'
|
||||
source = eq_args[0].split('/', 1)
|
||||
source_string = source[0].strip()
|
||||
source_attr_string = source[1].strip().upper()
|
||||
|
||||
# Check whether src_obj exists
|
||||
src_obj = Object.objects.standard_plr_objsearch(session, source_string)
|
||||
|
||||
if not src_obj:
|
||||
session.msg("Source object does not exist")
|
||||
return
|
||||
|
||||
# Check whether src_obj has src_attr
|
||||
src_attr = src_obj.attribute_namesearch(source_attr_string)
|
||||
|
||||
if not src_attr:
|
||||
session.msg("Source object does not have attribute " + source[1].strip())
|
||||
return
|
||||
|
||||
# For each target object, check it exists
|
||||
# Remove leading '' from the targets list.
|
||||
targets = eq_args[1].split(' ')[1:]
|
||||
|
||||
for target in targets:
|
||||
tar = target.split('/', 1)
|
||||
tar_string = tar[0].strip()
|
||||
tar_attr_string = tar[1].strip().upper()
|
||||
|
||||
tar_obj = Object.objects.standard_plr_objsearch(session, tar_string)
|
||||
|
||||
# Does target exist?
|
||||
if not tar_obj:
|
||||
session.msg("Target object does not exist: " + tar_string)
|
||||
return
|
||||
|
||||
# If target attribute is not given, use source_attr_string for name
|
||||
if tar_attr_string == '':
|
||||
# session.msg("Testing")
|
||||
src_attr_contents = src_obj.get_attribute_value(source_attr_string)
|
||||
tar_obj.set_attribute(source_attr_string, src_attr_contents)
|
||||
return
|
||||
|
||||
# If however, the target attribute is given, check it exists and update accordingly
|
||||
|
||||
# Does target attribute exist?
|
||||
|
||||
tar_attr = tar_obj.attribute_namesearch(tar_attr_string)
|
||||
|
||||
# If the target object does not have the given attribute, make a new attr
|
||||
if not tar_attr:
|
||||
src_attr_contents = src_obj.get_attribute_value(source_attr_string)
|
||||
tar_obj.set_attribute(tar_attr_string, src_attr_contents)
|
||||
return
|
||||
|
||||
# If target has attribute, update its contents
|
||||
src_attr_contents = src_obj.get_attribute_value(source_attr_string)
|
||||
tar_obj.set_attribute(tar_attr_string, src_attr_contents)
|
||||
session.msg(tar_obj.get_attribute_value(source_attr_string))
|
||||
|
||||
|
||||
def cmd_nextfree(command):
|
||||
"""
|
||||
Returns the next free object number.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue