/*
 * Progressive Quest XP Module for AzerothCore
 *
 * Applies a level-based XP multiplier to quest rewards only.
 * Does not affect kill XP, exploration XP, or PvP XP.
 */

#include "Config.h"
#include "Player.h"
#include "ScriptMgr.h"

class ProgressiveQuestXPPlayer : public PlayerScript
{
public:
    ProgressiveQuestXPPlayer() : PlayerScript("ProgressiveQuestXPPlayer",
        {PLAYERHOOK_ON_QUEST_COMPUTE_EXP}) { }

    void OnPlayerQuestComputeXP(Player* player, Quest const* /*quest*/,
                                uint32& xpValue) override
    {
        if (!sConfigMgr->GetOption<bool>("DynamicQuestXP.Enable", true))
            return;

        if (!xpValue)
            return;

        uint8 level = player->GetLevel();
        float multiplier;

        if (level <= 20)
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_1_20", 1.5f);
        else if (level <= 30)
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_21_30", 1.3f);
        else if (level <= 40)
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_31_40", 1.1f);
        else if (level <= 50)
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_41_50", 1.0f);
        else if (level <= 60)
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_51_60", 1.0f);
        else if (level <= 70)
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_61_70", 1.0f);
        else
            multiplier = sConfigMgr->GetOption<float>(
                "DynamicQuestXP.Level_70_plus", 1.0f);

        xpValue = static_cast<uint32>(xpValue * multiplier);
    }
};

void AddSC_ProgressiveQuestXP()
{
    new ProgressiveQuestXPPlayer();
}
