Script methods will now take a dictionary with keys rather than hard arguments. This will hopefully allow for a bit more flexibility.

This commit is contained in:
Greg Taylor 2007-07-17 15:58:19 +00:00
parent fadf3933af
commit be05772713
3 changed files with 40 additions and 20 deletions

View file

@ -164,7 +164,9 @@ def handle(cdat):
cdat['uinput'] = parsed_input cdat['uinput'] = parsed_input
# SCRIPT: See if the player can traverse the exit # SCRIPT: See if the player can traverse the exit
if not targ_exit.get_scriptlink().default_lock(pobject): if not targ_exit.get_scriptlink().default_lock({
"pobject": pobject
}):
session.msg("You can't traverse that exit.") session.msg("You can't traverse that exit.")
else: else:
pobject.move_to(targ_exit.get_home()) pobject.move_to(targ_exit.get_home())

View file

@ -119,7 +119,9 @@ def cmd_look(cdat):
})) }))
# SCRIPT: Call the object's script's a_desc() method. # SCRIPT: Call the object's script's a_desc() method.
target_obj.get_scriptlink().a_desc(pobject) target_obj.get_scriptlink().a_desc({
"target_obj": pobject
})
def cmd_get(cdat): def cmd_get(cdat):
""" """
@ -156,7 +158,9 @@ def cmd_get(cdat):
pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject) pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject)
# SCRIPT: Call the object's script's a_get() method. # SCRIPT: Call the object's script's a_get() method.
target_obj.get_scriptlink().a_get(pobject) target_obj.get_scriptlink().a_get({
"pobject": pobject
})
def cmd_drop(cdat): def cmd_drop(cdat):
""" """
@ -185,7 +189,9 @@ def cmd_drop(cdat):
pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject) pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject)
# SCRIPT: Call the object's script's a_drop() method. # SCRIPT: Call the object's script's a_drop() method.
target_obj.get_scriptlink().a_drop(pobject) target_obj.get_scriptlink().a_drop({
"pobject": pobject
})
def cmd_examine(cdat): def cmd_examine(cdat):
""" """

View file

@ -14,18 +14,25 @@ class BasicObject:
""" """
self.source_obj = source_obj self.source_obj = source_obj
def a_desc(self, actor): def a_desc(self, values):
""" """
Perform this action when someone uses the LOOK command on the object. Perform this action when someone uses the LOOK command on the object.
actor: (Object) Reference to the looker values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
""" """
# Un-comment the line below for an example # Un-comment the line below for an example
#print "SCRIPT TEST: %s looked at %s." % (actor, self.source_obj) #print "SCRIPT TEST: %s looked at %s." % (values["pobject"], self.source_obj)
pass pass
def return_appearance(self, values): def return_appearance(self, values):
target_obj = values["target_obj"] """
Returns a string representation of an object's appearance when LOOKed at.
values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
"""
target_obj = self.source_obj
pobject = values["pobject"] pobject = values["pobject"]
retval = "\r\n%s\r\n%s" % ( retval = "\r\n%s\r\n%s" % (
target_obj.get_name(), target_obj.get_name(),
@ -60,55 +67,60 @@ class BasicObject:
return retval return retval
def a_get(self, actor): def a_get(self, values):
""" """
Perform this action when someone uses the GET command on the object. Perform this action when someone uses the GET command on the object.
actor: (Object) Reference to the person who got the object values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
""" """
# Un-comment the line below for an example # Un-comment the line below for an example
#print "SCRIPT TEST: %s got %s." % (actor, self.source_obj) #print "SCRIPT TEST: %s got %s." % (values["pobject"], self.source_obj)
pass pass
def a_drop(self, actor): def a_drop(self, values):
""" """
Perform this action when someone uses the GET command on the object. Perform this action when someone uses the GET command on the object.
actor: (Object) Reference to the person who dropped the object values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
""" """
# Un-comment the line below for an example # Un-comment the line below for an example
#print "SCRIPT TEST: %s got %s." % (actor, self.source_obj) #print "SCRIPT TEST: %s dropped %s." % (values["pobject"], self.source_obj)
pass pass
def default_lock(self, actor): def default_lock(self, values):
""" """
This method returns a True or False boolean value to determine whether This method returns a True or False boolean value to determine whether
the actor passes the lock. This is generally used for picking up the actor passes the lock. This is generally used for picking up
objects or traversing exits. objects or traversing exits.
actor: (Object) Reference to the person attempting an action values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
""" """
# Assume everyone passes the default lock by default. # Assume everyone passes the default lock by default.
return True return True
def use_lock(self, actor): def use_lock(self, values):
""" """
This method returns a True or False boolean value to determine whether This method returns a True or False boolean value to determine whether
the actor passes the lock. This is generally used for seeing whether the actor passes the lock. This is generally used for seeing whether
a player can use an object or any of its commands. a player can use an object or any of its commands.
actor: (Object) Reference to the person attempting an action values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
""" """
# Assume everyone passes the use lock by default. # Assume everyone passes the use lock by default.
return True return True
def enter_lock(self, actor): def enter_lock(self, values):
""" """
This method returns a True or False boolean value to determine whether This method returns a True or False boolean value to determine whether
the actor passes the lock. This is generally used for seeing whether the actor passes the lock. This is generally used for seeing whether
a player can enter another object. a player can enter another object.
actor: (Object) Reference to the person attempting an action values: (Dict) Script arguments with keys:
* pobject: The object requesting the action.
""" """
# Assume everyone passes the enter lock by default. # Assume everyone passes the enter lock by default.
return True return True