How liyunfan1223/mod-playerbots works
Project Type and Purpose
• This is a C++ server-side module (“mod-playerbots”) for the AzerothCore MMORPG engine (World of Warcraft emulation).
• It plugs into the WorldServer, loading at runtime as a module, reads SQL schema/data to extend the database, registers AI bots, and implements a multi-tiered AI framework (triggers, strategies, actions, values).
Top-Level Components
a. AzerothCore WorldServer (host application)
b. Module Loader (AzerothCore plugin system)
c. mod-playerbots Module:
• Configuration subsystem (conf/*.dist, environment variables)
• SQL Schema/Data loader (data/sql/...)
• C++ AI core (src/*.cpp, src/strategy, src/factory, src/playerbots_loader.cpp)
• Database persistence (PlayerbotDbStore)
• Command server (PlayerbotCommandServer)
d. External dependencies:
• AzerothCore API (server events, world simulation, network I/O)
• DBC files (game data)
• MySQL/MariaDB
Relationships & Data Flows
1. Startup
• WorldServer initializes → plugin loader discovers mod-playerbots →
• playerbots_loader.cpp reads config/environment, executes SQL schema (data/sql/create) → registers DB tables/functions.
2. Runtime Loop
• WorldServer generates game events (player joined, NPC update tick, combat event) → mod-playerbots intercepts via ServerFacade and manager hooks (PlayerbotMgr, TravelMgr, FleeManager etc.).
• For each bot, AiFactory/RandomPlayerbotFactory instantiates a PlayerbotAI object.
• On each update tick:
• TriggerContext gathers world state → selects active triggers (src/strategy/triggers/*) →
• StrategyContext chooses appropriate strategy modules (class-specific, dungeon, raid strategies, etc.) →
• ActionContext picks concrete actions (movement, combat, chat) and computes Value objects as parameters →
• WorldServer API calls execute actions (move, cast spell, send chat).
• Any persistent state (quest progress, custom strategy) is read/written via PlayerbotDbStore.
• Chat commands received via PlayerbotCommandServer → parsed → invoke manager methods or AI updates.
Architectural Patterns
• Plugin architecture: module loaded into host server
• Factory pattern: AiFactory, RandomPlayerbotFactory for bot creation
• Strategy pattern: dynamic selection of Strategy classes (generic, class-specific, dungeon, raid)
• Command pattern: Action objects that encapsulate behavior
• Observer/Trigger pattern: Trigger objects that watch world events
• Data persistence layer: PlayerbotDbStore abstracts SQL operations