mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 23:36:30 +01:00
Started equipment docs
This commit is contained in:
parent
96264d192d
commit
267fb1eb9d
2 changed files with 81 additions and 36 deletions
|
|
@ -28,7 +28,7 @@ class WieldLocation(Enum):
|
|||
Basically, all the weapon/armor locations are exclusive - you can only have one item in each (or none).
|
||||
The BACKPACK is special - it contains any number of items (up to the maximum slot usage).
|
||||
|
||||
## EquipmentHandler
|
||||
## EquipmentHandler that saves
|
||||
|
||||
> Create a new module `mygame/evadventure/equipment.py`.
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ class EquipmentHandler:
|
|||
self.obj.attributes.add(self.save_attribute, self.slots, category="inventory")
|
||||
```
|
||||
|
||||
This is a compact and functioning little handler. Before analyzing how it works, this is how
|
||||
This is a compact and functional little handler. Before analyzing how it works, this is how
|
||||
we will add it to the Character:
|
||||
|
||||
```python
|
||||
|
|
@ -113,8 +113,54 @@ So we now have a handler on the character, and the handler has a back-reference
|
|||
on.
|
||||
|
||||
Since the handler itself is just a regular Python object, we need to use the `Character` to store
|
||||
our data - our _Knave_ slots. We must save them to the database, because we want the server to remember
|
||||
our data - our _Knave_ "slots". We must save them to the database, because we want the server to remember
|
||||
them even after reloading.
|
||||
|
||||
Using `self.obj.attributes.add()` and `.get()` we save the data to the Character in a specially named
|
||||
[Attribute](../../../Components/Attributes.md). Since we use a `category`, we are unlikely to collide with other Attributes.
|
||||
[Attribute](../../../Components/Attributes.md). Since we use a `category`, we are unlikely to collide with
|
||||
other Attributes.
|
||||
|
||||
Our storage structure is a `dict` with keys after our available `WieldLocation` enums. Each can only
|
||||
have one item except `WieldLocation.BACKPACK`, which is a list.
|
||||
|
||||
## Connecting the EquipmentHandler
|
||||
|
||||
We already made `EquipmentHandler` available on the Character as `.equipment`. Now we want it to come into
|
||||
play automatically whenever we pick up or drop something. To do this we need to override two hooks
|
||||
on the Character class:
|
||||
|
||||
```python
|
||||
# mygame/evadventure/character.py
|
||||
|
||||
# ...
|
||||
|
||||
class EvAdventureCharacter(LivingMixin, DefaultCharacter):
|
||||
|
||||
# ...
|
||||
|
||||
def at_pre_object_receive(self, moved_object, source_location, **kwargs):
|
||||
"""Called by Evennia before object arrives 'in' this character (that is,
|
||||
if they pick up something). If it returns False, move is aborted.
|
||||
|
||||
"""
|
||||
# we haven't written this yet!
|
||||
return self.equipment.validate_slot_usage(moved_object)
|
||||
|
||||
def at_object_receive(self, moved_object, source_location, **kwargs):
|
||||
"""
|
||||
Called by Evennia when an object arrives 'in' the character.
|
||||
|
||||
"""
|
||||
self.equipment.add(moved_object)
|
||||
|
||||
def at_object_leave(self, moved_object, destination, **kwargs):
|
||||
"""
|
||||
Called by Evennia when object leaves the Character.
|
||||
|
||||
"""
|
||||
self.equipment.remove(moved_object)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -593,41 +593,42 @@ class EvAdventureImprovement:
|
|||
# character sheet visualization
|
||||
|
||||
|
||||
class EvAdventureCharacterSheet:
|
||||
_SHEET = """
|
||||
+----------------------------------------------------------------------------+
|
||||
| Name: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| STR: x2xxxxx DEX: x3xxxxx CON: x4xxxxx WIS: x5xxxxx CHA: x6xxxxx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| HP: x7xxxxx XP: x8xxxxx Exploration speed: x9x Combat speed: xAx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| Desc: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccc1ccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
+----------------------------------------------------------------------------+
|
||||
"""
|
||||
|
||||
|
||||
def get_character_sheet(character):
|
||||
"""
|
||||
Generate a character sheet. This is grouped in a class in order to make
|
||||
it easier to override the look of the sheet.
|
||||
|
||||
"""
|
||||
|
||||
sheet = """
|
||||
+----------------------------------------------------------------------------+
|
||||
| Name: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| STR: x2xxxxx DEX: x3xxxxx CON: x4xxxxx WIS: x5xxxxx CHA: x6xxxxx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| HP: x7xxxxx XP: x8xxxxx Exploration speed: x9x Combat speed: xAx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| Desc: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
+----------------------------------------------------------------------------+
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccc1ccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
+----------------------------------------------------------------------------+
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get(character):
|
||||
"""
|
||||
|
|
@ -639,7 +640,7 @@ class EvAdventureCharacterSheet:
|
|||
equipment_table = EvTable(
|
||||
table=[equipment[i : i + 10] for i in range(0, len(equipment), 10)]
|
||||
)
|
||||
form = EvForm({"FORMCHAR": "x", "TABLECHAR": "c", "SHEET": EvAdventureCharacterSheet.sheet})
|
||||
form = EvForm({"FORMCHAR": "x", "TABLECHAR": "c", "SHEET": _SHEET})
|
||||
form.map(
|
||||
cells={
|
||||
1: character.key,
|
||||
|
|
@ -663,8 +664,6 @@ class EvAdventureCharacterSheet:
|
|||
|
||||
# singletons
|
||||
|
||||
# access sheet as rules.character_sheet.get(character)
|
||||
character_sheet = EvAdventureCharacterSheet()
|
||||
# access rolls e.g. with rules.dice.opposed_saving_throw(...)
|
||||
dice = EvAdventureRollEngine()
|
||||
# access improvement e.g. with rules.improvement.add_xp(character, xp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue