Files
ThordekkCore/PHASE3_COMPLETION_ARCHITECTURE.md
T
2026-01-20 21:33:16 -03:00

539 lines
20 KiB
Markdown

# Phase 3: Game System Integration - Complete Architecture Design
## Executive Summary
Phase 3 requires completion of critical game system integration components to enable bots to fully interact with the World of Warcraft game world. Analysis reveals significant gaps in Movement, Quest completion, and NPC interaction systems that must be implemented for functional bot behavior.
## Current State Analysis
### Existing Components (Complete or Near-Complete)
#### Combat System (36+ files) - **90% COMPLETE**
- Comprehensive combat management with threat, positioning, formations
- Advanced mechanics: interrupts, kiting, line of sight, obstacle avoidance
- Role-based positioning and group combat coordination
- Integration with ClassAI specializations
#### Quest System (11 files) - **60% COMPLETE**
- Quest pickup and automation frameworks implemented
- Dynamic quest system with objective tracking
- **MISSING**: Implementation bodies for QuestCompletion, QuestTurnIn, QuestValidation
#### Movement System (2 files) - **20% COMPLETE**
- Only LeaderFollowBehavior implemented
- **MISSING**: Core movement, pathfinding, terrain handling
#### NPC Interaction (3 files) - **15% COMPLETE**
- Basic NPCInteractionManager exists in Game/
- **MISSING**: Comprehensive vendor, trainer, gossip systems
## Architecture Design for Missing Components
### 1. Movement System Completion (Priority: CRITICAL)
#### Directory Structure
```
src/modules/Playerbot/Movement/
├── Core/
│ ├── MovementManager.cpp/h # Central movement coordinator
│ ├── MovementGenerator.cpp/h # Base movement generator
│ ├── MovementTypes.h # Movement enums and constants
│ └── MovementValidator.cpp/h # Path validation and safety
├── Pathfinding/
│ ├── PathfindingAdapter.cpp/h # TrinityCore pathfinding integration
│ ├── PathOptimizer.cpp/h # Path smoothing and optimization
│ ├── NavMeshInterface.cpp/h # MMap/VMap interface wrapper
│ └── DynamicObstacles.cpp/h # Runtime obstacle detection
├── Generators/
│ ├── PointMovementGenerator.cpp/h # Move to specific point
│ ├── ChaseMovementGenerator.cpp/h # Chase target movement
│ ├── FleeMovementGenerator.cpp/h # Escape/flee movement
│ ├── WanderMovementGenerator.cpp/h # Random wandering
│ ├── FormationMovementGenerator.cpp/h # Group formation movement
│ ├── PatrolMovementGenerator.cpp/h # Waypoint patrol movement
│ └── FollowMovementGenerator.cpp/h # Enhanced follow (extends LeaderFollow)
├── Terrain/
│ ├── TerrainAnalyzer.cpp/h # Terrain type detection
│ ├── WaterMovement.cpp/h # Swimming/underwater movement
│ ├── FlyingMovement.cpp/h # Flying mount movement
│ ├── IndoorMovement.cpp/h # Indoor/dungeon movement
│ └── ClimbingHandler.cpp/h # Slope and cliff handling
├── Coordination/
│ ├── GroupMovementCoordinator.cpp/h # Multi-bot movement sync
│ ├── CollisionAvoidance.cpp/h # Bot-to-bot collision
│ ├── TrafficManager.cpp/h # Doorway/chokepoint management
│ └── MovementPriority.cpp/h # Movement priority resolution
└── Integration/
├── CombatMovementBridge.cpp/h # Combat system integration
├── QuestMovementBridge.cpp/h # Quest objective movement
└── TransportHandler.cpp/h # Ships/zeppelins/elevators
```
#### Core Classes
```cpp
// MovementManager.h
namespace Playerbot
{
class MovementManager final
{
public:
static MovementManager* Instance();
// Main update - called from BotAI
void UpdateMovement(Player* bot, uint32 diff);
// Movement control
bool MoveTo(Player* bot, Position const& dest, float speed = 0.0f);
bool MoveToUnit(Player* bot, Unit* target, float distance = 0.0f);
bool Follow(Player* bot, Unit* leader, float minDist = 2.0f, float maxDist = 5.0f);
bool Flee(Player* bot, Unit* threat, float distance = 20.0f);
// Movement queries
bool IsMoving(Player* bot) const;
float GetDistanceToDestination(Player* bot) const;
uint32 GetTimeToDestination(Player* bot) const;
// Pathfinding
bool CalculatePath(Player* bot, Position const& dest, Movement::PointsArray& path);
bool HasValidPath(Player* bot) const;
// Generator management
void SetMovementGenerator(Player* bot, MovementGeneratorType type);
MovementGeneratorType GetCurrentGenerator(Player* bot) const;
// Group coordination
void UpdateFormation(Group* group, FormationType type);
void SynchronizeGroupMovement(Group* group);
private:
struct BotMovementData
{
std::unique_ptr<MovementGenerator> generator;
Movement::PointsArray currentPath;
Position destination;
float speed;
uint32 lastUpdate;
bool isMoving;
MovementFlags flags;
};
std::unordered_map<ObjectGuid, BotMovementData> m_botMovement;
std::unique_ptr<PathfindingAdapter> m_pathfinder;
std::unique_ptr<TerrainAnalyzer> m_terrainAnalyzer;
std::unique_ptr<GroupMovementCoordinator> m_groupCoordinator;
mutable std::shared_mutex m_mutex;
};
}
```
### 2. NPC Interaction System (Priority: CRITICAL)
#### Directory Structure
```
src/modules/Playerbot/Interaction/
├── Core/
│ ├── InteractionManager.cpp/h # Central NPC interaction coordinator
│ ├── InteractionTypes.h # Interaction enums and types
│ ├── GossipHandler.cpp/h # Gossip menu navigation
│ └── InteractionValidator.cpp/h # Interaction validation
├── Vendors/
│ ├── VendorInteraction.cpp/h # Buy/sell logic
│ ├── RepairManager.cpp/h # Equipment repair
│ ├── VendorDatabase.cpp/h # Vendor item preferences
│ └── AuctionHouseBot.cpp/h # AH interaction
├── Trainers/
│ ├── TrainerInteraction.cpp/h # Skill/spell training
│ ├── TrainerDatabase.cpp/h # Training priorities
│ ├── ProfessionTrainer.cpp/h # Profession learning
│ └── ClassTrainerLogic.cpp/h # Class-specific training
├── Services/
│ ├── InnkeeperInteraction.cpp/h # Rest/hearthstone
│ ├── FlightMasterInteraction.cpp/h # Flight path discovery/use
│ ├── StableMasterInteraction.cpp/h # Pet stable management
│ ├── BankInteraction.cpp/h # Bank/vault access
│ ├── MailboxInteraction.cpp/h # Mail sending/receiving
│ └── BattlemasterInteraction.cpp/h # PvP queue interaction
├── Quest/
│ ├── QuestGiverInteraction.cpp/h # Quest NPC interaction
│ ├── QuestDialogHandler.cpp/h # Quest text processing
│ └── QuestRewardSelection.cpp/h # Reward choice logic
└── Special/
├── DungeonFinderNPC.cpp/h # LFG interaction
├── TransmogrifierNPC.cpp/h # Transmog interaction
├── ReforgerNPC.cpp/h # Reforging interaction
└── PortalInteraction.cpp/h # Portal/teleport NPCs
```
#### Core Classes
```cpp
// InteractionManager.h
namespace Playerbot
{
enum class InteractionResult : uint8
{
SUCCESS,
FAILED,
IN_PROGRESS,
INVALID_TARGET,
OUT_OF_RANGE,
NO_MONEY,
INVENTORY_FULL,
REQUIREMENT_NOT_MET,
ON_COOLDOWN
};
class InteractionManager final
{
public:
static InteractionManager* Instance();
// Main interaction entry point
InteractionResult InteractWithNPC(Player* bot, Creature* npc);
// Vendor operations
bool BuyItem(Player* bot, Creature* vendor, uint32 itemId, uint32 count);
bool SellItem(Player* bot, Creature* vendor, Item* item, uint32 count);
bool RepairAll(Player* bot, Creature* vendor);
// Trainer operations
bool LearnSpell(Player* bot, Creature* trainer, uint32 spellId);
bool LearnAllAvailableSpells(Player* bot, Creature* trainer);
bool TrainProfession(Player* bot, Creature* trainer, uint32 skillId);
// Service operations
bool SetHearthstone(Player* bot, Creature* innkeeper);
bool DiscoverFlightPath(Player* bot, Creature* flightMaster);
bool TakeFlightPath(Player* bot, Creature* flightMaster, uint32 nodeId);
// Quest operations
bool AcceptQuest(Player* bot, Object* questGiver, uint32 questId);
bool CompleteQuest(Player* bot, Object* questGiver, uint32 questId);
bool TurnInQuest(Player* bot, Object* questGiver, uint32 questId, uint32 rewardChoice);
// Gossip handling
bool SelectGossipOption(Player* bot, Creature* npc, uint32 option);
std::vector<GossipMenuItem> GetGossipOptions(Player* bot, Creature* npc);
// Interaction queries
bool CanInteract(Player* bot, Creature* npc) const;
float GetInteractionRange(Creature* npc) const;
std::vector<Creature*> FindNearbyNPCs(Player* bot, NPCType type, float range);
private:
struct InteractionContext
{
Player* bot;
Creature* npc;
InteractionType type;
uint32 startTime;
uint32 attempts;
InteractionResult lastResult;
};
std::unordered_map<ObjectGuid, InteractionContext> m_activeInteractions;
std::unique_ptr<VendorDatabase> m_vendorDB;
std::unique_ptr<TrainerDatabase> m_trainerDB;
std::unique_ptr<GossipHandler> m_gossipHandler;
mutable std::shared_mutex m_mutex;
};
}
```
### 3. Quest System Completion (Priority: HIGH)
#### Implementation Files Needed
```
src/modules/Playerbot/Quest/
├── QuestCompletion.cpp # Implementation of QuestCompletion.h
├── QuestTurnIn.cpp # Implementation of QuestTurnIn.h
├── QuestValidation.cpp # Implementation of QuestValidation.h
├── Integration/
│ ├── QuestChainManager.cpp/h # Quest chain progression
│ ├── QuestRouteOptimizer.cpp/h # Optimal quest route planning
│ └── QuestGroupSync.cpp/h # Group quest synchronization
└── Database/
├── QuestDatabase.cpp/h # Quest priority/strategy database
└── QuestCache.cpp/h # Quest data caching
```
#### Quest Completion Implementation
```cpp
// QuestCompletion.cpp - Key implementation
namespace Playerbot
{
class QuestCompletionManager : public QuestCompletion
{
public:
bool UpdateQuestObjectives(Player* bot, uint32 questId) override
{
Quest const* quest = sObjectMgr->GetQuestTemplate(questId);
if (!quest)
return false;
QuestStatusData* questStatus = bot->GetQuestStatus(questId);
if (!questStatus || questStatus->Status != QUEST_STATUS_INCOMPLETE)
return false;
bool progressMade = false;
// Process each objective
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
{
if (quest->RequiredNpcOrGo[i] != 0)
{
progressMade |= UpdateKillObjective(bot, quest, i);
}
if (quest->RequiredItemId[i] != 0)
{
progressMade |= UpdateItemObjective(bot, quest, i);
}
}
// Check special objectives
progressMade |= UpdateSpecialObjectives(bot, quest);
// Update quest status if completed
if (bot->CanCompleteQuest(questId))
{
bot->CompleteQuest(questId);
LogQuestCompletion(bot, questId);
return true;
}
return progressMade;
}
CompletionStrategy DetermineStrategy(Player* bot, Quest const* quest) override
{
// Analyze quest type and determine optimal completion strategy
if (quest->HasFlag(QUEST_FLAGS_RAID))
return CompletionStrategy::GROUP_REQUIRED;
if (quest->HasFlag(QUEST_FLAGS_PVP))
return CompletionStrategy::PVP_FOCUSED;
if (quest->GetQuestLevel() > bot->GetLevel() + 3)
return CompletionStrategy::POSTPONE;
// Analyze objectives
bool hasKillObjective = false;
bool hasItemObjective = false;
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
{
if (quest->RequiredNpcOrGo[i] < 0)
return CompletionStrategy::INTERACT_OBJECT;
if (quest->RequiredNpcOrGo[i] > 0)
hasKillObjective = true;
if (quest->RequiredItemId[i] > 0)
hasItemObjective = true;
}
if (hasKillObjective)
return CompletionStrategy::COMBAT_FOCUSED;
if (hasItemObjective)
return CompletionStrategy::GATHERING_FOCUSED;
return CompletionStrategy::STANDARD;
}
Position FindObjectiveLocation(Player* bot, Quest const* quest, uint8 objectiveIndex) override
{
// Integration with database for known spawn points
if (auto location = m_questDB->GetObjectiveLocation(quest->GetQuestId(), objectiveIndex))
return *location;
// Fallback to area search
return SearchForObjective(bot, quest, objectiveIndex);
}
private:
std::unique_ptr<QuestDatabase> m_questDB;
std::unique_ptr<QuestRouteOptimizer> m_routeOptimizer;
};
}
```
### 4. Integration Architecture
#### System Integration Points
```cpp
// BotAI Integration Points
class BotAI
{
// Phase 3 System Integration
void UpdateSystems(uint32 diff)
{
// Movement System - Primary update
if (m_movementManager)
m_movementManager->UpdateMovement(me, diff);
// NPC Interaction - Check for nearby NPCs
if (m_interactionManager && !InCombat())
m_interactionManager->ProcessPendingInteractions(me);
// Quest System - Update objectives
if (m_questManager)
m_questManager->UpdateQuestProgress(me, diff);
// Combat Movement Bridge - Override movement in combat
if (InCombat() && m_combatMovementBridge)
m_combatMovementBridge->UpdateCombatMovement(me, diff);
}
private:
std::unique_ptr<MovementManager> m_movementManager;
std::unique_ptr<InteractionManager> m_interactionManager;
std::unique_ptr<QuestCompletionManager> m_questManager;
std::unique_ptr<CombatMovementBridge> m_combatMovementBridge;
};
```
## Performance Optimization Strategy
### Memory Optimization
- **Object Pooling**: Reuse movement paths and interaction contexts
- **Lazy Loading**: Load NPC/Quest databases on-demand
- **Cache Management**: LRU caches for frequent queries
- **Memory Budget**: Max 10MB per bot allocation
### CPU Optimization
- **Update Throttling**: Stagger system updates across frames
- **Priority Queues**: Process critical interactions first
- **Batch Operations**: Group similar operations together
- **Thread Pool Integration**: Offload pathfinding to worker threads
```cpp
// Performance-Optimized Update Pattern
class OptimizedSystemUpdate
{
void Update(uint32 diff)
{
m_accumulator += diff;
// Staggered updates
if (m_accumulator >= MOVEMENT_UPDATE_RATE)
{
UpdateMovement(m_accumulator);
m_accumulator = 0;
}
// Throttled NPC scanning
if (m_npcScanTimer.Passed())
{
m_npcScanTimer.Reset(NPC_SCAN_INTERVAL);
ThreadPool::Enqueue([this] { ScanForNPCs(); });
}
// Batched quest updates
if (m_questBatch.size() >= QUEST_BATCH_SIZE)
{
ProcessQuestBatch(m_questBatch);
m_questBatch.clear();
}
}
};
```
## Implementation Roadmap
### Phase 3A: Movement System (2 weeks)
**Week 1:**
- Core MovementManager and Generator framework
- PathfindingAdapter with MMap/VMap integration
- Basic movement generators (Point, Chase, Follow)
**Week 2:**
- Terrain-specific movement handlers
- Group movement coordination
- Combat/Quest movement bridges
### Phase 3B: NPC Interaction (2 weeks)
**Week 1:**
- Core InteractionManager framework
- Vendor and repair interactions
- Basic gossip handling
**Week 2:**
- Trainer interactions and skill learning
- Service NPCs (flight, inn, bank)
- Quest giver interactions
### Phase 3C: Quest Completion (1 week)
- Implement QuestCompletion.cpp
- Implement QuestTurnIn.cpp
- Implement QuestValidation.cpp
- Quest chain management
- Group quest synchronization
### Phase 3D: Integration & Testing (1 week)
- System integration with BotAI
- Performance profiling and optimization
- Comprehensive testing suite
- Documentation updates
## Estimated Code Scope
### Line Count Estimates
| System | Files | Estimated LoC |
|--------|-------|--------------|
| **Movement System** | 30 | 15,000 |
| Core & Pathfinding | 8 | 4,000 |
| Movement Generators | 7 | 3,500 |
| Terrain Handlers | 5 | 2,500 |
| Coordination | 4 | 2,000 |
| Integration | 3 | 1,500 |
| Tests | 3 | 1,500 |
| **NPC Interaction** | 25 | 12,000 |
| Core Framework | 4 | 2,000 |
| Vendor System | 4 | 2,000 |
| Trainer System | 4 | 2,000 |
| Service NPCs | 6 | 3,000 |
| Quest NPCs | 3 | 1,500 |
| Special NPCs | 4 | 1,500 |
| **Quest Completion** | 10 | 5,000 |
| Core Implementation | 3 | 2,000 |
| Integration | 3 | 1,500 |
| Database/Cache | 2 | 1,000 |
| Tests | 2 | 500 |
| **Total Phase 3** | **65** | **32,000** |
## Critical Success Factors
### Technical Requirements
1. **Thread Safety**: All systems must be thread-safe for concurrent bot execution
2. **Performance**: <0.1% CPU per bot, <10MB memory per bot
3. **Integration**: Seamless integration with existing Combat and AI systems
4. **Reliability**: Robust error handling and fallback mechanisms
5. **Scalability**: Support 5000+ concurrent bots
### Quality Metrics
1. **Code Coverage**: >80% test coverage for critical paths
2. **Performance**: <1ms average update time per bot
3. **Memory**: <100KB per bot steady-state memory usage
4. **Stability**: Zero crashes in 24-hour stress test
5. **Completeness**: 100% quest completion capability
## Risk Mitigation
### Technical Risks
1. **Pathfinding Performance**: Mitigate with caching and path reuse
2. **Memory Growth**: Implement strict memory budgets and monitoring
3. **Thread Contention**: Use lock-free structures where possible
4. **Database Load**: Implement aggressive caching and batching
### Integration Risks
1. **Core API Changes**: Maintain abstraction layer for TrinityCore APIs
2. **Combat Conflicts**: Priority system for movement overrides
3. **Quest Complexity**: Fallback strategies for complex objectives
4. **NPC Availability**: Timeout and retry mechanisms
## Conclusion
Phase 3 completion requires approximately 32,000 lines of new code across 65 files, with the Movement and NPC Interaction systems being the most critical missing components. The architecture emphasizes performance, thread safety, and seamless integration with existing systems while maintaining the ability to scale to 5000+ concurrent bots.
The modular design allows for parallel development of subsystems while maintaining clear integration points. Priority should be given to Movement and NPC Interaction as these are fundamental to all other bot behaviors.