Update prototype example module
This commit is contained in:
parent
b086e95e19
commit
c051d15f5c
3 changed files with 104 additions and 52 deletions
|
|
@ -2,40 +2,56 @@
|
|||
Prototypes
|
||||
|
||||
A prototype is a simple way to create individualized instances of a
|
||||
given `Typeclass`. For example, you might have a Sword typeclass that
|
||||
implements everything a Sword would need to do. The only difference
|
||||
between different individual Swords would be their key, description
|
||||
and some Attributes. The Prototype system allows to create a range of
|
||||
such Swords with only minor variations. Prototypes can also inherit
|
||||
and combine together to form entire hierarchies (such as giving all
|
||||
Sabres and all Broadswords some common properties). Note that bigger
|
||||
variations, such as custom commands or functionality belong in a
|
||||
hierarchy of typeclasses instead.
|
||||
given typeclass. It is dictionary with specific key names.
|
||||
|
||||
Example prototypes are read by the `@spawn` command but is also easily
|
||||
available to use from code via `evennia.spawn` or `evennia.utils.spawner`.
|
||||
Each prototype should be a dictionary. Use the same name as the
|
||||
variable to refer to other prototypes.
|
||||
For example, you might have a Sword typeclass that implements everything a
|
||||
Sword would need to do. The only difference between different individual Swords
|
||||
would be their key, description and some Attributes. The Prototype system
|
||||
allows to create a range of such Swords with only minor variations. Prototypes
|
||||
can also inherit and combine together to form entire hierarchies (such as
|
||||
giving all Sabres and all Broadswords some common properties). Note that bigger
|
||||
variations, such as custom commands or functionality belong in a hierarchy of
|
||||
typeclasses instead.
|
||||
|
||||
A prototype can either be a dictionary placed into a global variable in a
|
||||
python module (a 'module-prototype') or stored in the database as a dict on a
|
||||
special Script (a db-prototype). The former can be created just by adding dicts
|
||||
to modules Evennia looks at for prototypes, the latter is easiest created
|
||||
in-game via the `olc` command/menu.
|
||||
|
||||
Prototypes are read and used to create new objects with the `spawn` command
|
||||
or directly via `evennia.spawn` or the full path `evennia.prototypes.spawner.spawn`.
|
||||
|
||||
A prototype dictionary have the following keywords:
|
||||
|
||||
Possible keywords are:
|
||||
prototype_parent - string pointing to parent prototype of this structure.
|
||||
key - string, the main object identifier.
|
||||
typeclass - string, if not set, will use `settings.BASE_OBJECT_TYPECLASS`.
|
||||
location - this should be a valid object or #dbref.
|
||||
home - valid object or #dbref.
|
||||
destination - only valid for exits (object or dbref).
|
||||
- `prototype_key` - the name of the prototype. This is required for db-prototypes,
|
||||
for module-prototypes, the global variable name of the dict is used instead
|
||||
- `prototype_parent` - string pointing to parent prototype if any. Prototype inherits
|
||||
in a similar way as classes, with children overriding values in their partents.
|
||||
- `key` - string, the main object identifier.
|
||||
- `typeclass` - string, if not set, will use `settings.BASE_OBJECT_TYPECLASS`.
|
||||
- `location` - this should be a valid object or #dbref.
|
||||
- `home` - valid object or #dbref.
|
||||
- `destination` - only valid for exits (object or #dbref).
|
||||
- `permissions` - string or list of permission strings.
|
||||
- `locks` - a lock-string to use for the spawned object.
|
||||
- `aliases` - string or list of strings.
|
||||
- `attrs` - Attributes, expressed as a list of tuples on the form `(attrname, value)`,
|
||||
`(attrname, value, category)`, or `(attrname, value, category, locks)`. If using one
|
||||
of the shorter forms, defaults are used for the rest.
|
||||
- `tags` - Tags, as a list of tuples `(tag,)`, `(tag, category)` or `(tag, category, data)`.
|
||||
- Any other keywords are interpreted as Attributes with no category or lock.
|
||||
These will internally be added to `attrs` (eqivalent to `(attrname, value)`.
|
||||
|
||||
permissions - string or list of permission strings.
|
||||
locks - a lock-string.
|
||||
aliases - string or list of strings.
|
||||
|
||||
ndb_<name> - value of a nattribute (the "ndb_" part is ignored).
|
||||
any other keywords are interpreted as Attributes and their values.
|
||||
|
||||
See the `@spawn` command and `evennia.utils.spawner` for more info.
|
||||
See the `spawn` command and `evennia.prototypes.spawner.spawn` for more info.
|
||||
|
||||
"""
|
||||
|
||||
## example of module-based prototypes using
|
||||
## the variable name as `prototype_key` and
|
||||
## simple Attributes
|
||||
|
||||
# from random import randint
|
||||
#
|
||||
# GOBLIN = {
|
||||
|
|
@ -43,7 +59,8 @@ See the `@spawn` command and `evennia.utils.spawner` for more info.
|
|||
# "health": lambda: randint(20,30),
|
||||
# "resists": ["cold", "poison"],
|
||||
# "attacks": ["fists"],
|
||||
# "weaknesses": ["fire", "light"]
|
||||
# "weaknesses": ["fire", "light"],
|
||||
# "tags": = [("greenskin", "monster"), ("humanoid", "monster")]
|
||||
# }
|
||||
#
|
||||
# GOBLIN_WIZARD = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue