Add more parts of the turnbased combat tutorial

This commit is contained in:
Griatch 2022-07-11 20:45:30 +02:00
parent 83395211cc
commit e7f8926b23
7 changed files with 399 additions and 70 deletions

View file

@ -69,6 +69,9 @@ class ScriptHandler(object):
in script definition and listings)
autostart (bool, optional): Start the script upon adding it.
Returns:
Script: The newly created Script.
"""
if self.obj.__dbclass__.__name__ == "AccountDB":
# we add to an Account, not an Object
@ -76,21 +79,21 @@ class ScriptHandler(object):
scriptclass, key=key, account=self.obj, autostart=autostart
)
else:
# the normal - adding to an Object. We wait to autostart so we can differentiate
# adding to an Object. We wait to autostart so we can differentiate
# a failing creation from a script that immediately starts/stops.
script = create.create_script(scriptclass, key=key, obj=self.obj, autostart=False)
if not script:
logger.log_err("Script %s failed to be created/started." % scriptclass)
return False
logger.log_err(f"Script {scriptclass} failed to be created.")
return None
if autostart:
script.start()
if not script.id:
# this can happen if the script has repeats=1 or calls stop() in at_repeat.
logger.log_info(
"Script %s started and then immediately stopped; "
"it could probably be a normal function." % scriptclass
f"Script {scriptclass} started and then immediately stopped; "
"it could probably be a normal function."
)
return True
return script
def start(self, key):
"""
@ -118,10 +121,10 @@ class ScriptHandler(object):
key (str): Search criterion, the script's key or dbref.
Returns:
scripts (list): The found scripts matching `key`.
scripts (queryset): The found scripts matching `key`.
"""
return list(ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=key))
return ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=key)
def delete(self, key=None):
"""