diff --git a/State.lua b/State.lua index 2a42ef3..bedb843 100644 --- a/State.lua +++ b/State.lua @@ -23,6 +23,35 @@ F.State = { } } +local function GetQuestRewardXP(index, questID) + local rewardXP = 0 + + if questID and C_QuestLog.GetQuestLogRewardXP then + rewardXP = C_QuestLog.GetQuestLogRewardXP(questID) or 0 + end + + if questID and C_QuestLog.SetSelectedQuest and C_QuestLog.GetSelectedQuest and GetQuestLogRewardXP then + local previous = C_QuestLog.GetSelectedQuest() + if previous ~= questID then + C_QuestLog.SetSelectedQuest(questID) + end + + local selectedXP = GetQuestLogRewardXP() or 0 + + if previous and previous ~= questID then + C_QuestLog.SetSelectedQuest(previous) + end + + if selectedXP > 0 then + rewardXP = selectedXP + end + elseif rewardXP == 0 and GetQuestLogRewardXP then + rewardXP = GetQuestLogRewardXP(index) or 0 + end + + return rewardXP +end + function F.State:UpdatePlayerXP() self.level = UnitLevel("player") self.currentXP = UnitXP("player") @@ -44,12 +73,7 @@ function F.State:UpdateQuestXP() -- this skips the XP header for a category / campaign as they should not be respected if info and not info.isHeader and not info.isHidden and info.questID > 0 then -- Use the quest log index when querying the reward XP - local rewardXP = 0 - if info.questID and C_QuestLog.GetQuestLogRewardXP then - rewardXP = C_QuestLog.GetQuestLogRewardXP(info.questID) or 0 - else - rewardXP = GetQuestLogRewardXP(i) or 0 - end + local rewardXP = GetQuestRewardXP(i, info.questID) if rewardXP > 0 then qXP = qXP + rewardXP @@ -86,12 +110,7 @@ function F.State:DebugDumpQuests() for i = 1, numEntries do local info = C_QuestLog.GetInfo(i) if info then - local reward = 0 - if info.questID and C_QuestLog.GetQuestLogRewardXP then - reward = C_QuestLog.GetQuestLogRewardXP(info.questID) or 0 - else - reward = GetQuestLogRewardXP(i) or 0 - end + local reward = GetQuestRewardXP(i, info.questID) local status = "UNKNOWN" if info.isHeader then