Added new SCRIPT_ROOT variable to settings.py, you'll need to copy this over from settings.py.dist if you're running a test game. We also now have rudimentary support for default, enter, and use locks per the basicobject.py file. Take a look at the example locks in there. A returned boolean value determines whether the player passes. Make sure you emit an error message within the lock if you're going to return false. We will have simple in-game attribute or dbref locks via an @lock command similar to MUX/MUSH that override scripted behaviors.
This commit is contained in:
parent
679ef8dc74
commit
94779a86a5
4 changed files with 54 additions and 14 deletions
|
|
@ -159,11 +159,16 @@ def handle(cdat):
|
||||||
pobject = session.get_pobject()
|
pobject = session.get_pobject()
|
||||||
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
|
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
|
||||||
if exit_matches:
|
if exit_matches:
|
||||||
exit = exit_matches[0]
|
targ_exit = exit_matches[0]
|
||||||
if exit.get_home():
|
if targ_exit.get_home():
|
||||||
cdat['uinput'] = parsed_input
|
cdat['uinput'] = parsed_input
|
||||||
pobject.move_to(exit.get_home())
|
|
||||||
session.execute_cmd("look")
|
# SCRIPT: See if the player can traverse the exit
|
||||||
|
if not targ_exit.get_scriptlink().default_lock(pobject):
|
||||||
|
session.msg("You can't traverse that exit.")
|
||||||
|
else:
|
||||||
|
pobject.move_to(targ_exit.get_home())
|
||||||
|
session.execute_cmd("look")
|
||||||
else:
|
else:
|
||||||
session.msg("That exit leads to nowhere.")
|
session.msg("That exit leads to nowhere.")
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
|
|
||||||
|
import settings
|
||||||
import functions_general
|
import functions_general
|
||||||
"""
|
"""
|
||||||
This module is responsible for managing scripts and their connection to the
|
This module is responsible for managing scripts and their connection to the
|
||||||
|
|
@ -31,9 +32,6 @@ def scriptlink(source_obj, scriptname):
|
||||||
if retval:
|
if retval:
|
||||||
return retval.class_factory(source_obj)
|
return retval.class_factory(source_obj)
|
||||||
|
|
||||||
# Store the original working directory so we can revert.
|
|
||||||
orig_path = os.getcwd()
|
|
||||||
|
|
||||||
# Split the script name up by periods to give us the directory we need
|
# Split the script name up by periods to give us the directory we need
|
||||||
# to change to. I really wish we didn't have to do this, but there's some
|
# to change to. I really wish we didn't have to do this, but there's some
|
||||||
# strange issue with __import__ and more than two directories worth of
|
# strange issue with __import__ and more than two directories worth of
|
||||||
|
|
@ -45,22 +43,22 @@ def scriptlink(source_obj, scriptname):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Change the working directory to the location of the script and import.
|
# Change the working directory to the location of the script and import.
|
||||||
os.chdir('scripts/%s/' % (newpath_str))
|
os.chdir('%s/%s/' % (settings.SCRIPT_ROOT, newpath_str))
|
||||||
functions_general.log_infomsg("SCRIPT: Caching and importing %s." % (modname))
|
functions_general.log_infomsg("SCRIPT: Caching and importing %s." % (modname))
|
||||||
modreference = __import__(modname)
|
modreference = __import__(modname)
|
||||||
# Store the module reference for later fast retrieval.
|
# Store the module reference for later fast retrieval.
|
||||||
cached_scripts[scriptname] = modreference
|
cached_scripts[scriptname] = modreference
|
||||||
except ImportError:
|
except ImportError:
|
||||||
functions_general.log_infomsg('Error importing %s: %s' % (modname, format_exc()))
|
functions_general.log_infomsg('Error importing %s: %s' % (modname, format_exc()))
|
||||||
os.chdir(orig_path)
|
os.chdir(settings.BASE_PATH)
|
||||||
return
|
return
|
||||||
except OSError:
|
except OSError:
|
||||||
functions_general.log_infomsg('Invalid module path: %s' % (format_exc()))
|
functions_general.log_infomsg('Invalid module path: %s' % (format_exc()))
|
||||||
os.chdir(orig_path)
|
os.chdir(settings.BASE_PATH)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Change back to the original working directory.
|
# Change back to the original working directory.
|
||||||
os.chdir(orig_path)
|
os.chdir(settings.BASE_PATH)
|
||||||
|
|
||||||
# The new script module has been cached, return the reference.
|
# The new script module has been cached, return the reference.
|
||||||
return modreference.class_factory(source_obj)
|
return modreference.class_factory(source_obj)
|
||||||
|
|
@ -42,6 +42,39 @@ class BasicObject:
|
||||||
#print "SCRIPT TEST: %s got %s." % (actor, self.source_obj)
|
#print "SCRIPT TEST: %s got %s." % (actor, self.source_obj)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def default_lock(self, actor):
|
||||||
|
"""
|
||||||
|
This method returns a True or False boolean value to determine whether
|
||||||
|
the actor passes the lock. This is generally used for picking up
|
||||||
|
objects or traversing exits.
|
||||||
|
|
||||||
|
actor: (Object) Reference to the person attempting an action
|
||||||
|
"""
|
||||||
|
# Assume everyone passes the default lock by default.
|
||||||
|
return True
|
||||||
|
|
||||||
|
def use_lock(self, actor):
|
||||||
|
"""
|
||||||
|
This method returns a True or False boolean value to determine whether
|
||||||
|
the actor passes the lock. This is generally used for seeing whether
|
||||||
|
a player can use an object or any of its commands.
|
||||||
|
|
||||||
|
actor: (Object) Reference to the person attempting an action
|
||||||
|
"""
|
||||||
|
# Assume everyone passes the use lock by default.
|
||||||
|
return True
|
||||||
|
|
||||||
|
def enter_lock(self, actor):
|
||||||
|
"""
|
||||||
|
This method returns a True or False boolean value to determine whether
|
||||||
|
the actor passes the lock. This is generally used for seeing whether
|
||||||
|
a player can enter another object.
|
||||||
|
|
||||||
|
actor: (Object) Reference to the person attempting an action
|
||||||
|
"""
|
||||||
|
# Assume everyone passes the enter lock by default.
|
||||||
|
return True
|
||||||
|
|
||||||
def class_factory(source_obj):
|
def class_factory(source_obj):
|
||||||
"""
|
"""
|
||||||
This method is called any script you retrieve (via the scripthandler). It
|
This method is called any script you retrieve (via the scripthandler). It
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ ADMINS = (
|
||||||
|
|
||||||
MANAGERS = ADMINS
|
MANAGERS = ADMINS
|
||||||
|
|
||||||
# The path that contains this settings.py file.
|
# The path that contains this settings.py file (no trailing slash).
|
||||||
BASE_PATH = '/home/evennia/evennia'
|
BASE_PATH = '/home/evennia/evennia'
|
||||||
|
|
||||||
# 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'.
|
# 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'.
|
||||||
|
|
@ -52,10 +52,14 @@ USE_I18N = False
|
||||||
# lighttpd).
|
# lighttpd).
|
||||||
SERVE_MEDIA = False
|
SERVE_MEDIA = False
|
||||||
|
|
||||||
# Absolute path to the directory that holds media.
|
# Absolute path to the directory that holds media (no trailing slash).
|
||||||
# Example: "/home/media/media.lawrence.com/"
|
# Example: "/home/media/media.lawrence.com"
|
||||||
MEDIA_ROOT = '%s/media' % (BASE_PATH)
|
MEDIA_ROOT = '%s/media' % (BASE_PATH)
|
||||||
|
|
||||||
|
# Absolute path to the directory that has the script tree in it. (no trailing slash)
|
||||||
|
# Example: "/home/evennia/scripts"
|
||||||
|
SCRIPT_ROOT = '%s/scripts' % (BASE_PATH)
|
||||||
|
|
||||||
# URL that handles the media served from MEDIA_ROOT.
|
# URL that handles the media served from MEDIA_ROOT.
|
||||||
# Example: "http://media.lawrence.com"
|
# Example: "http://media.lawrence.com"
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue