mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 00:36:30 +01:00
Update README.md
Added section at bottom addressing adding additional TraitHandlers. Shows example based on first example, but instead using a stats, skills and the original TraitHandler.
This commit is contained in:
parent
74d470a4f6
commit
b6edb59d37
1 changed files with 39 additions and 0 deletions
|
|
@ -439,3 +439,42 @@ class Character(DefaultCharacter):
|
|||
rage = TraitProperty("A dark mood", rage=30, trait_type='rage')
|
||||
|
||||
```
|
||||
|
||||
## Adding additional TraitHandlers
|
||||
|
||||
Sometimes, it is easier to top-level classify traits, such as stats, skills, or other categories of traits you want to handle independantly of each other. Here is an example showing an example on the object typeclass, expanding on the first installation example:
|
||||
|
||||
```python
|
||||
# mygame/typeclasses/objects.py
|
||||
|
||||
from evennia import DefaultCharacter
|
||||
from evennia.utils import lazy_property
|
||||
from evennia.contrib.rpg.traits import TraitHandler
|
||||
|
||||
# ...
|
||||
|
||||
class Character(DefaultCharacter):
|
||||
...
|
||||
@lazy_property
|
||||
def traits(self):
|
||||
# this adds the handler as .traits
|
||||
return TraitHandler(self)
|
||||
|
||||
@lazy_property
|
||||
def stats(self):
|
||||
# this adds the handler as .stats
|
||||
return TraitHandler(self, db_attribute_key="stats")
|
||||
|
||||
@lazy_property
|
||||
def skills(self):
|
||||
# this adds the handler as .skills
|
||||
return TraitHandler(self, db_attribute_key="skills")
|
||||
|
||||
|
||||
def at_object_creation(self):
|
||||
# (or wherever you want)
|
||||
self.stats.add("str", "Strength", trait_type="static", base=10, mod=2)
|
||||
self.traits.add("hp", "Health", trait_type="gauge", min=0, max=100)
|
||||
self.skills.add("hunting", "Hunting Skill", trait_type="counter",
|
||||
base=10, mod=1, min=0, max=100)
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue