Strange, that's the approach I tried the first time, but it didn't work out for me. I get the feeling this mechanic has more events firing that they aren't exposing to Lua side. Anyway, this is the code I have. It's really robust in which I like to have anything I can think of covered.
This also allows any addon wanting to poll
GarrisonMissionFrame.MissionComplete.completeMissions get updated info.
Note:
nop() is a global dummy function in UIParent.lua
Lua Code:
LoadAddOn("Blizzard_GarrisonUI");
GarrisonMissionFrame_CheckCompleteMissions=nop;
local EFrame=CreateFrame("Frame");
EFrame:RegisterEvent("GARRISON_MISSION_NPC_OPENED");-- Open Command Table
EFrame:RegisterEvent("GARRISON_MISSION_NPC_CLOSED");-- Close Command Table
EFrame:RegisterEvent("GARRISON_MISSION_FINISHED");-- Mission Completed
EFrame:RegisterEvent("GARRISON_MISSION_COMPLETE_RESPONSE");-- Mission Turned In
local MissionsOpen=false;
local function ScanMissions(delay)
if not MissionsOpen then return; end
if not delay then
local list=C_Garrison.GetCompleteMissions();
GarrisonMissionFrame.MissionComplete.completeMissions=list;
if #list<=0 then GarrisonMissionList_UpdateMissions(); return; end
for i,j in ipairs(list) do
C_Garrison.MarkMissionComplete(j.missionID);
end
end
C_Timer.After(0.5,ScanMissions);
end
EFrame:SetScript("OnEvent",function(self,event,...)
if event=="GARRISON_MISSION_NPC_OPENED" then
MissionsOpen=true;
ScanMissions();
elseif event=="GARRISON_MISSION_NPC_CLOSED" then
MissionsOpen=false;
elseif event=="GARRISON_MISSION_FINISHED" and MissionsOpen then
C_Garrison.MarkMissionComplete((...));
ScanMissions(true);
elseif event=="GARRISON_MISSION_COMPLETE_RESPONSE" then
if C_Garrison.CanOpenMissionChest((...)) then C_Garrison.MissionBonusRoll((...)); end
end
end);