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:
Greg Taylor 2007-07-12 13:45:23 +00:00
parent 679ef8dc74
commit 94779a86a5
4 changed files with 54 additions and 14 deletions

View file

@ -159,11 +159,16 @@ def handle(cdat):
pobject = session.get_pobject()
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
if exit_matches:
exit = exit_matches[0]
if exit.get_home():
targ_exit = exit_matches[0]
if targ_exit.get_home():
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:
session.msg("That exit leads to nowhere.")
return

View file

@ -1,6 +1,7 @@
import os
from traceback import format_exc
import settings
import functions_general
"""
This module is responsible for managing scripts and their connection to the
@ -31,9 +32,6 @@ def scriptlink(source_obj, scriptname):
if retval:
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
# 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
@ -45,22 +43,22 @@ def scriptlink(source_obj, scriptname):
try:
# 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))
modreference = __import__(modname)
# Store the module reference for later fast retrieval.
cached_scripts[scriptname] = modreference
except ImportError:
functions_general.log_infomsg('Error importing %s: %s' % (modname, format_exc()))
os.chdir(orig_path)
os.chdir(settings.BASE_PATH)
return
except OSError:
functions_general.log_infomsg('Invalid module path: %s' % (format_exc()))
os.chdir(orig_path)
os.chdir(settings.BASE_PATH)
return
# 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.
return modreference.class_factory(source_obj)

View file

@ -41,6 +41,39 @@ class BasicObject:
# Un-comment the line below for an example
#print "SCRIPT TEST: %s got %s." % (actor, self.source_obj)
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):
"""

View file

@ -14,7 +14,7 @@ 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'
# 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'.
@ -52,10 +52,14 @@ USE_I18N = False
# lighttpd).
SERVE_MEDIA = False
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
# Absolute path to the directory that holds media (no trailing slash).
# Example: "/home/media/media.lawrence.com"
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.
# Example: "http://media.lawrence.com"
MEDIA_URL = '/media/'