NPC AI module for EvAdventure (WIP)

This implements a simple state machine for NPCs to follow.

The AIHandler class is stored on the NPC object and is queried by the game loop to determine what the NPC does next. This leads to the calling of one of the relevant state methods on the NPC, which is where the actual logic for the NPC’s behaviour is implemented. Each state is responsible for switching to the next state when the conditions are met.

The AIMixin class is a mixin that can be added to any object that needs AI. It provides the .ai reference to the AIHandler and a few basic ai_* methods for basic AI behaviour.

Example usage:

from evennia import create_object
from .npc import EvadventureNPC
from .ai import AIMixin

class MyMob(AIMixin, EvadventureNPC):

mob = create_object(MyMob, key="Goblin", location=room)


# tick the ai whenever needed
class evennia.contrib.tutorials.evadventure.ai.AIHandler(obj)[source]

Bases: object

attribute_name = 'ai_state'
attribute_category = 'ai_state'

Initialize self. See help(type(self)) for accurate signature.


Get a list of potential targets for the NPC to combat.


Get a list of exits that the NPC can traverse. Optionally exclude a destination.


exclude_destination (Object, optional) – Exclude exits with this destination.


Given a dictionary of probabilities, return the key of the chosen probability.


probabilities (dict) – A dictionary of probabilities, where the key is the action and the value is the probability of that action.

class evennia.contrib.tutorials.evadventure.ai.AIMixin[source]

Bases: object

Mixin for adding AI to an Object. This is a simple state machine. Just add more ai_* methods to the object to make it do more things.

In the tutorial, the handler is added directly to the Mob class, to avoid going into the details of multiple inheritance. In a real game, you would probably want to use a mixin like this.