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

6.1 KiB

PlayerBot Architecture Refactoring - Integration Report

Executive Summary

The architecture refactoring to fix bot following issues has been partially implemented. The core files have been updated with the new clean update chain architecture, but integration issues remain due to interface mismatches with existing code.

Completed Work

1. Core Files Updated ✅

  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\BotAI.h - Replaced with refactored version
  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\BotAI.cpp - Replaced with refactored version
  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\ClassAI.h - Replaced with refactored version
  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\ClassAI.cpp - Replaced with refactored version

2. Architecture Improvements Implemented ✅

  • Single UpdateAI() entry point - no more DoUpdateAI/UpdateEnhanced confusion
  • Clean OnCombatUpdate() virtual method for combat specialization
  • No throttling of base behaviors - ensures smooth following
  • Clear separation between base behaviors (BotAI) and combat specialization (ClassAI)

3. API Compatibility Fixes Applied ✅

  • Fixed ObjectGuid usage (using ObjectGuid::Empty instead of nullptr)
  • Fixed Group iteration (using GetMembers() with range-based for)
  • Fixed Player::isMoving() API calls
  • Fixed GetRelativeAngle() method usage
  • Fixed SpellHistory::GetRemainingCooldown() API

Integration Issues Encountered

1. Strategy Interface Mismatch ❌

Issue: Refactored BotAI expects:

  • Strategy::Update(BotAI*, uint32)
  • Strategy::OnCombatStart(BotAI*, Unit*)
  • Strategy::OnCombatEnd(BotAI*)

Actual Interface:

  • Strategy::UpdateBehavior(BotAI*, uint32)
  • No combat lifecycle methods

Impact: BotAI.cpp compilation errors when calling non-existent methods

2. Trigger Interface Mismatch ❌

Issue: Refactored BotAI expects:

  • Trigger::GetResult(BotAI*)
  • TriggerResult::actionName

Actual Interface: Different trigger result structure

Impact: Trigger processing logic fails to compile

3. BotAIFactory Methods Missing ❌

Issue: Factory methods don't match:

  • Missing CreateSpecializedAI(), CreatePvPAI(), etc.
  • Player::getClass() vs actual API

Impact: AI creation logic fails

4. Class AI Member Variables ❌

Issue: Some class AIs have their own _currentTarget as ObjectGuid

  • HunterAI, PaladinAI, MageAI, WarlockAI

Impact: Type conflicts and assignment errors

  1. Fix Strategy Interface

    // In BotAI.cpp, change:
    strategy->Update(this, diff);
    // To:
    strategy->UpdateBehavior(this, diff);
    
  2. Remove Combat Lifecycle from Strategies

    • Remove calls to OnCombatStart/End on strategies
    • Keep these only on ClassAI level
  3. Fix Trigger Processing

    • Analyze actual Trigger interface
    • Adapt trigger processing to match
  4. Clean Up Class AI Conflicts

    • Remove duplicate _currentTarget members
    • Use base class member consistently

Option 2: Incremental Refactor

  1. Keep existing BotAI/ClassAI structure
  2. Only apply the key fix: Remove throttling from movement updates
  3. Add OnCombatUpdate() as optional override
  4. Gradually migrate functionality

Option 3: Full Revert and Redesign

  1. Revert all changes
  2. Design new architecture that matches existing interfaces
  3. Implement with full compatibility from start

Critical Success Factors

The main goal was to fix bot following issues caused by:

  1. Update throttling - PARTIALLY FIXED (architecture supports it, needs integration)
  2. Dual update paths - FIXED (single UpdateAI entry point)
  3. Movement control conflicts - FIXED (ClassAI no longer controls movement)

Performance Impact

  • Every-frame updates now possible for strategies
  • No throttling on core behaviors
  • Combat updates cleanly separated
  • Should achieve smooth following once integration issues resolved

Files Modified

Core Architecture Files

  1. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\BotAI.h
  2. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\BotAI.cpp
  3. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\ClassAI.h
  4. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\ClassAI.cpp

Class AI Files Requiring Updates

  1. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\Hunters\HunterAI.cpp
  2. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\Paladins\PaladinAI.cpp
  3. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\Mages\MageAI_Specialization.cpp
  4. C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\Warlocks\WarlockAI_Specialization.cpp

Conclusion

The architecture refactoring provides a clean foundation for fixing the bot following issues. However, integration with the existing codebase requires additional work to adapt the interfaces. The core improvements are sound:

✅ Single update path established ✅ Combat specialization separated ✅ Movement control centralized ✅ Throttling removed from base behaviors

❌ Strategy interface adaptation needed ❌ Trigger processing needs adjustment ❌ Class AI member conflicts need resolution ❌ Factory methods need alignment

Recommendation: Continue with Option 1 - adapt the refactored code to match existing interfaces. The architectural improvements are valuable and worth preserving.

Build Commands for Testing

# Windows build command
cd /c/TrinityBots/TrinityCore && cmake --build build --config RelWithDebInfo --target worldserver -j4

# Check for errors
cmake --build build --config RelWithDebInfo --target worldserver -j4 2>&1 | grep -E "error|FAILED"

Backup Files Location

Original files are preserved as:

  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\BotAI_Refactored.h
  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\BotAI_Refactored.cpp
  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\ClassAI_Refactored.h
  • C:\TrinityBots\TrinityCore\src\modules\Playerbot\AI\ClassAI\ClassAI_Refactored.cpp