You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TurnIn.lua 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. --[[
  2. Turn-In Mod
  3. version 2.1
  4. Authored by Ian Friedman
  5. Sabindeus of Smolderthorn (Alliance)
  6. The repeatable quest turn in automating machine.
  7. Thanks to Arcanemagus of Hyjal for extra bug fixes and coding input
  8. ]]
  9. -- WOW Version detection
  10. local function TI_IsRetail()
  11. if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
  12. return true;
  13. else
  14. return false;
  15. end
  16. end
  17. TI_VersionString = "2.0";
  18. local TI_slashtable;
  19. TI_gossipclosed = false;
  20. TI_LoadedNPCIndex = 0;
  21. TI_activenumber = 1;
  22. TI_availnumber = 1;
  23. TI_specnum = 0;
  24. TI_gossipopts = {};
  25. TI_TempNPCList = {};
  26. TI_TempNPCListMaxSize = 5;
  27. TI_NPCInQuestion = nil;
  28. local TI_GossipDefaults = {
  29. availquest ="Available Quests",
  30. activequest = "Active Quests",
  31. gossip = "Gossip",
  32. vendor = "Vendor",
  33. taxi = "Taxi",
  34. trainer = "Trainer",
  35. battlemaster = "Battlemaster",
  36. binder = "Hearthstone Binder",
  37. healer = "Spirit Healer",
  38. banker = "Bank"
  39. };
  40. TI_FunctionList = {};
  41. local TI_DefaultStatus = {
  42. state = false,
  43. version = TI_VersionString,
  44. options = {},
  45. debugstate = false,
  46. usedefault=true,
  47. autoadd=false
  48. };
  49. local TI_events = {
  50. "GOSSIP_SHOW",
  51. "GOSSIP_CLOSED",
  52. "QUEST_DETAIL",
  53. "QUEST_COMPLETE",
  54. "QUEST_PROGRESS",
  55. "QUEST_GREETING",
  56. "QUEST_FINISHED"
  57. };
  58. local TI_GossipIconNameToId = {
  59. ["activequesticon"] = 132048,
  60. ["availablequesticon"] = 132049,
  61. ["banker"] = 132050,
  62. ["battlemaster"] = 132051,
  63. ["binder"] = 132052,
  64. ["gossip"] = 132053,
  65. ["healer"] = 132054,
  66. ["petition"] = 132055,
  67. ["tabard"] = 132056,
  68. ["taxi"] = 132057,
  69. ["trainer"] = 132058,
  70. ["unlearn"] = 132059,
  71. ["vendor"] = 132060,
  72. ["incompletequest"] = 365195,
  73. ["dailyquest"] = 368364,
  74. ["dailyactivequest"] = 368577,
  75. ["auctioneer"] = 528409,
  76. ["activelegendaryquest"] = 646979,
  77. ["availablelegendaryquest"] = 646980,
  78. ["chatbubble"] = 1019848,
  79. ["workorder"] = 1130518,
  80. ["transmogrify"] = 1673939,
  81. ["campaignactivequest"] = 3532316,
  82. ["campaignavailablequest"] = 3532317,
  83. ["campaignincompletequest"] = 3532318,
  84. ["campaigngossipicons"] = 3595324,
  85. }
  86. local function TI_InvertDictionary(input)
  87. local s={}
  88. for k,v in pairs(input) do
  89. s[v]=k
  90. end
  91. return s
  92. end
  93. local TI_GossipIconIdToName = TI_InvertDictionary(TI_GossipIconNameToId)
  94. local function TI_TranslateIconToType(iconId)
  95. return TI_GossipIconIdToName[iconId]
  96. end
  97. TI_TempNPCList = {};
  98. function TI_message(...)
  99. local x = {...};
  100. for k,v in pairs(x) do
  101. DEFAULT_CHAT_FRAME:AddMessage(tostring(v));
  102. end
  103. end
  104. function TI_debug(...)
  105. if(TI_status.debugstate) then
  106. TI_message(...)
  107. end
  108. end
  109. function TI_OnLoad()
  110. SlashCmdList["TI"]=TI_SlashCmdHandler;
  111. SLASH_TI1="/turnin";
  112. SLASH_TI2="/ti";
  113. tinsert(UISpecialFrames,"TI_OptionsFrame");
  114. TI_message("Turn In loaded");
  115. TI_slashtable = {};
  116. TI_gossipopts = {};
  117. TI_gossipclosed = false;
  118. TurnIn:RegisterEvent("VARIABLES_LOADED");
  119. TI_activenumber = 1;
  120. TI_availnumber = 1;
  121. TI_specnum = 0;
  122. StaticPopupDialogs["TI_NPCINQUESTION"] = {
  123. text = "The NPC %s is already in your NPC Database. Do you wish to replace his gossip options with the current ones? (Note: This will overwrite your settings for this NPC.)",
  124. button1 = "Yes",
  125. button2 = "No",
  126. OnAccept = function()
  127. TI_AddNPCToList(TI_NPCInQuestion.list, TI_NPCInQuestion.name, true);
  128. end,
  129. timeout=0,
  130. whileDead = 1,
  131. hideOnEscape = 1
  132. };
  133. end
  134. function TI_VarInit()
  135. if(not TI_status or TI_status.version ~= TI_VersionString) then
  136. TI_status = TI_copyTable(TI_DefaultStatus);
  137. TI_OptionsInit();
  138. end
  139. if(not TI_status.options or #TI_status.options == 0) then
  140. TI_OptionsInit();
  141. end
  142. if(not TI_NPCDB) then
  143. TI_NPCDB = {};
  144. end
  145. if(not TI_NPCIndex) then
  146. TI_NPCIndexGenerate();
  147. end
  148. TI_PopulateOptions("vars loaded");
  149. end
  150. function TI_OptionsInit()
  151. TI_status.options = {};
  152. for k,v in pairs(TI_GossipDefaults) do
  153. local temp = {};
  154. temp.name = v;
  155. temp.type = k;
  156. temp.state = false;
  157. table.insert(TI_status.options, temp);
  158. end
  159. end
  160. function TI_NPCIndexGenerate()
  161. TI_NPCIndex = {};
  162. for k,v in pairs(TI_NPCDB) do
  163. table.insert(TI_NPCIndex, k);
  164. end
  165. table.sort(TI_NPCIndex);
  166. end
  167. function TI_LoadEvents()
  168. for k,v in pairs(TI_events) do
  169. TurnIn:RegisterEvent(v);
  170. end
  171. end
  172. function TI_ResetPointers()
  173. TI_activenumber = 1;
  174. TI_availnumber = 1;
  175. TI_specnum = 0;
  176. end
  177. function TI_UnloadEvents()
  178. for k,v in pairs(TI_events) do
  179. TurnIn:UnregisterEvent(v);
  180. end
  181. end
  182. function TI_Switch(state)
  183. if(state=="on") then
  184. TI_status.state = true;
  185. TI_LoadEvents();
  186. TI_message("Turn In On");
  187. elseif(state=="off") then
  188. TI_ResetPointers();
  189. TI_status.state = false;
  190. TI_UnloadEvents();
  191. TI_message("Turn In Off");
  192. elseif(state=="toggle") then
  193. if(TI_status.state) then
  194. TI_Switch("off");
  195. else
  196. TI_Switch("on");
  197. end
  198. end
  199. TI_StatusIndicatorUpdate();
  200. end
  201. function TI_SlashCmdHandler(cmd)
  202. cmdlist = {strsplit(" ", cmd)};
  203. local commands = {
  204. on = function ()
  205. TI_Switch("on");
  206. end,
  207. off = function ()
  208. TI_Switch("off");
  209. end,
  210. toggle = function ()
  211. TI_Switch("toggle");
  212. end,
  213. status = function ()
  214. if(TI_status.state) then
  215. TI_message("Turn In On");
  216. else
  217. TI_message("Turn In Off");
  218. end
  219. end,
  220. window = function ()
  221. TI_OptionsFrame:Show();
  222. end,
  223. config = function ()
  224. TI_OptionsFrame:Show();
  225. end,
  226. recent = function ()
  227. TI_TempNPCListWindow:Show();
  228. end,
  229. debug = function ()
  230. if(TI_status.debugstate) then
  231. TI_status.debugstate = false;
  232. TI_message("debug mode off");
  233. else
  234. TI_status.debugstate = true;
  235. TI_message("debug mode on");
  236. end
  237. end
  238. };
  239. if(commands[cmdlist[1]]) then
  240. commands[cmdlist[1]](cmdlist[2], cmdlist[3], cmdlist[4]);
  241. else
  242. TI_message("Turn In 2.1 Help", "--------------", "/ti on - turns Turn In on", "/ti off - turns Turn In off", "/ti toggle - toggles Turn In on or off", "/ti window - shows the options window", "/ti recent - shows the recently visited NPCs");
  243. end
  244. end
  245. function TI_IsNPCOn(npcname, type)
  246. local opton = false;
  247. if(type ~= nil) then
  248. for k,v in pairs(TI_status.options) do
  249. if(v.type == type and v.state == true) then
  250. opton = true;
  251. end
  252. end
  253. else
  254. opton = true;
  255. end
  256. if(TI_NPCDB[npcname] == nil and TI_status.usedefault == true and opton == true) then
  257. TI_debug("case 1");
  258. return true;
  259. elseif(TI_NPCDB[npcname] ~= nil and TI_NPCDB[npcname].state) then
  260. TI_debug("case 2");
  261. return true;
  262. elseif(TI_NPCDB[npcname] ~= nil and TI_status.usedefault == true and not TI_NPCDB[npcname].state and opton == true) then
  263. TI_debug("case 4");
  264. return true;
  265. else
  266. TI_debug("case 3");
  267. return false;
  268. end
  269. end
  270. function TI_OnEvent(self, event, ...)
  271. if(event == "VARIABLES_LOADED") then
  272. TI_VarInit();
  273. if(TI_status.state) then
  274. TI_LoadEvents();
  275. end
  276. end
  277. if(TI_status.state and not IsShiftKeyDown()) then
  278. if(event == "QUEST_GREETING") then
  279. TI_debug("Quest Greeting");
  280. TI_lastquestframe = "greeting";
  281. if(QuestFrame:IsVisible()) then
  282. if(TI_gossipclosed) then
  283. TI_debug("resetting pointers");
  284. TI_gossipclosed = false;
  285. TI_ResetPointers();
  286. end
  287. TI_HandleGossipWindow("q");
  288. end
  289. end
  290. if(event == "GOSSIP_SHOW") then
  291. TI_debug("Gossip Show");
  292. if(GossipFrame:IsVisible()) then
  293. if(TI_gossipclosed) then
  294. TI_debug("resetting pointers");
  295. TI_gossipclosed = false;
  296. TI_ResetPointers();
  297. end
  298. TI_HandleGossipWindow("g");
  299. end
  300. end
  301. if(event == "GOSSIP_CLOSED") then
  302. TI_debug("Gossip Closed");
  303. if(not GossipFrame:IsVisible()) then
  304. TI_gossipclosed = true;
  305. end;
  306. end
  307. if(event == "QUEST_COMPLETE") then
  308. TI_debug("Quest Complete");
  309. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  310. if(not (GetNumQuestChoices() > 1)) then
  311. GetQuestReward(1);
  312. end
  313. end
  314. TI_ResetPointers();
  315. end
  316. if(event == "QUEST_PROGRESS") then
  317. TI_debug("Quest Progress");
  318. TI_gossipclosed = false;
  319. TI_lastquestframe = "progress";
  320. TI_HandleQuestProgress();
  321. end
  322. if(event == "QUEST_DETAIL") then
  323. TI_debug("Quest Detail");
  324. TI_gossipclosed = false;
  325. if(TI_IsNPCOn(UnitName("npc"), "availquest")) then
  326. TI_HandleAcceptQuest();
  327. end
  328. TI_ResetPointers();
  329. end
  330. if(event == "QUEST_FINISHED") then
  331. TI_debug("Quest Finished");
  332. if(not QuestFrame:IsVisible() and TI_lastquestframe == "greeting") then
  333. TI_debug("looks like the quest frame closed, resetting pointers on next open");
  334. TI_gossipclosed = true;
  335. end
  336. end
  337. end
  338. end
  339. function TI_HandleAcceptQuest()
  340. --QuestInfoFadingFrame_OnUpdate(QuestInfoFadingFrame, 1); -- does not exist anymore in 6.0
  341. QuestDetailAcceptButton_OnClick();
  342. end
  343. function TI_HandleQuestProgress()
  344. local questname = GetTitleText();
  345. local npcname = UnitName("npc");
  346. if(QuestFrame:IsVisible()) then
  347. if(TI_NPCDB[npcname]) then
  348. local thisnpc = TI_NPCDB[npcname];
  349. if(thisnpc.state) then
  350. for i,current in ipairs(thisnpc) do
  351. if(current.name == questname and current.state) then
  352. TI_CompleteQuest();
  353. end
  354. end
  355. else
  356. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  357. TI_CompleteQuest();
  358. end
  359. end
  360. else
  361. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  362. TI_CompleteQuest();
  363. end
  364. end
  365. end
  366. end
  367. function TI_CompleteQuest()
  368. if(IsQuestCompletable()) then
  369. TI_debug("quest is completable, completeing");
  370. CompleteQuest();
  371. TI_ResetPointers();
  372. else
  373. TI_debug("quest is not completable, declining");
  374. QuestDetailDeclineButton_OnClick();
  375. end
  376. end
  377. function TI_GetQuests(type)
  378. local numQuests = (getglobal("GetNum"..type.."Quests"))();
  379. local qfn = getglobal("Get"..type.."Title");
  380. local ret = {};
  381. local qname;
  382. local i=1;
  383. for i=1,numQuests do
  384. qname = qfn(i);
  385. ret[i] = {name=qname};
  386. end
  387. return ret;
  388. end
  389. function TI_HandleGossipWindow(gorq)
  390. local SAcQ;
  391. local SAvQ;
  392. local AvailableQuests;
  393. local ActiveQuests;
  394. local GossipOptions;
  395. if(gorq == "g") then
  396. AvailableQuests = TI_FunctionList.g.tabulateAvailable(TI_FunctionList.g.getavailquests());
  397. ActiveQuests = TI_FunctionList.g.tabulateActive(TI_FunctionList.g.getactivequests());
  398. GossipOptions = TI_FunctionList.g.tabulateOptions(TI_FunctionList.g.getoptions());
  399. SAcQ = TI_FunctionList.g.activequest;
  400. SAvQ = TI_FunctionList.g.availquest;
  401. elseif(gorq == "q") then
  402. AvailableQuests = TI_GetQuests("Available");
  403. ActiveQuests = TI_GetQuests("Active");
  404. GossipOptions = {};
  405. SAcQ=TI_FunctionList.q.activequest;
  406. SAvQ=TI_FunctionList.q.availquest;
  407. end
  408. local ListEntry = {};
  409. for i,v in ipairs(AvailableQuests) do
  410. local x={};
  411. x.name = v.name;
  412. x.gorq = gorq;
  413. x.args = i;
  414. x.type = "availquest";
  415. x.icon = v.icon;
  416. x.state = false;
  417. table.insert(ListEntry, x);
  418. end
  419. for i,v in ipairs(ActiveQuests) do
  420. local x={};
  421. x.name = v.name;
  422. x.gorq = gorq;
  423. x.args = i;
  424. x.type = "activequest";
  425. x.icon = v.icon;
  426. x.state = false;
  427. table.insert(ListEntry, x);
  428. end
  429. for i,v in ipairs(GossipOptions) do
  430. local x={};
  431. x.name = v.name;
  432. x.gorq = gorq;
  433. x.args = i;
  434. x.type = v.type;
  435. x.icon = v.icon;
  436. x.state = false;
  437. table.insert(ListEntry, x);
  438. end
  439. ListEntry.state = false;
  440. local TotalOptions = #AvailableQuests+#ActiveQuests+#GossipOptions;
  441. if(TotalOptions < 1) then
  442. return;
  443. end
  444. local npcname = UnitName("npc");
  445. TI_AddNPCToTempList(npcname, ListEntry);
  446. if(TI_status.autoadd and (not TI_NPCDB[npcname])) then
  447. TI_debug("autoadd on, adding this NPC", TI_status.autoadd, TI_NPCDB[npcname]);
  448. TI_AddNPCToList(ListEntry, npcname);
  449. end
  450. -- If a NPC is in the Database but a new dialog option has appeared (new daily/completed quest) then add it to the DB
  451. if (TI_NPCDB[npcname]) then
  452. for k1, v1 in ipairs(ListEntry) do
  453. local found = false;
  454. for k2, v2 in ipairs(TI_NPCDB[npcname]) do
  455. if (v2.type == v1.type and v2.name == v1.name) then
  456. found = true;
  457. end
  458. end
  459. if (not found) then
  460. table.insert(TI_NPCDB[npcname], v1)
  461. TI_PopulateOptions("npclist updated");
  462. end
  463. end
  464. end
  465. if(TI_availnumber > TotalOptions or TI_activenumber > TotalOptions) then
  466. TI_ResetPointers();
  467. return;
  468. end
  469. TI_debug(npcname);
  470. if(TI_NPCDB[npcname]) then
  471. local thisnpc = TI_NPCDB[npcname];
  472. if(thisnpc.state) then
  473. TI_debug("npc is active, using his options");
  474. for i1,current in ipairs(thisnpc) do
  475. if (current.state == true) then
  476. TI_debug("Current Quest: "..current.name);
  477. if (TI_specnum == 0 or i1 > TI_specnum) then
  478. TI_specnum = i1;
  479. if (current.type == "availquest") then
  480. for i2,v2 in ipairs(AvailableQuests) do
  481. if (v2.name == current.name) then
  482. TI_debug(i1.."-Available Match Found: "..current.name);
  483. SAvQ(v2.questID);
  484. return;
  485. end
  486. end
  487. elseif (current.type == "activequest") then
  488. for i2,v2 in ipairs(ActiveQuests) do
  489. if (v2.name == current.name) then
  490. TI_debug(i1.."-Active Match Found: "..current.name..", "..current.type);
  491. SAcQ(v2.questID);
  492. return;
  493. end
  494. end
  495. else
  496. for i2,v2 in ipairs(GossipOptions) do
  497. if (v2.name == current.name) then
  498. TI_debug(i1.."-Gossip Match Found: "..current.name..", "..current.type);
  499. TI_FunctionList.g.gossip(i2);
  500. return;
  501. end
  502. end
  503. end
  504. end
  505. end
  506. end
  507. return;
  508. else
  509. TI_debug("npc in list, but not active");
  510. end
  511. else
  512. TI_debug("npc not in list");
  513. end
  514. if(TI_status.usedefault == false) then
  515. TI_debug("npc not in list, default set to off, returning.");
  516. return;
  517. end;
  518. TI_debug("using default config");
  519. for i,current in ipairs(TI_status.options) do
  520. if(current.state) then
  521. if(current.type == "availquest" and #AvailableQuests > 0 and TI_availnumber <= #AvailableQuests) then
  522. SAvQ(AvailableQuests[TI_availnumber].questID);
  523. TI_debug("Selecting Available Quest ".. TI_availnumber);
  524. TI_ResetPointers();
  525. return;
  526. elseif(current.type == "activequest" and #ActiveQuests > 0 and TI_activenumber <= #ActiveQuests) then
  527. while TI_activenumber <= #ActiveQuests do
  528. if ActiveQuests[TI_activenumber].isComplete then
  529. TI_debug("Selecting Active Quest ".. TI_activenumber .. " " .. ActiveQuests[TI_activenumber].name );
  530. SAcQ(ActiveQuests[TI_activenumber].questID);
  531. TI_ResetPointers();
  532. return;
  533. else
  534. TI_debug("Active Quest ".. TI_activenumber .. " " .. ActiveQuests[TI_activenumber].name .. " is not complete")
  535. TI_activenumber = TI_activenumber + 1;
  536. end
  537. end
  538. elseif(#GossipOptions > 0) then
  539. for j,val in ipairs(GossipOptions) do
  540. if(val.type == current.type) then
  541. TI_ResetPointers();
  542. TI_FunctionList.g.gossip(j);
  543. return;
  544. end
  545. end
  546. end
  547. end
  548. end
  549. end
  550. function TI_AddNPCToList(OptList, npcname, confirminquestion)
  551. if (npcname == nil) then
  552. npcname = UnitName("npc");
  553. end
  554. if(#OptList > 0) then
  555. if(TI_NPCDB[npcname] == nil) then
  556. TI_NPCDB[npcname] = TI_copyTable(OptList);
  557. table.insert(TI_NPCIndex, npcname);
  558. table.sort(TI_NPCIndex);
  559. TI_PopulateOptions("npclist updated");
  560. elseif(confirminquestion == true) then
  561. TI_NPCDB[npcname] = TI_copyTable(OptList);
  562. TI_PopulateOptions("npclist updated");
  563. else
  564. TI_NPCInQuestion = {name=npcname, list=OptList};
  565. StaticPopup_Show("TI_NPCINQUESTION", npcname);
  566. end
  567. end
  568. end
  569. function TI_AddNPCToTempList(name, list)
  570. local temp = {};
  571. temp.name = name;
  572. temp.list = list;
  573. local subZone = GetSubZoneText();
  574. local realZone = GetRealZoneText();
  575. if(subZone == "") then
  576. temp.location = realZone;
  577. else
  578. temp.location = subZone .. ", " .. realZone;
  579. end
  580. table.insert(TI_TempNPCList, 1, temp);
  581. if(#TI_TempNPCList > TI_TempNPCListMaxSize) then
  582. table.remove(TI_TempNPCList, TI_TempNPCListMaxSize);
  583. end
  584. TI_TempNPCListUpdate();
  585. end
  586. function TI_DeleteTempNPCIndex(index)
  587. table.remove(TI_TempNPCList, index);
  588. TI_TempNPCListUpdate();
  589. end
  590. function TI_AddTempNPCIndex(index)
  591. TI_AddNPCToList(TI_TempNPCList[index].list, TI_TempNPCList[index].name);
  592. end
  593. function TI_DeleteNPC(index)
  594. local name = TI_NPCIndex[index];
  595. table.remove(TI_NPCIndex, index);
  596. TI_NPCDB[name] = nil;
  597. end
  598. function TI_StripDescriptors(...)
  599. local x = {};
  600. local arg = {...};
  601. for i=1, #arg, 2 do
  602. table.insert(x,arg[i]);
  603. end
  604. return x;
  605. end
  606. function TI_TabulateGossipOptions_Classic(...)
  607. local x = {};
  608. local arg = {...};
  609. for i=1, #arg, 2 do
  610. local temp = {};
  611. temp.name = arg[i];
  612. temp.type = arg[i+1];
  613. table.insert(x, temp);
  614. end
  615. return x;
  616. end
  617. function TI_TabulateGossipQuestUIInfo_Retail(gquis)
  618. local x = {};
  619. for i,gqui in ipairs(gquis) do
  620. local temp = {};
  621. temp.name = gqui.title;
  622. temp.icon = QuestUtil.GetQuestIconOffer(
  623. gqui.isLegendary,
  624. gqui.frequency,
  625. gqui.isRepeatable,
  626. false,
  627. false
  628. );
  629. temp.questID = gqui.questID;
  630. temp.isComplete = gqui.isComplete;
  631. table.insert(x, temp);
  632. end
  633. return x;
  634. end
  635. function TI_TabulateGossipUIInfo_Retail(guis)
  636. local x = {};
  637. for i,gui in ipairs(guis) do
  638. local temp = {};
  639. temp.name = gui.name;
  640. local gossipType = TI_TranslateIconToType(gui.icon)
  641. if gossipType == "chatbubble" then
  642. gossipType = "gossip"
  643. end
  644. temp.type = gossipType;
  645. temp.icon = gui.icon;
  646. temp.gossipOptionID = gui.gossipOptionID
  647. temp.orderIndex = gui.orderIndex
  648. table.insert(x, temp);
  649. end
  650. return x;
  651. end
  652. function TI_TabulateGossipAvailableQuests_Classic(...)
  653. local x = {};
  654. for i=1, select("#", ...), 7 do
  655. local temp = {};
  656. temp.name = select(i, ...);
  657. local isTrivial = select(i+2, ...);
  658. local isDaily = select(i+3, ...);
  659. local isRepeatable = select(i+4, ...);
  660. local isLegendary = select(i+5, ...);
  661. local isIgnored = select(i+6, ...);
  662. if ( isDaily ) then
  663. temp.icon = "Interface\\GossipFrame\\DailyQuestIcon";
  664. elseif ( isRepeatable ) then
  665. temp.icon = "Interface\\GossipFrame\\DailyActiveQuestIcon";
  666. elseif ( isLegendary ) then
  667. temp.icon = "Interface\\GossipFrame\\AvailableLegendaryQuestIcon";
  668. else
  669. temp.icon = "Interface\\GossipFrame\\AvailableQuestIcon";
  670. end
  671. table.insert(x, temp);
  672. end
  673. return x;
  674. end
  675. function TI_TabulateGossipActiveQuests_Classic(...)
  676. local x = {};
  677. for i=1, select("#", ...), 6 do
  678. local temp = {};
  679. temp.name = select(i, ...);
  680. local isComplete = select(i+3, ...);
  681. temp.isComplete = isComplete;
  682. local isLegendary = select(i+4, ...);
  683. if(isComplete) then
  684. if(isLegendary) then
  685. temp.icon = "Interface\\GossipFrame\\ActiveLegendaryQuestIcon";
  686. else
  687. temp.icon = "Interface\\GossipFrame\\ActiveQuestIcon";
  688. end
  689. else
  690. temp.icon = "Interface\\GossipFrame\\IncompleteQuestIcon";
  691. end
  692. table.insert(x, temp);
  693. end
  694. return x;
  695. end
  696. -- set up functions by release type
  697. if (TI_IsRetail()) then
  698. TI_FunctionList = {
  699. g = {
  700. availquest = C_GossipInfo.SelectAvailableQuest,
  701. activequest = C_GossipInfo.SelectActiveQuest,
  702. gossip = SelectGossipOption,
  703. getavailquests = C_GossipInfo.GetAvailableQuests,
  704. getactivequests = C_GossipInfo.GetActiveQuests,
  705. getoptions = C_GossipInfo.GetOptions,
  706. tabulateAvailable = TI_TabulateGossipQuestUIInfo_Retail,
  707. tabulateActive = TI_TabulateGossipQuestUIInfo_Retail,
  708. tabulateOptions = TI_TabulateGossipUIInfo_Retail,
  709. },
  710. q = {
  711. activequest = SelectActiveQuest,
  712. availquest = SelectAvailableQuest,
  713. }
  714. };
  715. else
  716. TI_FunctionList = {
  717. g = {
  718. availquest = SelectGossipAvailableQuest,
  719. activequest = SelectGossipActiveQuest,
  720. gossip = SelectGossipOption,
  721. getavailquests = GetGossipAvailableQuests,
  722. getactivequests = GetGossipActiveQuests,
  723. getoptions = GetGossipOptions,
  724. tabulateAvailable = TI_TabulateGossipAvailableQuests_Classic,
  725. tabulateActive = TI_TabulateGossipActiveQuests_Classic,
  726. tabulateOptions = TI_TabulateGossipOptions_Classic,
  727. },
  728. q = {
  729. activequest = SelectActiveQuest,
  730. availquest = SelectAvailableQuest,
  731. }
  732. };
  733. end
  734. --[[this function stolen from WhisperCast by Sarris, whom I love dearly for his contribution to Paladins everywhere.
  735. ]]
  736. function TI_copyTable( src )
  737. local copy = {}
  738. for k1,v1 in pairs(src) do
  739. if ( type(v1) == "table" ) then
  740. copy[k1]=TI_copyTable(v1)
  741. else
  742. copy[k1]=v1
  743. end
  744. end
  745. return copy
  746. end
  747. function toggle(arg)
  748. if(arg) then
  749. return false;
  750. else
  751. return true;
  752. end
  753. end