How avirar/mod-playerbots works
Project type and purpose
• This is a C++ “module” plugin for the AzerothCore MMORPG server (WorldServer) named mod-playerbots.
• Its purpose is to add AI-driven, player-like bots to the game world by hooking into the server’s event loop, chat system, and database layer.
High-level architectural components
a. AzerothCore WorldServer (host application)
• Loads the module at startup via CMake/C++ plugin mechanism.
• Provides core game loop, networking, scripting engine, and event hooks.
b. Playerbots Module (our code under src/)
• Module Loader (playerbots_loader.cpp)
• Configuration (conf/playerbots.conf.dist)
• Database schema and migrations (data/sql/...)
• Core services:
• AiFactory
• PlayerbotMgr
• PlayerbotAI / PlayerbotAIBase
• PlayerbotDbStore
• CommandServer
• Helpers (ChatHelper, TravelMgr, Security, PerformanceMonitor, etc.)
• Strategy Engine (src/strategy/):
• *Core engine* (StrategyContext, AiObjectContext, Engine, EventContext)
• *Actions* (one file per action in actions/)
• *Triggers* (in triggers/)
• *Values* (in values/)
• *Class-specific, dungeon, raid, generic sub-folders*
• Factory subsystem (src/factory/):
• PlayerbotFactory, StatsCollector, StatsWeightCalculator, RandomPlayerbotFactory
c. MySQL Database
• Stores persistent bot data, account links, guild tasks, dungeon suggestions, etc.
• Module includes DDL/DML scripts to create and update schemas under data/sql.
d. Clients & External Tools
• In-game Chat (players send commands to bots via chat)
• Optional UI Add-Ons (Multibot, Unbot) calling ChatCommandServer APIs
Relationships and data flow
• On startup, WorldServer loads Module Loader, reads Configuration, applies SQL migrations to the Database.
• WorldServer triggers events (e.g., on player login, on tick, on chat). The module’s hooks (ChatFilter, ServerFacade) intercept these.
• PlayerbotMgr spawns bot entities; each bot is backed by a PlayerbotAI instance.
• AiFactory + Factory subsystem create and configure bot AIs (class, spec, equipment).
• During each tick:
1. PlayerbotAI calls the Strategy Engine
2. Engine queries Triggers (am I low HP?), Values (who is nearest?), then picks Actions (cast heal, move, loot).
3. Engine executes selected Actions via ServerFacade (which makes in-game API calls).
• CommandServer listens for chat commands (e.g., “!bot follow”) routes them to appropriate in-module handlers.
• PlayerbotDbStore reads/writes bot state to the Database when persistence is needed.
• Helpers like TravelMgr, ChatHelper abstract world-server APIs for reuse.
Important architectural patterns and principles
• Plugin/Module pattern: decouples bot logic from core server.
• Factory pattern: abstracts bot creation and stat weighting.
• Strategy pattern: encapsulates per-class, per-scenario behavior (generic, dungeon, raid, class).
• Separation of concerns:
• Configuration vs. code vs. data/schema
• Core AI loop vs. class-specific strategies
• Database persistence vs. in-memory logic