Clean up some of the methods on the script parent system. I have no idea why I was being silly and passing things around through dictionaries. Yick. Also added a at_player_creation method to basicplayer.py that is triggered after player objects are created and ready to go, but before they are logged in.

This commit is contained in:
Greg Taylor 2009-03-30 00:54:05 +00:00
parent 4af854271a
commit b3c386a2c3
5 changed files with 43 additions and 42 deletions

View file

@ -180,9 +180,7 @@ def match_exits(command):
# it's not traversible.
if targ_exit.get_home():
# SCRIPT: See if the player can traverse the exit
if not targ_exit.scriptlink.default_lock({
"pobject": source_object
}):
if not targ_exit.scriptlink.default_lock(source_object):
source_object.emit_to("You can't traverse that exit.")
else:
source_object.move_to(targ_exit.get_home())

View file

@ -136,15 +136,10 @@ def cmd_look(command):
target_obj = source_object.get_location()
# SCRIPT: Get the item's appearance from the scriptlink.
source_object.emit_to(target_obj.scriptlink.return_appearance({
"target_obj": target_obj,
"pobject": source_object
}))
source_object.emit_to(target_obj.scriptlink.return_appearance(source_object))
# SCRIPT: Call the object's script's a_desc() method.
target_obj.scriptlink.a_desc({
"target_obj": source_object
})
target_obj.scriptlink.a_desc(source_object)
GLOBAL_CMD_TABLE.add_command("look", cmd_look)
def cmd_get(command):
@ -184,9 +179,7 @@ def cmd_get(command):
exclude=source_object)
# SCRIPT: Call the object's script's a_get() method.
target_obj.scriptlink.a_get({
"pobject": source_object
})
target_obj.scriptlink.a_get(source_object)
GLOBAL_CMD_TABLE.add_command("get", cmd_get)
def cmd_drop(command):
@ -218,9 +211,7 @@ def cmd_drop(command):
exclude=source_object)
# SCRIPT: Call the object's script's a_drop() method.
target_obj.scriptlink.a_drop({
"pobject": source_object
})
target_obj.scriptlink.a_drop(source_object)
GLOBAL_CMD_TABLE.add_command("drop", cmd_drop),
def cmd_examine(command):

View file

@ -340,6 +340,10 @@ class ObjectManager(models.Manager):
"owner": None}
user_object = self.create_object(odat)
# The User and player Object are ready, do anything needed by the
# game to further prepare things.
user_object.scriptlink.at_player_creation()
# Activate the player's session and set them loose.
command.session.login(user)
print 'Registration: %s' % (command.session, user_object.get_name())

View file

@ -18,27 +18,27 @@ class EvenniaBasicObject(object):
"""
self.source_obj = source_obj
def a_desc(self, values):
def a_desc(self, pobject):
"""
Perform this action when someone uses the LOOK command on the object.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# Un-comment the line below for an example
#print "SCRIPT TEST: %s looked at %s." % (values["pobject"], self.source_obj)
#print "SCRIPT TEST: %s looked at %s." % (pobject, self.source_obj)
pass
def return_appearance(self, values):
def return_appearance(self, pobject):
"""
Returns a string representation of an object's appearance when LOOKed at.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# This is the object being looked at.
target_obj = self.source_obj
pobject = values["pobject"]
# See if the envoker sees dbref numbers.
show_dbrefs = pobject.sees_dbrefs()
description = target_obj.get_description()
@ -80,60 +80,60 @@ class EvenniaBasicObject(object):
return retval
def a_get(self, values):
def a_get(self, pobject):
"""
Perform this action when someone uses the GET command on the object.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# Un-comment the line below for an example
#print "SCRIPT TEST: %s got %s." % (values["pobject"], self.source_obj)
#print "SCRIPT TEST: %s got %s." % (pobject, self.source_obj)
pass
def a_drop(self, values):
def a_drop(self, pobject):
"""
Perform this action when someone uses the GET command on the object.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# Un-comment the line below for an example
#print "SCRIPT TEST: %s dropped %s." % (values["pobject"], self.source_obj)
#print "SCRIPT TEST: %s dropped %s." % (pobject, self.source_obj)
pass
def default_lock(self, values):
def default_lock(self, pobject):
"""
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.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# Assume everyone passes the default lock by default.
return True
def use_lock(self, values):
def use_lock(self, pobject):
"""
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.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# Assume everyone passes the use lock by default.
return True
def enter_lock(self, values):
def enter_lock(self, pobject):
"""
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.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
values:
* pobject: (Object) The object requesting the action.
"""
# Assume everyone passes the enter lock by default.
return True

View file

@ -9,6 +9,14 @@ import time
from src import comsys
class EvenniaBasicPlayer(object):
def at_player_creation(self):
"""
This is triggered after a new User and accompanying Object is created.
By the time this is triggered, the player is ready to go but not
logged in.
"""
pass
def at_pre_login(self, session):
"""
Everything done here takes place before the player is actually