mirror of
https://github.com/evennia/evennia.git
synced 2026-04-01 21:47:17 +02:00
Updated HTML docs.
This commit is contained in:
parent
035831f963
commit
ff7479faba
33 changed files with 200 additions and 92 deletions
|
|
@ -168,6 +168,8 @@ class EvAdventureCharacter(LivingMixin, DefaultCharacter):
|
|||
|
||||
Above we have assumed the `EquipmentHandler` (`.equipment`) has methods `.validate_slot_usage`, `.add` and `.remove`. But we haven't actually added them yet - we just put some reasonable names! Before we can use this, we need to go actually adding those methods.
|
||||
|
||||
When you do things like `create/drop monster:NPC`, the npc will briefly be in your inventory before being dropped on the ground. Since an NPC is not a valid thing to equip, the EquipmentHandler will complain with an `EquipmentError` (we define this see below). So we need to
|
||||
|
||||
## Expanding the Equipmenthandler
|
||||
|
||||
## `.validate_slot_usage`
|
||||
|
|
@ -497,6 +499,55 @@ In the `.armor()` method we get the item (if any) out of each relevant wield-slo
|
|||
|
||||
In `.weapon()`, we simply check which of the possible weapon slots (weapon-hand or two-hands) have something in them. If not we fall back to the 'Bare Hands' object we created in the [Object tutorial lesson](./Beginner-Tutorial-Objects.md#your-bare-hands) earlier.
|
||||
|
||||
### Fixing the Character class
|
||||
|
||||
So we have added our equipment handler which validate what we put in it. This will however lead to a problem when we create things like NPCs in game, e.g. with
|
||||
|
||||
create/drop monster:evadventure.npcs.EvAdventureNPC
|
||||
|
||||
The problem is that when the monster is created it will briefly appear in your inventory before being dropped, so this code will fire on you when you do that (assuming you are an `EvAdventureCharacter`):
|
||||
|
||||
```python
|
||||
# mygame/evadventure/characters.py
|
||||
# ...
|
||||
|
||||
class EvAdventureCharacter(LivingMixin, DefaultCharacter):
|
||||
|
||||
# ...
|
||||
|
||||
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)
|
||||
```
|
||||
|
||||
At this means that the equipmenthandler will check the NPC, and since it's not a equippable thing, an `EquipmentError` will be raised, failing the creation. Since we want to be able to create npcs etc easily, we will handle this error with a `try...except` statement like so:
|
||||
|
||||
```python
|
||||
# mygame/evadventure/characters.py
|
||||
# ...
|
||||
from evennia import logger
|
||||
from .equipment import EquipmentError
|
||||
|
||||
class EvAdventureCharacter(LivingMixin, DefaultCharacter):
|
||||
|
||||
# ...
|
||||
|
||||
def at_object_receive(self, moved_object, source_location, **kwargs):
|
||||
"""
|
||||
Called by Evennia when an object arrives 'in' the character.
|
||||
|
||||
"""
|
||||
try:
|
||||
self.equipment.add(moved_object)
|
||||
except EquipmentError:
|
||||
logger.log_trace()
|
||||
|
||||
```
|
||||
|
||||
Using Evennia's `logger.log_trace()` we catch the error and direct it to the server log. This allows you to see if there are real errors here as well, but once things work and these errors are spammy, you can also just replace the `logger.log_trace()` line with a `pass` to hide these errors.
|
||||
|
||||
## Extra credits
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue