mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Rename all at_before/after hooks to at_pre/post. Old names still work but are deprecated. Resolves #1454.
This commit is contained in:
parent
7b25299be4
commit
36e985557f
21 changed files with 106 additions and 102 deletions
|
|
@ -170,14 +170,14 @@ object).
|
|||
1. The Exit command triggers `at_traverse(obj, destination)` on the Exit object.
|
||||
1. In `at_traverse`, `object.move_to(destination)` is triggered. This triggers the following hooks,
|
||||
in order:
|
||||
1. `obj.at_before_move(destination)` - if this returns False, move is aborted.
|
||||
1. `origin.at_before_leave(obj, destination)`
|
||||
1. `obj.at_pre_move(destination)` - if this returns False, move is aborted.
|
||||
1. `origin.at_pre_leave(obj, destination)`
|
||||
1. `obj.announce_move_from(destination)`
|
||||
1. Move is performed by changing `obj.location` from source location to `destination`.
|
||||
1. `obj.announce_move_to(source)`
|
||||
1. `destination.at_object_receive(obj, source)`
|
||||
1. `obj.at_after_move(source)`
|
||||
1. On the Exit object, `at_after_traverse(obj, source)` is triggered.
|
||||
1. `obj.at_post_move(source)`
|
||||
1. On the Exit object, `at_post_traverse(obj, source)` is triggered.
|
||||
|
||||
If the move fails for whatever reason, the Exit will look for an Attribute `err_traverse` on itself
|
||||
and display this as an error message. If this is not found, the Exit will instead call
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ for more info.
|
|||
**Q:** How does one keep a character from using any exit, if they meet a certain condition? (I.E. in
|
||||
combat, immobilized, etc.)
|
||||
|
||||
**A:** The `at_before_move` hook is called by Evennia just before performing any move. If it returns
|
||||
**A:** The `at_pre_move` hook is called by Evennia just before performing any move. If it returns
|
||||
`False`, the move is aborted. Let's say we want to check for an [Attribute](../Components/Attributes.md) `cantmove`.
|
||||
Add the following code to the `Character` class:
|
||||
|
||||
```python
|
||||
def at_before_move(self, destination):
|
||||
def at_pre_move(self, destination):
|
||||
"Called just before trying to move"
|
||||
if self.db.cantmove: # replace with condition you want to test
|
||||
self.msg("Something is preventing you from moving!")
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ This requires a change to our Character typeclass. Open `mygame/typeclasses/char
|
|||
class Character(DefaultCharacter):
|
||||
# ...
|
||||
|
||||
def at_before_move(self, destination):
|
||||
def at_pre_move(self, destination):
|
||||
"""
|
||||
Called by self.move_to when trying to move somewhere. If this returns
|
||||
False, the move is immediately cancelled.
|
||||
|
|
@ -49,7 +49,7 @@ class Character(DefaultCharacter):
|
|||
```
|
||||
|
||||
When moving somewhere, [character.move_to](evennia.objects.objects.DefaultObject.move_to) is called. This in turn
|
||||
will call `character.at_before_move`. Here we look for an Attribute `is_resting` (which we will assign below)
|
||||
will call `character.at_pre_move`. Here we look for an Attribute `is_resting` (which we will assign below)
|
||||
to determine if we are stuck on the chair or not.
|
||||
|
||||
## Making the Chair itself
|
||||
|
|
|
|||
|
|
@ -81,14 +81,14 @@ This room checks the typeclass of objects entering it (using `utils.inherits_fro
|
|||
contents and inform any `NPCs inside by calling their `at_char_entered` method.
|
||||
|
||||
You'll also see that we have added a 'look' into this code. This is because, by default, the
|
||||
`at_object_receive` is carried out *before* the character's `at_after_move` which, we will now
|
||||
`at_object_receive` is carried out *before* the character's `at_post_move` which, we will now
|
||||
overload. This means that a character entering would see the NPC perform its actions before the
|
||||
'look' command. Deactivate the look command in the default `Character` class within the
|
||||
`typeclasses.characters` module:
|
||||
|
||||
```python
|
||||
# Add this hook in any blank area within your Character class.
|
||||
def at_after_move(self, source_location):
|
||||
def at_post_move(self, source_location):
|
||||
"""
|
||||
Default is to look around after a move
|
||||
Note: This has been moved to Room.at_object_receive
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue