mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 18:26:32 +01:00
GLOBAL_STATE_TABLE.add_state() before adding commands to it. The state can now be much more configured by including as much or as little of the normal default commands into it as wanted (so you can now have states which are almost as normal, except some commands are missing or change their behaviour ... illness or darkness comes to mind). The possibilities here are limitless. * States now also optionally allow traversing exits as well as using command tables defined on objects. * States now better handle error messages (so if you try 'look' in a state which does not contain a look command you will no longer get the 'Huh?' but will be told that the command is not available at the moment). * All examples in commands/examples/ have been updated to use the new State system. Also added a @test_state function for trying out the functionality. * Added hooks at_before_move() and at_after_move(), useful for character based move-restrictions and checks (e.g. movement speed) * Minor tweaks to the event system; avoiding the counters to go negative should they hit an uncaught traceback. * Small fixes of typos and minor extra safety checks. /Griatch
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
"""
|
|
Simple example of a custom modified object, derived from the base object.
|
|
|
|
If you want to make this your new default object type, move this into
|
|
gamesrc/parents and set SCRIPT_DEFAULT_OBJECT = 'custom_basicobject'
|
|
in game/settings.py.
|
|
|
|
Generally, if you want to conveniently set future objects to inherit from this
|
|
script parent, this files and others like it need to be
|
|
located under the game/gamesrc/parent directory.
|
|
"""
|
|
from game.gamesrc.parents.base.basicobject import BasicObject
|
|
|
|
class CustomBasicObject(BasicObject):
|
|
|
|
def at_object_creation(self):
|
|
"""
|
|
This function is called whenever the object is created. Use
|
|
this instead of __init__ to set start attributes etc on a
|
|
particular object type.
|
|
"""
|
|
|
|
#Set an "sdesc" (short description) attribute on object,
|
|
#defaulting to its given name
|
|
|
|
#get the stored object related to this class
|
|
obj = self.scripted_obj
|
|
|
|
#find out the object's name
|
|
name = obj.get_name(fullname=False,
|
|
show_dbref=False,
|
|
show_flags=False)
|
|
#assign the name to the new attribute
|
|
obj.set_attribute('sdesc',name)
|
|
|
|
def at_object_destruction(self, pobject=None):
|
|
"""
|
|
This is triggered when an object is about to be destroyed via
|
|
@destroy ONLY. If an object is deleted via delete(), it is assumed
|
|
that this method is to be skipped.
|
|
|
|
values:
|
|
* pobject: (Object) The object requesting the action.
|
|
"""
|
|
pass
|
|
|
|
def at_before_move(self, target_location):
|
|
"""
|
|
This hook is called just before the object is moved.
|
|
Input:
|
|
target_location (obj): The location the player is about to move to.
|
|
Return value:
|
|
If this function returns anything but None (no return value),
|
|
the move is aborted. This allows for character-based move
|
|
restrictions (not only exit locks).
|
|
"""
|
|
pass
|
|
|
|
def at_after_move(self):
|
|
"""
|
|
This hook is called just after the player has been successfully moved.
|
|
"""
|
|
pass
|
|
|
|
|
|
def class_factory(source_obj):
|
|
"""
|
|
This method is called by any script you retrieve (via the scripthandler). It
|
|
creates an instance of the class and returns it transparently.
|
|
|
|
source_obj: (Object) A reference to the object being scripted (the child).
|
|
"""
|
|
return CustomBasicObject(source_obj)
|