Some cleanup. Fixed all examples to match the changes in the states and help systems, also
ran them through pylint to pretty them up. /Griatch
This commit is contained in:
parent
8074617285
commit
84aeabb272
11 changed files with 323 additions and 211 deletions
|
|
@ -1,29 +1,40 @@
|
||||||
"""
|
"""
|
||||||
This is an example command module for showing the pluggable command system
|
This is an example command module for showing the pluggable command
|
||||||
in action.
|
system in action.
|
||||||
|
|
||||||
You'll need to make sure that this or any new modules you create are added to
|
You'll need to make sure that this or any new modules you create are
|
||||||
game/settings.py under CUSTOM_COMMAND_MODULES or CUSTOM_UNLOGGED_COMMAND_MODULES,
|
added to game/settings.py under CUSTOM_COMMAND_MODULES or
|
||||||
which are tuples of module import path strings. See src/config_defaults.py for more details.
|
CUSTOM_UNLOGGED_COMMAND_MODULES, which are tuples of module import
|
||||||
|
path strings. See src/config_defaults.py for more details.
|
||||||
|
|
||||||
E.g. to add this example command for testing, your entry in game/settings.py would
|
E.g. to add this example command for testing, your entry in
|
||||||
look like this:
|
game/settings.py would look like this:
|
||||||
|
|
||||||
CUSTOM_COMMAND_MODULES = ('game.gamesrc.commands.examples.example',)
|
CUSTOM_COMMAND_MODULES = ('game.gamesrc.commands.examples.example',)
|
||||||
|
|
||||||
(note the extra comma at the end to make this into a Python tuple. It's only
|
(note the extra comma at the end to make this into a Python
|
||||||
needed if you have only one entry.) You need to restart the Evennia server before new
|
tuple. It's only needed if you have only one entry.) You need to
|
||||||
files are recognized.
|
restart the Evennia server before new files are recognized. Once this
|
||||||
|
is done once, you don't have to restart again, just use
|
||||||
|
@reload/commands to use the changes you make to your modules.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# This is the common global CommandTable object which we'll be adding the
|
# This is the common global CommandTable object which we'll be adding the
|
||||||
# example command to. We can add any number of commands this way in the
|
# example command(s) to.
|
||||||
# same file.
|
|
||||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||||
|
|
||||||
|
# The main command definition. We can add any number of commands this way in the
|
||||||
|
# same file.
|
||||||
def cmd_example(command):
|
def cmd_example(command):
|
||||||
"""
|
"""
|
||||||
|
example - example command
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
example[/switches] <text>
|
||||||
|
|
||||||
|
switches:
|
||||||
|
use any string
|
||||||
|
|
||||||
This is the help text for the 'example' command, a command to
|
This is the help text for the 'example' command, a command to
|
||||||
show how the pluggable command system works.
|
show how the pluggable command system works.
|
||||||
|
|
||||||
|
|
@ -32,15 +43,17 @@ def cmd_example(command):
|
||||||
> example/test/test2 Hello
|
> example/test/test2 Hello
|
||||||
and see what is returned.
|
and see what is returned.
|
||||||
|
|
||||||
<<TOPIC:example_auto_help>>
|
[[example_auto_help]]
|
||||||
|
|
||||||
This is a subtopic to the main example command help entry.
|
This is a subtopic to the main example command help entry. It is
|
||||||
|
done by the help system splitting the text by markup of the
|
||||||
|
form [ [title ] ] (with no spaces between the square brackets)
|
||||||
|
|
||||||
Note that this text is auto-added since auto_help=True
|
Note that this help entry is auto-added as long as HELP_AUTO
|
||||||
was set in the call to add_function. Any number of subtopics like
|
is not set to False in your game/settings.py file.
|
||||||
this one can be added on the fly using the auto-help system. See
|
Any number of subtopics like this one can be added on the fly
|
||||||
help topics on 'help' and 'help_staff' for more information and
|
using the auto-help system. See help topics on 'help' and
|
||||||
options.
|
'help_markup' for more information and options.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# By building one big string and passing it at once, we cut down on a lot
|
# By building one big string and passing it at once, we cut down on a lot
|
||||||
|
|
@ -65,32 +78,35 @@ def cmd_example(command):
|
||||||
command.source_object.emit_to(retval)
|
command.source_object.emit_to(retval)
|
||||||
|
|
||||||
# Add the command to the common global command table. Note that
|
# Add the command to the common global command table. Note that
|
||||||
# since auto_help=True, help entries named "example" and
|
# this will auto-create help entries 'example' and
|
||||||
# "example_auto_help" (as defined in the __doc__ string) will
|
# "example_auto_help" for us.
|
||||||
# automatically be created for us.
|
GLOBAL_CMD_TABLE.add_command("example", cmd_example)
|
||||||
GLOBAL_CMD_TABLE.add_command("example", cmd_example, auto_help=True),
|
|
||||||
|
|
||||||
#another simple example
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# another simple example
|
||||||
|
#
|
||||||
def cmd_emote_smile(command):
|
def cmd_emote_smile(command):
|
||||||
"""
|
"""
|
||||||
Simplistic 'smile' emote.
|
smile - break a smile
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
smile
|
||||||
|
|
||||||
|
A 'smile' emote.
|
||||||
"""
|
"""
|
||||||
#get the source object (that is, the player using the command)
|
#get the source object (that is, the player using the command)
|
||||||
caller = command.source_object
|
source_object = command.source_object
|
||||||
#find name of caller
|
#find name of caller
|
||||||
name = caller.get_name(show_dbref=False)
|
name = source_object.get_name(show_dbref=False)
|
||||||
#get the location caller is at
|
#get the location caller is at
|
||||||
location = caller.get_location()
|
location = source_object.get_location()
|
||||||
#build the emote
|
#build the emote
|
||||||
text = "%s smiles." % name
|
text = "%s smiles." % name
|
||||||
#emit the emote to everyone at the current location
|
#emit the emote to everyone at the current location
|
||||||
location.emit_to_contents(text)
|
location.emit_to_contents(text)
|
||||||
|
|
||||||
#add to global command table (no auto_help activated)
|
# add to global command table (we probably want an auto-help entry
|
||||||
GLOBAL_CMD_TABLE.add_command('smile', cmd_emote_smile)
|
# for this, but we are turning auto-help off anyway, to show
|
||||||
|
# how it works)
|
||||||
|
GLOBAL_CMD_TABLE.add_command('smile', cmd_emote_smile,
|
||||||
|
auto_help_override=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,42 @@
|
||||||
"""
|
"""
|
||||||
Example of using the state system. The Event system allows a player object to be
|
Example of using the state system. The State system allows a player
|
||||||
'trapped' in a special environment where different commands are available than normal.
|
object to be 'trapped' in a special environment where different
|
||||||
This is very useful in order to implement anything from menus to npc-conversational
|
commands are available than normal. This is very useful in order to
|
||||||
|
implement anything from menus and combat states to npc-conversational
|
||||||
choices and inline text-editors.
|
choices and inline text-editors.
|
||||||
|
|
||||||
This example uses the State system to create a simple menu.
|
This example uses the State system to create a simple menu.
|
||||||
|
|
||||||
To test out this example, add this module to the CUSTOM_COMMAND_MODULES tuple in
|
To test out this example, add this module to the
|
||||||
your game/settings.py as 'game.gamesrc.commands.examples.state_example' (see ./example.py
|
CUSTOM_COMMAND_MODULES tuple in your game/settings.py as
|
||||||
for another example). You need to restart the Evennia server before new files are
|
'game.gamesrc.commands.examples.state_example' (see ./example.py for
|
||||||
recognized.
|
another example). You need to restart the Evennia server before new
|
||||||
|
files are recognized.
|
||||||
|
|
||||||
Next enter the mud and give the command
|
Next enter the mud and give the command
|
||||||
|
|
||||||
> entermenu
|
> entermenu
|
||||||
|
|
||||||
Note that the help entries related to this little menu are not part of the normal
|
Note that the help entries related to this little menu are not part of
|
||||||
help database, they are stored with the state and only accessible
|
the normal help database, they are stored with the state and only
|
||||||
from inside it. If you want to describe the state itself in more detail you
|
accessible from inside it. Try 'help entermenu' from outside the state
|
||||||
should add a help entry about it to the main help index manually.
|
and 'help' and 'info' from inside the menu to see the auto-help system
|
||||||
|
in action.
|
||||||
|
|
||||||
To further test the state system, try the command
|
To further test the state system, try the command
|
||||||
|
|
||||||
> enterstate
|
> enterstate
|
||||||
|
|
||||||
|
This takes arguments between 1-6 to set up various states with varying
|
||||||
|
access to different global commands.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#This is the normal command table, accessible by default
|
# This is the normal command table, accessible by default
|
||||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||||
|
|
||||||
#The statetable contains sets of cmdtables that is made available
|
# The statetable contains sets of cmdtables that is made available
|
||||||
#only when we are in a particular state, overriding the GLOBAL_CMD_TABLE
|
# only when we are in a particular state (possibly overriding
|
||||||
|
# same-named commands in GLOBAL_CMD_TABLE).
|
||||||
from src.statetable import GLOBAL_STATE_TABLE
|
from src.statetable import GLOBAL_STATE_TABLE
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -38,38 +47,47 @@ from src.statetable import GLOBAL_STATE_TABLE
|
||||||
STATENAME = 'menu'
|
STATENAME = 'menu'
|
||||||
|
|
||||||
#
|
#
|
||||||
# 'entry' command
|
# 'entry' command. This takes the player from the normal game
|
||||||
|
# mode into the menu state. This must be added to the
|
||||||
|
# GLOBAL_CMD_TABLE like any other command.
|
||||||
#
|
#
|
||||||
def cmd_entermenu(command):
|
def cmd_entermenu(command):
|
||||||
"""
|
"""
|
||||||
|
entermenu - enter the example menu
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
entermenu
|
||||||
|
|
||||||
This is the 'entry' command that takes the player from the normal
|
This is the 'entry' command that takes the player from the normal
|
||||||
gameplay mode into the 'menu' state. In order to do this, it
|
gameplay mode into the 'menu' state.
|
||||||
must be added to the GLOBAL_CMD_TABLE like any command.
|
|
||||||
"""
|
"""
|
||||||
#get the player object calling the command
|
# get the player object calling the command
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
#this is important: we use the set_state() command
|
|
||||||
#to shift the player into a state named 'menu'. Other useful
|
# this is important: we use the set_state() command
|
||||||
#access functions on source_object are get_state()
|
# to shift the player into a state named 'menu'. Other useful
|
||||||
|
# access functions on source_object are get_state()
|
||||||
# and clear_state(), the latter returns the player to
|
# and clear_state(), the latter returns the player to
|
||||||
# the normal mode of gameplay.
|
# the normal mode of gameplay.
|
||||||
source_object.set_state(STATENAME)
|
source_object.set_state(STATENAME)
|
||||||
#show the menu.
|
|
||||||
s = """
|
#show a welcome text .
|
||||||
Welcome to the Demo menu!
|
string = """
|
||||||
In this small demo all you can do is select one of
|
Welcome to the Demo menu! In this small demo all you can do is
|
||||||
the two options so it changes colour.
|
select one of the two options so it changes colour. This is just
|
||||||
This is just intended to show off the
|
intended to show off the possibilities of the state system. More
|
||||||
possibilities of the state system. More
|
interesting things should of course happen in a real menu.
|
||||||
interesting things should of course happen
|
|
||||||
in a real menu.
|
Use @exit to leave the menu.
|
||||||
Use @exit to leave the menu."""
|
"""
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(string)
|
||||||
|
|
||||||
|
# show the menu
|
||||||
source_object.execute_cmd('menu')
|
source_object.execute_cmd('menu')
|
||||||
|
|
||||||
#
|
#
|
||||||
# Commands only available while in the 'menu' state. Note that
|
# Below are commands only available while in the 'menu' state.
|
||||||
# these have auto_help, so the __doc__ strings of the functions
|
# Note that the _doc__ strings of the functions
|
||||||
# can be read as help entries when in the menu.
|
# can be read as help entries when in the menu.
|
||||||
#
|
#
|
||||||
def menu_cmd_option1(command):
|
def menu_cmd_option1(command):
|
||||||
|
|
@ -79,6 +97,7 @@ def menu_cmd_option1(command):
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
print_menu(source_object, 1)
|
print_menu(source_object, 1)
|
||||||
|
|
||||||
def menu_cmd_option2(command):
|
def menu_cmd_option2(command):
|
||||||
"""
|
"""
|
||||||
option2
|
option2
|
||||||
|
|
@ -86,13 +105,20 @@ def menu_cmd_option2(command):
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
print_menu(source_object, 2)
|
print_menu(source_object, 2)
|
||||||
|
|
||||||
def menu_cmd_menu(command):
|
def menu_cmd_menu(command):
|
||||||
"""
|
"""
|
||||||
menu
|
menu
|
||||||
|
|
||||||
Clears the options and redraws the menu.
|
Clears the options and redraws the menu.
|
||||||
|
|
||||||
[[autohelp]]
|
[[autohelp]]
|
||||||
|
|
||||||
|
Auto-help
|
||||||
|
|
||||||
This is an extra topic to test the auto-help functionality. The state-help
|
This is an extra topic to test the auto-help functionality. The state-help
|
||||||
system supports nested ('related') topics just like the normal help index does.
|
system supports nested ('related') topics using [ [subtopic] ] markup,
|
||||||
|
just like the normal help index does.
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
print_menu(source_object)
|
print_menu(source_object)
|
||||||
|
|
@ -100,61 +126,50 @@ def menu_cmd_menu(command):
|
||||||
#
|
#
|
||||||
# helper function
|
# helper function
|
||||||
#
|
#
|
||||||
def print_menu(source_obj,choice=None):
|
def print_menu(source_obj, choice=None):
|
||||||
"""
|
"""
|
||||||
Utility function to print the menu. More interesting things
|
Utility function to print the menu. More interesting things
|
||||||
would happen here in a real menu.
|
would happen here in a real menu.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if choice==1:
|
if choice == 1:
|
||||||
ch = "%s> option1\n %soption2" % ('%ch%cy','%cn%cy') #ansi colouring; see src.ansi
|
#ansi colouring; see src.ansi
|
||||||
elif choice==2:
|
chtext = "%s> option1\n %soption2" % ('%ch%cy','%cn%cy')
|
||||||
ch = " %soption1\n%s> option2" % ('%cn%cy','%ch%cy')
|
elif choice == 2:
|
||||||
|
chtext = " %soption1\n%s> option2" % ('%cn%cy','%ch%cy')
|
||||||
else:
|
else:
|
||||||
ch = " %soption1\n option2" % ('%cn%cy')
|
chtext = " %soption1\n option2" % ('%cn%cy')
|
||||||
|
|
||||||
s ="\n%sMenu: \n%s\n %shelp" % ('%ch%cr',ch,'%cn%cy')
|
string ="\n%sMenu: \n%s\n %shelp \n @exit" % ('%ch%cr', chtext, '%cn%cy')
|
||||||
source_obj.emit_to(s)
|
source_obj.emit_to(string)
|
||||||
|
|
||||||
#Add the 'entry' command to the normal command table
|
# Add the 'entry' command to the normal command table
|
||||||
GLOBAL_CMD_TABLE.add_command("entermenu", cmd_entermenu)
|
GLOBAL_CMD_TABLE.add_command("entermenu", cmd_entermenu)
|
||||||
|
|
||||||
#create the state.
|
# create the state. We make sure the player can exit it at
|
||||||
GLOBAL_STATE_TABLE.add_state(STATENAME,exit_command=True)
|
# any time by @exit.
|
||||||
|
GLOBAL_STATE_TABLE.add_state(STATENAME, exit_command=True)
|
||||||
|
|
||||||
#Add the menu commands to the state table by tying them to the 'menu' state. It is
|
# Add the menu commands to the state table by tying them to the 'menu'
|
||||||
#important that the name of the state matches what we set the player-object to in
|
# state. It is important that the name of the state matches what we
|
||||||
#the 'entry' command.
|
# set the player-object to in the 'entry' command.
|
||||||
GLOBAL_STATE_TABLE.add_command(STATENAME, "option1", menu_cmd_option1)
|
GLOBAL_STATE_TABLE.add_command(STATENAME, "option1", menu_cmd_option1)
|
||||||
GLOBAL_STATE_TABLE.add_command(STATENAME, "option2", menu_cmd_option2)
|
GLOBAL_STATE_TABLE.add_command(STATENAME, "option2", menu_cmd_option2)
|
||||||
GLOBAL_STATE_TABLE.add_command(STATENAME, "menu", menu_cmd_menu)
|
GLOBAL_STATE_TABLE.add_command(STATENAME, "menu", menu_cmd_menu)
|
||||||
|
|
||||||
#-----------------------testing the depth of the state system
|
|
||||||
# This is a test suite that shows off all the features of the state system.
|
|
||||||
# It sets up a test command @test_state that takes an argument 1-6 for moving into states
|
|
||||||
# with different characteristics. Note that the only difference as to how the
|
|
||||||
# various states are created lies in the options given to the add_state() function.
|
|
||||||
# Use @exit to leave any state.
|
|
||||||
#
|
|
||||||
# All states includes a small test function named "test".
|
|
||||||
# 1: A very limited state; only contains the "test" command.
|
|
||||||
# 2: All global commands are included (so this should be the same as normal operation,
|
|
||||||
# except you cannot traverse exits and use object-based cmds)
|
|
||||||
# 3: Only the global commands "get" and "inventory" are included into the state.
|
|
||||||
# 4: All global commands /except/ "get" and "inventory" are available
|
|
||||||
# 5: All global commands availabe + ability to traverse exits (not use object-based cmds).
|
|
||||||
# 6: Only the "test" command, but ability to both traverse exits and use object-based cmds.
|
|
||||||
#
|
|
||||||
# Examples of in-game use:
|
|
||||||
# 1: was used for the menu system above.
|
|
||||||
# 2: could be used in order to stop someone from moving despite exits being open (tied up?)
|
|
||||||
# 3: someone incapacitated or blinded might get only limited commands available
|
|
||||||
# 4: in e.g. a combat state, things like crafting should not be possible
|
|
||||||
# 5: Pretty much default operation, maybe limiting the use of magical weapons in a room etc?
|
|
||||||
# 6: A state of panic? You can move, but not take in your surroundings?
|
|
||||||
# ... the possibilities are endless.
|
|
||||||
|
|
||||||
#defining the test-state names so they are the same everywhere
|
#
|
||||||
|
# enterstate - testing the depth of the state system
|
||||||
|
#
|
||||||
|
|
||||||
|
# This is a test suite that shows off all the features of the state
|
||||||
|
# system. It sets up a test command @test_state that takes an
|
||||||
|
# argument 1-6 for moving into states with different
|
||||||
|
# characteristics. Note that the only difference as to how the various
|
||||||
|
# states are created lies in the options given to the add_state()
|
||||||
|
# function. Use @exit to leave any state.
|
||||||
|
|
||||||
|
# defining the test-state names so they are the same everywhere
|
||||||
TSTATE1 = 'no_globals'
|
TSTATE1 = 'no_globals'
|
||||||
TSTATE2 = 'all_globals'
|
TSTATE2 = 'all_globals'
|
||||||
TSTATE3 = 'include_some_globals'
|
TSTATE3 = 'include_some_globals'
|
||||||
|
|
@ -163,83 +178,153 @@ TSTATE5 = 'global_allow_exits'
|
||||||
TSTATE6 = 'noglobal_allow_exits_obj_cmds'
|
TSTATE6 = 'noglobal_allow_exits_obj_cmds'
|
||||||
|
|
||||||
#
|
#
|
||||||
#the test command @test_state
|
#the test command 'enterstate'
|
||||||
#
|
#
|
||||||
def cmd_test_state(command):
|
def cmd_test_state(command):
|
||||||
"testing the new state system"
|
"""
|
||||||
|
enterstate - testing the state system
|
||||||
|
|
||||||
|
Usage: enterstate [1 - 6]
|
||||||
|
|
||||||
|
Give arguments 1..6 to enter different game states. Use @exit to
|
||||||
|
get out of the state at any time.
|
||||||
|
|
||||||
|
1: A very limited state; only contains the 'test' state command.
|
||||||
|
2: All global commands are included (so this should be the same as
|
||||||
|
normal operation, except you cannot traverse exits and use
|
||||||
|
object-based cmds)
|
||||||
|
3: /Only/ the global commands 'get' and 'inventory' are included
|
||||||
|
into the state.
|
||||||
|
4: All global commands /except/ 'get' and 'inventory' are available
|
||||||
|
5: All global commands availabe + ability to traverse exits (not use
|
||||||
|
object-based cmds).
|
||||||
|
6: Only the 'test' command available, but ability to
|
||||||
|
both traverse exits and use object-based cmds.
|
||||||
|
|
||||||
|
Ideas for in-game use:
|
||||||
|
1: Try out the 'entermenu' command for an example of this state.
|
||||||
|
2: Could be used in order to stop someone from moving despite exits
|
||||||
|
being open (tied up? In combat?)
|
||||||
|
3: someone incapacitated or blinded might get only limited commands
|
||||||
|
available
|
||||||
|
4: in e.g. a combat state, things like crafting should not be
|
||||||
|
possible
|
||||||
|
5: Pretty much default operation, just removing some global commands.
|
||||||
|
Maybe limiting the use of magical weapons in a room or similar.
|
||||||
|
6: A state of panic - You can move, but not take in your surroundings.
|
||||||
|
|
||||||
|
... the possibilities are endless.
|
||||||
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
args = command.command_argument
|
args = command.command_argument
|
||||||
|
# check for missing arguments
|
||||||
if not args:
|
if not args:
|
||||||
source_object.emit_to("Usage: enterstate 1 - 6")
|
source_object.emit_to("Usage: enterstate [1 - 6]")
|
||||||
return
|
return
|
||||||
s = "\n Entering state ... \nThis state includes the commands 'test', 'help', '@exit' and "
|
# build up a return string
|
||||||
|
string = "\n Entering state ... \nThis state includes the"
|
||||||
|
string += " commands 'test', 'help', '@exit' and "
|
||||||
arg = args.strip()
|
arg = args.strip()
|
||||||
if arg=='1':
|
|
||||||
s += "no global commands at all. With some more state commands, this state would work well for e.g. a combat state or a menu where the player don't need access to the normal command definitions. Take a special look at the help command, which is in fact a state-only version of the normal help."
|
# step through the various options
|
||||||
|
if arg == '1':
|
||||||
|
string += "no global commands at all. \nWith some more state commands, "
|
||||||
|
string += "this state would work well for e.g. a "
|
||||||
|
string += "combat state or a menu where the player don't need access "
|
||||||
|
string += "to the normal command definitions. Take a special "
|
||||||
|
string += "look at the help command, which is in fact a "
|
||||||
|
string += "state-only version of the normal help."
|
||||||
state = TSTATE1
|
state = TSTATE1
|
||||||
elif arg=='2':
|
elif arg == '2':
|
||||||
s += "all global commands. You should be able to do everything as normal, but not move around."
|
string += "all global commands. You should be able to do "
|
||||||
|
string += "everything as normal, but not move around."
|
||||||
state = TSTATE2
|
state = TSTATE2
|
||||||
elif arg=='3':
|
elif arg == '3':
|
||||||
s += "the global commands 'inv' and 'get' only."
|
string += "the global commands 'inv' and 'get' only."
|
||||||
state = TSTATE3
|
state = TSTATE3
|
||||||
elif arg=='4':
|
elif arg == '4':
|
||||||
s += "all global commands *except* 'inv' and 'get' (try using them). This allows you to disable commands that should not be possible at a certain time (like starting to craft while in a fight or something)."
|
string += "all global commands *except* 'inv' and 'get' (try "
|
||||||
|
string += "using them). \nThis allows you to disable commands that "
|
||||||
|
string += "should not be possible at a certain time (like starting "
|
||||||
|
string += "to craft while in the middle of a fight or something)."
|
||||||
state = TSTATE4
|
state = TSTATE4
|
||||||
elif arg=='5':
|
elif arg == '5':
|
||||||
s += "all global commands as well as the ability to traverse exits. You do not have the ability to use commands defined on objects though."
|
string += "all global commands as well as the ability to traverse "
|
||||||
|
string += "exits. You do not have the ability to use commands "
|
||||||
|
string += "defined on objects though."
|
||||||
state = TSTATE5
|
state = TSTATE5
|
||||||
elif arg=='6':
|
elif arg == '6':
|
||||||
s += "no globals at all, but you have the ability to both use exits and commands on items. This would maybe be interesting for a 'total darkness' state or maybe a 'panic' state where you can move around but cannot actually take in your surroundings."
|
string += "no globals at all, but you have the ability to both "
|
||||||
|
string += "use exits and commands on items. \nThis would maybe be "
|
||||||
|
string += "interesting for a 'total darkness' state or maybe a "
|
||||||
|
string += "'panic' state where you can move around but cannot "
|
||||||
|
string += "actually take in your surroundings."
|
||||||
state = TSTATE6
|
state = TSTATE6
|
||||||
else:
|
else:
|
||||||
source_object.emit_to("Usage: enterstate 1 - 6")
|
source_object.emit_to("Usage: enterstate 1 - 6")
|
||||||
return
|
return
|
||||||
#set the state
|
#set the state
|
||||||
source_object.set_state(state)
|
source_object.set_state(state)
|
||||||
source_object.emit_to("%s\n (Now in state %s: '%s' ... use @exit to leave the state.)" % (s,arg,state))
|
info = "%s\n (Now in state %s: '%s' ... use @exit to leave the state.)"
|
||||||
|
source_object.emit_to(info % (string, arg, state))
|
||||||
#a simple command to include in all states.
|
#
|
||||||
|
# define a simple command to include in all states.
|
||||||
|
#
|
||||||
def cmd_instate_cmd(command):
|
def cmd_instate_cmd(command):
|
||||||
"""
|
"""
|
||||||
This is the help text for the test command (created with the auto_help sytem).
|
test
|
||||||
This is a state-only command that does not exist outside this state. Since this state
|
|
||||||
is completely isolated from the normal gameplay, commands can also
|
Usage:
|
||||||
harmlessly redefine any normal command - so if there was a normal command named
|
test
|
||||||
|
|
||||||
|
This is the help text for the test command (created with the
|
||||||
|
auto_help sytem). This is a state-only command that does not
|
||||||
|
exist outside this state. Since this state is completely isolated
|
||||||
|
from the normal gameplay, commands can also harmlessly redefine
|
||||||
|
any normal command - so if there was a normal command named
|
||||||
'test', it would remain unchanged when we leave the state.
|
'test', it would remain unchanged when we leave the state.
|
||||||
"""
|
"""
|
||||||
command.source_object.emit_to("This state command works!")
|
command.source_object.emit_to("This state command (test) works!")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create the test states
|
||||||
|
#
|
||||||
|
|
||||||
#define some global commands to filter for
|
#define some global commands to filter for
|
||||||
cmdfilter = ['get','inventory']
|
CMDFILTER = ['get', 'inventory']
|
||||||
|
|
||||||
|
#1: A simple, basic state with no global commands
|
||||||
|
GLOBAL_STATE_TABLE.add_state(TSTATE1, exit_command=True)
|
||||||
|
|
||||||
#1: A simple, basic state
|
|
||||||
GLOBAL_STATE_TABLE.add_state(TSTATE1,exit_command=True)
|
|
||||||
#2: Include all normal commands in the state
|
#2: Include all normal commands in the state
|
||||||
GLOBAL_STATE_TABLE.add_state(TSTATE2,exit_command=True,global_cmds='all')
|
GLOBAL_STATE_TABLE.add_state(TSTATE2, exit_command=True, global_cmds='all')
|
||||||
|
|
||||||
#3: Include only the two global commands in cmdfilter
|
#3: Include only the two global commands in cmdfilter
|
||||||
GLOBAL_STATE_TABLE.add_state(TSTATE3,exit_command=True,
|
GLOBAL_STATE_TABLE.add_state(TSTATE3, exit_command=True,
|
||||||
global_cmds='include',global_filter=cmdfilter)
|
global_cmds='include', global_filter=CMDFILTER)
|
||||||
|
|
||||||
#4: Include all global commands except the ones in cmdfilter
|
#4: Include all global commands except the ones in cmdfilter
|
||||||
GLOBAL_STATE_TABLE.add_state(TSTATE4,exit_command=True,
|
GLOBAL_STATE_TABLE.add_state(TSTATE4, exit_command=True,
|
||||||
global_cmds='exclude',global_filter=cmdfilter)
|
global_cmds='exclude', global_filter=CMDFILTER)
|
||||||
|
|
||||||
#5: Include all global commands + ability to traverse exits
|
#5: Include all global commands + ability to traverse exits
|
||||||
GLOBAL_STATE_TABLE.add_state(TSTATE5,exit_command=True,
|
GLOBAL_STATE_TABLE.add_state(TSTATE5, exit_command=True,
|
||||||
global_cmds='all',
|
global_cmds='all',
|
||||||
allow_exits=True)
|
allow_exits=True)
|
||||||
|
|
||||||
#6: No global commands, allow exits and commands defined on objects.
|
#6: No global commands, allow exits and commands defined on objects.
|
||||||
GLOBAL_STATE_TABLE.add_state(TSTATE6,exit_command=True,
|
GLOBAL_STATE_TABLE.add_state(TSTATE6, exit_command=True,
|
||||||
allow_exits=True,allow_obj_cmds=True)
|
allow_exits=True, allow_obj_cmds=True)
|
||||||
|
|
||||||
#append the "test" function to all states
|
#append the "test" function to all states
|
||||||
GLOBAL_STATE_TABLE.add_command(TSTATE1,'test',cmd_instate_cmd)
|
GLOBAL_STATE_TABLE.add_command(TSTATE1, 'test', cmd_instate_cmd)
|
||||||
GLOBAL_STATE_TABLE.add_command(TSTATE2,'test',cmd_instate_cmd)
|
GLOBAL_STATE_TABLE.add_command(TSTATE2, 'test', cmd_instate_cmd)
|
||||||
GLOBAL_STATE_TABLE.add_command(TSTATE3,'test',cmd_instate_cmd)
|
GLOBAL_STATE_TABLE.add_command(TSTATE3, 'test', cmd_instate_cmd)
|
||||||
GLOBAL_STATE_TABLE.add_command(TSTATE4,'test',cmd_instate_cmd)
|
GLOBAL_STATE_TABLE.add_command(TSTATE4, 'test', cmd_instate_cmd)
|
||||||
GLOBAL_STATE_TABLE.add_command(TSTATE5,'test',cmd_instate_cmd)
|
GLOBAL_STATE_TABLE.add_command(TSTATE5, 'test', cmd_instate_cmd)
|
||||||
GLOBAL_STATE_TABLE.add_command(TSTATE6,'test',cmd_instate_cmd)
|
GLOBAL_STATE_TABLE.add_command(TSTATE6, 'test', cmd_instate_cmd)
|
||||||
|
|
||||||
#create the entry function for testing all states
|
#create the entry function for testing all states
|
||||||
GLOBAL_CMD_TABLE.add_command('enterstate',cmd_test_state)
|
GLOBAL_CMD_TABLE.add_command('enterstate', cmd_test_state)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ This is the base object type/interface that all parents are derived from by
|
||||||
default. Each object type sub-classes this class and over-rides methods as
|
default. Each object type sub-classes this class and over-rides methods as
|
||||||
needed.
|
needed.
|
||||||
|
|
||||||
NOTE: This file should NOT be directly modified. Sub-class the BasicObject
|
NOTE: This file should NOT be directly modified. Sub-class this in
|
||||||
class in game/gamesrc/parents/base/basicobject.py and change the
|
your own class in game/gamesrc/parents and change
|
||||||
SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class.
|
SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class.
|
||||||
"""
|
"""
|
||||||
from src.script_parents.basicobject import EvenniaBasicObject
|
from src.script_parents.basicobject import EvenniaBasicObject
|
||||||
|
|
@ -18,5 +18,10 @@ def class_factory(source_obj):
|
||||||
creates an instance of the class and returns it transparently.
|
creates an instance of the class and returns it transparently.
|
||||||
|
|
||||||
source_obj: (Object) A reference to the object being scripted (the child).
|
source_obj: (Object) A reference to the object being scripted (the child).
|
||||||
|
|
||||||
|
Since this is the only place where the object is actually instantiated,
|
||||||
|
this is also the place to put commands you want to act on this object,
|
||||||
|
do this by obj.command_table.add_command('cmd', cmd_def).
|
||||||
"""
|
"""
|
||||||
return BasicObject(source_obj)
|
obj = BasicObject(source_obj)
|
||||||
|
return obj
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
This is the basic Evennia-standard player parent.
|
This is the basic Evennia-standard player parent.
|
||||||
|
|
||||||
NOTE: This file should NOT be directly modified. Sub-class the BasicPlayer
|
NOTE: This file should NOT be directly modified. Sub-class the BasicPlayer
|
||||||
class in game/gamesrc/parents/base/basicplayer.py and change the
|
class in your own class in game/gamesrc/parents and change the
|
||||||
SCRIPT_DEFAULT_PLAYER variable in settings.py to point to the new class.
|
SCRIPT_DEFAULT_PLAYER variable in settings.py to point to the new class.
|
||||||
"""
|
"""
|
||||||
from src.script_parents.basicobject import EvenniaBasicObject
|
from src.script_parents.basicobject import EvenniaBasicObject
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,15 @@ gamesrc/parents and set SCRIPT_DEFAULT_OBJECT = 'custom_basicobject'
|
||||||
in game/settings.py.
|
in game/settings.py.
|
||||||
|
|
||||||
Generally, if you want to conveniently set future objects to inherit from this
|
Generally, if you want to conveniently set future objects to inherit from this
|
||||||
script parent, this files and others like it need to be
|
script parent, this file and others like it need to be
|
||||||
located under the game/gamesrc/parent directory.
|
located under the game/gamesrc/parent directory.
|
||||||
"""
|
"""
|
||||||
from game.gamesrc.parents.base.basicobject import BasicObject
|
from game.gamesrc.parents.base.basicobject import BasicObject
|
||||||
|
|
||||||
class CustomBasicObject(BasicObject):
|
class CustomBasicObject(BasicObject):
|
||||||
|
"""
|
||||||
|
This defines the base class of all non-player objects in game.
|
||||||
|
"""
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
"""
|
"""
|
||||||
This function is called whenever the object is created. Use
|
This function is called whenever the object is created. Use
|
||||||
|
|
@ -31,7 +33,7 @@ class CustomBasicObject(BasicObject):
|
||||||
show_dbref=False,
|
show_dbref=False,
|
||||||
show_flags=False)
|
show_flags=False)
|
||||||
#assign the name to the new attribute
|
#assign the name to the new attribute
|
||||||
obj.set_attribute('sdesc',name)
|
obj.set_attribute('sdesc', name)
|
||||||
|
|
||||||
def at_object_destruction(self, pobject=None):
|
def at_object_destruction(self, pobject=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,17 @@ This is an example of customizing the basic player character object.
|
||||||
You will want to do this to add all sorts of custom things like
|
You will want to do this to add all sorts of custom things like
|
||||||
attributes, skill values, injuries and so on.
|
attributes, skill values, injuries and so on.
|
||||||
|
|
||||||
If you want to make this the default player object for all players, move it
|
If you want to make this the default player object for all players,
|
||||||
into gamesrc/parents and set SCRIPT_DEFAULT_PLAYER = 'custom_basicplayer'
|
move it into gamesrc/parents and set SCRIPT_DEFAULT_PLAYER =
|
||||||
in game/settings.py.
|
'custom_basicplayer' in game/settings.py.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from game.gamesrc.parents.base.basicplayer import BasicPlayer
|
from game.gamesrc.parents.base.basicplayer import BasicPlayer
|
||||||
|
|
||||||
class CustomBasicPlayer(BasicPlayer):
|
class CustomBasicPlayer(BasicPlayer):
|
||||||
|
"""
|
||||||
|
This is the base class for all players in game.
|
||||||
|
"""
|
||||||
def at_player_creation(self):
|
def at_player_creation(self):
|
||||||
"""
|
"""
|
||||||
Called when player object is first created. Use this
|
Called when player object is first created. Use this
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,16 @@ test button you must drop it before you will see its messages!
|
||||||
"""
|
"""
|
||||||
from game.gamesrc.parents.base.basicobject import BasicObject
|
from game.gamesrc.parents.base.basicobject import BasicObject
|
||||||
|
|
||||||
#you have to import the event definition(s) from somewhere covered by @reload,
|
# you have to import the event definition(s) from somewhere
|
||||||
# - this is as good a place as any.
|
# covered by @reload, and this is as good a place as any.
|
||||||
|
# Doing this will start the event ticking.
|
||||||
|
|
||||||
import game.gamesrc.events.example
|
import game.gamesrc.events.example
|
||||||
|
|
||||||
#
|
#
|
||||||
#commands on the button object
|
# commands for using the button object. These are added to
|
||||||
|
# the object in the class_factory function at the
|
||||||
|
# bottom of this module.
|
||||||
#
|
#
|
||||||
|
|
||||||
def cmd_push_button(command):
|
def cmd_push_button(command):
|
||||||
|
|
@ -40,26 +44,17 @@ def cmd_pull_button(command):
|
||||||
command.source_object.emit_to(retval)
|
command.source_object.emit_to(retval)
|
||||||
|
|
||||||
#
|
#
|
||||||
#The object itself
|
# Definition of the object itself
|
||||||
#
|
#
|
||||||
|
|
||||||
class RedButton(BasicObject):
|
class RedButton(BasicObject):
|
||||||
|
"""
|
||||||
def __init__(self, scripted_obj, *args, **kwargs):
|
This class describes an evil red button.
|
||||||
"""
|
It will use the event definition in
|
||||||
This is called when class_factory() instantiates a temporary instance
|
game/gamesrc/events/example.py to blink
|
||||||
of the script parent. This is typically not something you want to
|
at regular intervals until the lightbulb
|
||||||
mess with much.
|
breaks.
|
||||||
"""
|
"""
|
||||||
# Calling the super class' __init__ is critical! Never forget to do
|
|
||||||
# this or everything else from here on out will fail.
|
|
||||||
super(RedButton, self).__init__(scripted_obj, args, kwargs)
|
|
||||||
# Add the commands to the object's command table (this is about
|
|
||||||
#the only thing you should use the __init__ for).
|
|
||||||
self.command_table.add_command("pushbutton", cmd_push_button)
|
|
||||||
self.command_table.add_command("pullbutton", cmd_pull_button)
|
|
||||||
|
|
||||||
|
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
"""
|
"""
|
||||||
This function is called when object is created. Use this
|
This function is called when object is created. Use this
|
||||||
|
|
@ -73,9 +68,12 @@ class RedButton(BasicObject):
|
||||||
obj.set_attribute("count", 0)
|
obj.set_attribute("count", 0)
|
||||||
|
|
||||||
def blink(self):
|
def blink(self):
|
||||||
"""If the event system is active, it will regularly call this function to make
|
"""
|
||||||
the button blink. Note the use of attributes to store the variable count and
|
If the event system is active, it will regularly call this
|
||||||
breakpoint in a persistent way."""
|
function to make the button blink. Note the use of attributes
|
||||||
|
to store the variable count and breakpoint in a persistent
|
||||||
|
way.
|
||||||
|
"""
|
||||||
obj = self.scripted_obj
|
obj = self.scripted_obj
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -86,13 +84,13 @@ class RedButton(BasicObject):
|
||||||
|
|
||||||
if count <= breakpoint:
|
if count <= breakpoint:
|
||||||
if int(count) == int(breakpoint):
|
if int(count) == int(breakpoint):
|
||||||
s = "The button flashes, then goes dark. "
|
string = "The button flashes, then goes dark. "
|
||||||
s += "Looks like the lamp just broke."
|
string += "Looks like the lamp just broke."
|
||||||
else:
|
else:
|
||||||
s = "The red button flashes, demanding your attention."
|
string = "The red button flashes, demanding your attention."
|
||||||
count += 1
|
count += 1
|
||||||
obj.set_attribute("count",count)
|
obj.set_attribute("count", count)
|
||||||
obj.get_location().emit_to_contents(s)
|
obj.get_location().emit_to_contents(string)
|
||||||
|
|
||||||
def class_factory(source_obj):
|
def class_factory(source_obj):
|
||||||
"""
|
"""
|
||||||
|
|
@ -100,6 +98,12 @@ def class_factory(source_obj):
|
||||||
creates an instance of the class and returns it transparently.
|
creates an instance of the class and returns it transparently.
|
||||||
|
|
||||||
source_obj: (Object) A reference to the object being scripted (the child).
|
source_obj: (Object) A reference to the object being scripted (the child).
|
||||||
"""
|
|
||||||
return RedButton(source_obj)
|
|
||||||
|
|
||||||
|
This is a good place for adding new commands to the button since this is
|
||||||
|
where it is actually instantiated.
|
||||||
|
"""
|
||||||
|
button = RedButton(source_obj)
|
||||||
|
# add the object-based commands to the button
|
||||||
|
button.command_table.add_command("pushbutton", cmd_push_button)
|
||||||
|
button.command_table.add_command("pullbutton", cmd_pull_button)
|
||||||
|
return button
|
||||||
|
|
|
||||||
|
|
@ -221,10 +221,10 @@ class EditHelp(object):
|
||||||
|
|
||||||
# identify markup and do nice formatting as well as eventual
|
# identify markup and do nice formatting as well as eventual
|
||||||
# related entries to the help entries.
|
# related entries to the help entries.
|
||||||
logger.log_infomsg("auto-help in: %s %s %s %s" % (topicstr, category, entrytext, permissions))
|
#logger.log_infomsg("auto-help in: %s %s %s %s" % (topicstr, category, entrytext, permissions))
|
||||||
topics = self.format_help_entry(topicstr, category,
|
topics = self.format_help_entry(topicstr, category,
|
||||||
entrytext, permissions)
|
entrytext, permissions)
|
||||||
logger.log_infomsg("auto-help: %s -> %s" % (topicstr,topics))
|
#logger.log_infomsg("auto-help: %s -> %s" % (topicstr,topics))
|
||||||
# create the help entries:
|
# create the help entries:
|
||||||
if topics:
|
if topics:
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
|
|
|
||||||
|
|
@ -891,8 +891,7 @@ class Object(models.Model):
|
||||||
script_parent: (string) String pythonic import path of the script parent
|
script_parent: (string) String pythonic import path of the script parent
|
||||||
assuming the python path is game/gamesrc/parents.
|
assuming the python path is game/gamesrc/parents.
|
||||||
"""
|
"""
|
||||||
if script_parent != None and scripthandler.scriptlink(self,
|
if script_parent != None and scripthandler.scriptlink(self, str(script_parent).strip()):
|
||||||
str(script_parent).strip()):
|
|
||||||
#assigning a custom parent
|
#assigning a custom parent
|
||||||
self.script_parent = str(script_parent).strip()
|
self.script_parent = str(script_parent).strip()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,6 @@ class StateTable(object):
|
||||||
special conditions or clean-up operations before allowing a player
|
special conditions or clean-up operations before allowing a player
|
||||||
to exit (e.g. combat states and text editors), in which case this
|
to exit (e.g. combat states and text editors), in which case this
|
||||||
feature should be turned off and handled by custom exit commands.
|
feature should be turned off and handled by custom exit commands.
|
||||||
help_command
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
state_name = state_name.strip()
|
state_name = state_name.strip()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue