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

3.3 KiB

QuestManager BehaviorManager Integration Fix

Summary

Fixed QuestManager.cpp to properly inherit from BehaviorManager base class according to Phase 2.4 refactoring plan.

Issues Fixed

1. Removed Duplicate/Conflicting Methods

  • REMOVED: Update(uint32 diff) - BehaviorManager provides this
  • REMOVED: Reset() - Not part of BehaviorManager pattern
  • REMOVED: Shutdown() - BehaviorManager handles cleanup
  • REMOVED: Initialize() - Replaced with OnInitialize()

2. Removed Duplicate Member Variables

  • REMOVED: m_ai - BehaviorManager provides GetAI()
  • REMOVED: m_enabled - BehaviorManager provides IsEnabled()/SetEnabled()
  • REMOVED: m_timeSinceLastUpdate - BehaviorManager handles timing
  • REMOVED: m_updateInterval - BehaviorManager handles this
  • REMOVED: m_totalUpdateTime - Not needed
  • REMOVED: m_updateCount - BehaviorManager provides m_updateCount
  • REMOVED: m_cpuUsage - BehaviorManager handles performance

3. Removed Undefined Performance Methods

  • REMOVED: StartPerformanceTimer() - BehaviorManager handles this
  • REMOVED: EndPerformanceTimer() - BehaviorManager handles this
  • REMOVED: UpdatePerformanceMetrics() - BehaviorManager handles this

4. Implemented BehaviorManager Virtual Methods

  • ADDED: OnInitialize() - Returns true on successful init
  • CHANGED: Update() to OnUpdate(uint32 elapsed) - Called by base class
  • CHANGED: Shutdown() to OnShutdown() - Called by base class

5. Added Missing Method Implementation

  • ADDED: HasActiveQuest(uint32 questId) - Was declared but not implemented

BehaviorManager Pattern Implementation

class QuestManager : public BehaviorManager {
public:
    QuestManager(Player* bot, BotAI* ai)
        : BehaviorManager(bot, ai, 2000, "QuestManager")  // 2 second update interval
        // ... initialize QuestManager-specific members

protected:
    // Called once at startup
    bool OnInitialize() override {
        // One-time initialization
        return true;
    }

    // Called every 2 seconds (throttled by BehaviorManager)
    void OnUpdate(uint32 elapsed) override {
        // Regular quest updates
    }

    // Called at shutdown
    void OnShutdown() override {
        // Cleanup
    }
};

Key Changes in Constructor

  • Properly calls BehaviorManager constructor with all 4 parameters
  • Removed initialization of duplicate member variables
  • Kept only QuestManager-specific members

Benefits

  1. Consistent API: All managers use same base class pattern
  2. Automatic Throttling: Updates only run every 2 seconds
  3. Performance Monitoring: Built-in slow update detection
  4. Thread Safety: Atomic state flags for lock-free queries
  5. Reduced Code Duplication: Base class handles common functionality

Testing Required

  1. Compile playerbot module
  2. Verify QuestManager initializes correctly
  3. Verify quest scanning works
  4. Verify quest acceptance/completion works
  5. Check performance metrics
  • src/modules/Playerbot/Game/QuestManager.h - Header file (already correct)
  • src/modules/Playerbot/Game/QuestManager.cpp - Implementation (FIXED)
  • src/modules/Playerbot/AI/BehaviorManager.h - Base class definition
  • PHASE_2_4_MANAGER_REFACTOR.md - Refactoring plan documentation