evennia.contrib.tutorials.evadventure.ai

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):
    pass

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

mob.ai.set_state("patrol")

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

Bases: object

__init__(obj)[source]

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

set_state(state)[source]
get_state()[source]
get_targets()[source]

Get a list of potential targets for the NPC to attack

get_traversable_exits(exclude_destination=None)[source]
random_probability(probabilities)[source]

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

run()[source]
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.

combat_probabilities = {'attack': 0.9, 'flee': 0.0, 'hold': 0.1, 'item': 0.0, 'stunt': 0.0}
ai[source]
ai_idle()[source]
ai_attack()[source]
ai_patrol()[source]
ai_flee()[source]
class evennia.contrib.tutorials.evadventure.ai.IdleMobMixin[source]

Bases: evennia.contrib.tutorials.evadventure.ai.AIMixin

A simple mob that understands AI commands, but does nothing.

ai_idle()[source]
class evennia.contrib.tutorials.evadventure.ai.AggressiveMobMixin[source]

Bases: evennia.contrib.tutorials.evadventure.ai.AIMixin

A simple aggressive mob that can roam, attack and flee.

combat_probabilities = {'attack': 0.85, 'flee': 0.05, 'hold': 0.0, 'item': 0.0, 'stunt': 0.05}
ai_idle()[source]

Do nothing, but switch to attack state if a target is found.

ai_attack()[source]

Manage the attack/combat state of the mob.

ai_patrol()[source]

Patrol, moving randomly to a new room. If a target is found, switch to attack state.

ai_flee()[source]

Flee from the current room, avoiding going back to the room from which we came. If no exits are found, switch to patrol state.