Updated the game template, renaming subdir typeclasses rather than types since the latter collides with the python library module of the same name.
This commit is contained in:
parent
3fbc9acc51
commit
c96c5a1fc7
112 changed files with 456 additions and 229 deletions
0
game_template/typeclasses/__init__.py
Normal file
0
game_template/typeclasses/__init__.py
Normal file
31
game_template/typeclasses/character.py
Normal file
31
game_template/typeclasses/character.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
Characters
|
||||
|
||||
Characters are (by default) Objects setup to be puppeted by Players.
|
||||
They are what you "see" in game. The Character class in this module
|
||||
is setup to be the "default" character type created by the default
|
||||
creation commands.
|
||||
|
||||
"""
|
||||
from evennia import DefaultCharacter
|
||||
|
||||
class Character(DefaultCharacter):
|
||||
"""
|
||||
The Character defaults to implementing some of its hook methods with the
|
||||
following standard functionality:
|
||||
|
||||
at_basetype_setup - always assigns the DefaultCmdSet to this object type
|
||||
(important!)sets locks so character cannot be picked up
|
||||
and its commands only be called by itself, not anyone else.
|
||||
(to change things, use at_object_creation() instead)
|
||||
at_after_move - launches the "look" command
|
||||
at_post_puppet(player) - when Player disconnects from the Character, we
|
||||
store the current location, so the "unconnected" character
|
||||
object does not need to stay on grid but can be given a
|
||||
None-location while offline.
|
||||
at_pre_puppet - just before Player re-connects, retrieves the character's
|
||||
old location and puts it back on the grid with a "charname
|
||||
has connected" message echoed to the room
|
||||
|
||||
"""
|
||||
pass
|
||||
34
game_template/typeclasses/exit.py
Normal file
34
game_template/typeclasses/exit.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
Exits
|
||||
|
||||
Exits are connectors between Rooms. An exit always has a destination property
|
||||
set and has a single command defined on itself with the same name as its key,
|
||||
for allowing Characters to traverse the exit to its destination.
|
||||
|
||||
"""
|
||||
from evennia import DefaultExit
|
||||
|
||||
class Exit(DefaultExit):
|
||||
"""
|
||||
Exits are connectors between rooms. Exits are normal Objects except
|
||||
they defines the 'destination' property. It also does work in the
|
||||
following methods:
|
||||
|
||||
basetype_setup() - sets default exit locks (to change, use at_object_creation instead)
|
||||
at_cmdset_get(**kwargs) - this is called when the cmdset is accessed and should
|
||||
rebuild the Exit cmdset along with a command matching the name
|
||||
of the Exit object. Conventionally, a kwarg 'force_init'
|
||||
should force a rebuild of the cmdset, this is triggered
|
||||
by the @alias command when aliases are changed.
|
||||
at_failed_traverse() - gives a default error message ("You cannot
|
||||
go there") if exit traversal fails and an
|
||||
attribute err_traverse is not defined.
|
||||
|
||||
Relevant hooks to overload (compared to other types of Objects):
|
||||
at_before_traverse(traveller) - called just before traversing
|
||||
at_after_traverse(traveller, source_loc) - called just after traversing
|
||||
at_failed_traverse(traveller) - called if traversal failed for some reason. Will
|
||||
not be called if the attribute 'err_traverse' is
|
||||
defined, in which case that will simply be echoed.
|
||||
"""
|
||||
pass
|
||||
157
game_template/typeclasses/object.py
Normal file
157
game_template/typeclasses/object.py
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
"""
|
||||
Object
|
||||
|
||||
The Object is the "naked" base class for things in the game world.
|
||||
|
||||
Note that the default Character, Room and Exit does not inherit from
|
||||
this Object, but from their respective default implementations in the
|
||||
evennia library. If you want to use this class as a parent to change
|
||||
the other types, you can do so by adding this as a multiple
|
||||
inheritance.
|
||||
|
||||
"""
|
||||
from evennia import DefaultObject
|
||||
|
||||
class Object(DefaultObject):
|
||||
"""
|
||||
This is the root typeclass object, implementing an in-game Evennia
|
||||
game object, such as having a location, being able to be
|
||||
manipulated or looked at, etc. If you create a new typeclass, it
|
||||
must always inherit from this object (or any of the other objects
|
||||
in this file, since they all actually inherit from BaseObject, as
|
||||
seen in src.object.objects).
|
||||
|
||||
The BaseObject class implements several hooks tying into the game
|
||||
engine. By re-implementing these hooks you can control the
|
||||
system. You should never need to re-implement special Python
|
||||
methods, such as __init__ and especially never __getattribute__ and
|
||||
__setattr__ since these are used heavily by the typeclass system
|
||||
of Evennia and messing with them might well break things for you.
|
||||
|
||||
|
||||
* Base properties defined/available on all Objects
|
||||
|
||||
key (string) - name of object
|
||||
name (string)- same as key
|
||||
aliases (list of strings) - aliases to the object. Will be saved to
|
||||
database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
back to this class
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
player (Player) - controlling player (if any, only set together with
|
||||
sessid below)
|
||||
sessid (int, read-only) - session id (if any, only set together with
|
||||
player above)
|
||||
location (Object) - current location. Is None if this is a room
|
||||
home (Object) - safety start-location
|
||||
sessions (list of Sessions, read-only) - returns all sessions connected
|
||||
to this object
|
||||
has_player (bool, read-only)- will only return *connected* players
|
||||
contents (list of Objects, read-only) - returns all objects inside this
|
||||
object (including exits)
|
||||
exits (list of Objects, read-only) - returns all exits from this
|
||||
object, if any
|
||||
destination (Object) - only set if this object is an exit.
|
||||
is_superuser (bool, read-only) - True/False if this user is a superuser
|
||||
|
||||
* Handlers available
|
||||
|
||||
locks - lock-handler: use locks.add() to add new lock strings
|
||||
db - attribute-handler: store/retrieve database attributes on this
|
||||
self.db.myattr=val, val=self.db.myattr
|
||||
ndb - non-persistent attribute handler: same as db but does not create
|
||||
a database entry when storing data
|
||||
scripts - script-handler. Add new scripts to object with scripts.add()
|
||||
cmdset - cmdset-handler. Use cmdset.add() to add new cmdsets to object
|
||||
nicks - nick-handler. New nicks with nicks.add().
|
||||
|
||||
* Helper methods (see src.objects.objects.py for full headers)
|
||||
|
||||
search(ostring, global_search=False, attribute_name=None,
|
||||
use_nicks=False, location=None, ignore_errors=False, player=False)
|
||||
execute_cmd(raw_string)
|
||||
msg(text=None, **kwargs)
|
||||
msg_contents(message, exclude=None, from_obj=None, **kwargs)
|
||||
move_to(destination, quiet=False, emit_to_obj=None, use_destination=True)
|
||||
copy(new_key=None)
|
||||
delete()
|
||||
is_typeclass(typeclass, exact=False)
|
||||
swap_typeclass(new_typeclass, clean_attributes=False, no_default=True)
|
||||
access(accessing_obj, access_type='read', default=False)
|
||||
check_permstring(permstring)
|
||||
|
||||
* Hooks (these are class methods, so args should start with self):
|
||||
|
||||
basetype_setup() - only called once, used for behind-the-scenes
|
||||
setup. Normally not modified.
|
||||
basetype_posthook_setup() - customization in basetype, after the object
|
||||
has been created; Normally not modified.
|
||||
|
||||
at_object_creation() - only called once, when object is first created.
|
||||
Object customizations go here.
|
||||
at_object_delete() - called just before deleting an object. If returning
|
||||
False, deletion is aborted. Note that all objects
|
||||
inside a deleted object are automatically moved
|
||||
to their <home>, they don't need to be removed here.
|
||||
|
||||
at_init() - called whenever typeclass is cached from memory,
|
||||
at least once every server restart/reload
|
||||
at_cmdset_get(**kwargs) - this is called just before the command handler
|
||||
requests a cmdset from this object. The kwargs are
|
||||
not normally used unless the cmdset is created
|
||||
dynamically (see e.g. Exits).
|
||||
at_pre_puppet(player)- (player-controlled objects only) called just
|
||||
before puppeting
|
||||
at_post_puppet() - (player-controlled objects only) called just
|
||||
after completing connection player<->object
|
||||
at_pre_unpuppet() - (player-controlled objects only) called just
|
||||
before un-puppeting
|
||||
at_post_unpuppet(player) - (player-controlled objects only) called just
|
||||
after disconnecting player<->object link
|
||||
at_server_reload() - called before server is reloaded
|
||||
at_server_shutdown() - called just before server is fully shut down
|
||||
|
||||
at_access(result, accessing_obj, access_type) - called with the result
|
||||
of a lock access check on this object. Return value
|
||||
does not affect check result.
|
||||
|
||||
at_before_move(destination) - called just before moving object
|
||||
to the destination. If returns False, move is cancelled.
|
||||
announce_move_from(destination) - called in old location, just
|
||||
before move, if obj.move_to() has quiet=False
|
||||
announce_move_to(source_location) - called in new location, just
|
||||
after move, if obj.move_to() has quiet=False
|
||||
at_after_move(source_location) - always called after a move has
|
||||
been successfully performed.
|
||||
at_object_leave(obj, target_location) - called when an object leaves
|
||||
this object in any fashion
|
||||
at_object_receive(obj, source_location) - called when this object receives
|
||||
another object
|
||||
|
||||
at_before_traverse(traversing_object) - (exit-objects only)
|
||||
called just before an object traverses this object
|
||||
at_after_traverse(traversing_object, source_location) - (exit-objects only)
|
||||
called just after a traversal has happened.
|
||||
at_failed_traverse(traversing_object) - (exit-objects only) called if
|
||||
traversal fails and property err_traverse is not defined.
|
||||
|
||||
at_msg_receive(self, msg, from_obj=None, **kwargs) - called when a message
|
||||
(via self.msg()) is sent to this obj.
|
||||
If returns false, aborts send.
|
||||
at_msg_send(self, msg, to_obj=None, **kwargs) - called when this objects
|
||||
sends a message to someone via self.msg().
|
||||
|
||||
return_appearance(looker) - describes this object. Used by "look"
|
||||
command by default
|
||||
at_desc(looker=None) - called by 'look' whenever the
|
||||
appearance is requested.
|
||||
at_get(getter) - called after object has been picked up.
|
||||
Does not stop pickup.
|
||||
at_drop(dropper) - called when this object has been dropped.
|
||||
at_say(speaker, message) - by default, called if an object inside this
|
||||
object speaks
|
||||
|
||||
"""
|
||||
pass
|
||||
81
game_template/typeclasses/player.py
Normal file
81
game_template/typeclasses/player.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
"""
|
||||
Player
|
||||
|
||||
The Player represents the game "account" and each login has only one
|
||||
Player object. A Player is what chats on default channels but has no
|
||||
other in-game-world existance. Rather the Player puppets Objects (such
|
||||
as Characters) in order to actually participate in the game world.
|
||||
|
||||
"""
|
||||
|
||||
from evennia import DefaultPlayer
|
||||
|
||||
|
||||
class Player(DefaultPlayer):
|
||||
"""
|
||||
This class describes the actual OOC player (i.e. the user connecting
|
||||
to the MUD). It does NOT have visual appearance in the game world (that
|
||||
is handled by the character which is connected to this). Comm channels
|
||||
are attended/joined using this object.
|
||||
|
||||
It can be useful e.g. for storing configuration options for your game, but
|
||||
should generally not hold any character-related info (that's best handled
|
||||
on the character level).
|
||||
|
||||
Can be set using BASE_PLAYER_TYPECLASS.
|
||||
|
||||
|
||||
* available properties
|
||||
|
||||
key (string) - name of player
|
||||
name (string)- wrapper for user.username
|
||||
aliases (list of strings) - aliases to the object. Will be saved to database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
user (User, read-only) - django User authorization object
|
||||
obj (Object) - game object controlled by player. 'character' can also be used.
|
||||
sessions (list of Sessions) - sessions connected to this player
|
||||
is_superuser (bool, read-only) - if the connected user is a superuser
|
||||
|
||||
* Handlers
|
||||
|
||||
locks - lock-handler: use locks.add() to add new lock strings
|
||||
db - attribute-handler: store/retrieve database attributes on this self.db.myattr=val, val=self.db.myattr
|
||||
ndb - non-persistent attribute handler: same as db but does not create a database entry when storing data
|
||||
scripts - script-handler. Add new scripts to object with scripts.add()
|
||||
cmdset - cmdset-handler. Use cmdset.add() to add new cmdsets to object
|
||||
nicks - nick-handler. New nicks with nicks.add().
|
||||
|
||||
* Helper methods
|
||||
|
||||
msg(text=None, **kwargs)
|
||||
swap_character(new_character, delete_old_character=False)
|
||||
execute_cmd(raw_string, sessid=None)
|
||||
search(ostring, global_search=False, attribute_name=None, use_nicks=False, location=None, ignore_errors=False, player=False)
|
||||
is_typeclass(typeclass, exact=False)
|
||||
swap_typeclass(new_typeclass, clean_attributes=False, no_default=True)
|
||||
access(accessing_obj, access_type='read', default=False)
|
||||
check_permstring(permstring)
|
||||
|
||||
* Hook methods (when re-implementation, remember methods need to have self as first arg)
|
||||
|
||||
basetype_setup()
|
||||
at_player_creation()
|
||||
|
||||
- note that the following hooks are also found on Objects and are
|
||||
usually handled on the character level:
|
||||
|
||||
at_init()
|
||||
at_cmdset_get(**kwargs)
|
||||
at_first_login()
|
||||
at_post_login(sessid=None)
|
||||
at_disconnect()
|
||||
at_message_receive()
|
||||
at_message_send()
|
||||
at_server_reload()
|
||||
at_server_shutdown()
|
||||
|
||||
"""
|
||||
pass
|
||||
21
game_template/typeclasses/room.py
Normal file
21
game_template/typeclasses/room.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
"""
|
||||
Room
|
||||
|
||||
Rooms are simple containers that has no location of their own.
|
||||
|
||||
"""
|
||||
|
||||
from evennia import DefaultRoom
|
||||
|
||||
|
||||
class Room(DefaultRoom):
|
||||
"""
|
||||
Rooms are like any Object, except their location is None
|
||||
(which is default). They also use basetype_setup() to
|
||||
add locks so they cannot be puppeted or picked up.
|
||||
(to change that, use at_object_creation instead)
|
||||
|
||||
See examples/object.py for a list of
|
||||
properties and methods available on all Objects.
|
||||
"""
|
||||
pass
|
||||
91
game_template/typeclasses/script.py
Normal file
91
game_template/typeclasses/script.py
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
"""
|
||||
Scripts
|
||||
|
||||
Scripts are powerful jacks-of-all-trades. They have no in-game
|
||||
existence and can be used to represent persistent game systems in some
|
||||
circumstances. Scripts can also have a time component that allows them
|
||||
to "fire" regularly or a limited number of times.
|
||||
|
||||
There is generally no "tree" of Scripts inheriting from each other.
|
||||
Rather, each script tends to inherit from the base Script class and
|
||||
just overloads its hooks to have it perform its function.
|
||||
|
||||
"""
|
||||
|
||||
from evennia import Script
|
||||
|
||||
|
||||
class ExampleScript(Script):
|
||||
"""
|
||||
A script type is customized by redefining some or all of its hook
|
||||
methods and variables.
|
||||
|
||||
* available properties
|
||||
|
||||
key (string) - name of object
|
||||
name (string)- same as key
|
||||
aliases (list of strings) - aliases to the object. Will be saved
|
||||
to database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
desc (string) - optional description of script, shown in listings
|
||||
obj (Object) - optional object that this script is connected to
|
||||
and acts on (set automatically by obj.scripts.add())
|
||||
interval (int) - how often script should run, in seconds. <0 turns
|
||||
off ticker
|
||||
start_delay (bool) - if the script should start repeating right away or
|
||||
wait self.interval seconds
|
||||
repeats (int) - how many times the script should repeat before
|
||||
stopping. 0 means infinite repeats
|
||||
persistent (bool) - if script should survive a server shutdown or not
|
||||
is_active (bool) - if script is currently running
|
||||
|
||||
* Handlers
|
||||
|
||||
locks - lock-handler: use locks.add() to add new lock strings
|
||||
db - attribute-handler: store/retrieve database attributes on this
|
||||
self.db.myattr=val, val=self.db.myattr
|
||||
ndb - non-persistent attribute handler: same as db but does not
|
||||
create a database entry when storing data
|
||||
|
||||
* Helper methods
|
||||
|
||||
start() - start script (this usually happens automatically at creation
|
||||
and obj.script.add() etc)
|
||||
stop() - stop script, and delete it
|
||||
pause() - put the script on hold, until unpause() is called. If script
|
||||
is persistent, the pause state will survive a shutdown.
|
||||
unpause() - restart a previously paused script. The script will continue
|
||||
from the paused timer (but at_start() will be called).
|
||||
time_until_next_repeat() - if a timed script (interval>0), returns time
|
||||
until next tick
|
||||
|
||||
* Hook methods (should also include self as the first argument):
|
||||
|
||||
at_script_creation() - called only once, when an object of this
|
||||
class is first created.
|
||||
is_valid() - is called to check if the script is valid to be running
|
||||
at the current time. If is_valid() returns False, the running
|
||||
script is stopped and removed from the game. You can use this
|
||||
to check state changes (i.e. an script tracking some combat
|
||||
stats at regular intervals is only valid to run while there is
|
||||
actual combat going on).
|
||||
at_start() - Called every time the script is started, which for persistent
|
||||
scripts is at least once every server start. Note that this is
|
||||
unaffected by self.delay_start, which only delays the first
|
||||
call to at_repeat().
|
||||
at_repeat() - Called every self.interval seconds. It will be called
|
||||
immediately upon launch unless self.delay_start is True, which
|
||||
will delay the first call of this method by self.interval
|
||||
seconds. If self.interval==0, this method will never
|
||||
be called.
|
||||
at_stop() - Called as the script object is stopped and is about to be
|
||||
removed from the game, e.g. because is_valid() returned False.
|
||||
at_server_reload() - Called when server reloads. Can be used to
|
||||
save temporary variables you want should survive a reload.
|
||||
at_server_shutdown() - called at a full server shutdown.
|
||||
|
||||
"""
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue