View Single Post
11-22-14, 01:55 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
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:
  1. LoadAddOn("Blizzard_GarrisonUI");
  2. GarrisonMissionFrame_CheckCompleteMissions=nop;
  3.  
  4. local EFrame=CreateFrame("Frame");
  5. EFrame:RegisterEvent("GARRISON_MISSION_NPC_OPENED");--      Open Command Table
  6. EFrame:RegisterEvent("GARRISON_MISSION_NPC_CLOSED");--      Close Command Table
  7. EFrame:RegisterEvent("GARRISON_MISSION_FINISHED");--        Mission Completed
  8. EFrame:RegisterEvent("GARRISON_MISSION_COMPLETE_RESPONSE");--   Mission Turned In
  9.  
  10. local MissionsOpen=false;
  11. local function ScanMissions(delay)
  12.     if not MissionsOpen then return; end
  13.     if not delay then
  14.         local list=C_Garrison.GetCompleteMissions();
  15.         GarrisonMissionFrame.MissionComplete.completeMissions=list;
  16.         if #list<=0 then GarrisonMissionList_UpdateMissions(); return; end
  17.  
  18.         for i,j in ipairs(list) do
  19.             C_Garrison.MarkMissionComplete(j.missionID);
  20.         end
  21.     end
  22.     C_Timer.After(0.5,ScanMissions);
  23. end
  24.  
  25. EFrame:SetScript("OnEvent",function(self,event,...)
  26.     if event=="GARRISON_MISSION_NPC_OPENED" then
  27.         MissionsOpen=true;
  28.         ScanMissions();
  29.     elseif event=="GARRISON_MISSION_NPC_CLOSED" then
  30.         MissionsOpen=false;
  31.     elseif event=="GARRISON_MISSION_FINISHED" and MissionsOpen then
  32.         C_Garrison.MarkMissionComplete((...));
  33.         ScanMissions(true);
  34.     elseif event=="GARRISON_MISSION_COMPLETE_RESPONSE" then
  35.         if C_Garrison.CanOpenMissionChest((...)) then C_Garrison.MissionBonusRoll((...)); end
  36.     end
  37. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote