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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. C_AddOns.LoadAddOn("Blizzard_DebugTools")
  107. local x = {...};
  108. for k,v in pairs(x) do
  109. if type(v) == "table" and DevTools_Dump then
  110. DevTools_Dump(v)
  111. else
  112. DEFAULT_CHAT_FRAME:AddMessage(tostring(v));
  113. end
  114. end
  115. end
  116. end
  117. function TI_OnLoad()
  118. SlashCmdList["TI"]=TI_SlashCmdHandler;
  119. SLASH_TI1="/turnin";
  120. SLASH_TI2="/ti";
  121. tinsert(UISpecialFrames,"TI_OptionsFrame");
  122. TI_message("Turn In loaded");
  123. TI_slashtable = {};
  124. TI_gossipopts = {};
  125. TI_gossipclosed = false;
  126. TurnIn:RegisterEvent("VARIABLES_LOADED");
  127. TI_activenumber = 1;
  128. TI_availnumber = 1;
  129. TI_specnum = 0;
  130. StaticPopupDialogs["TI_NPCINQUESTION"] = {
  131. 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.)",
  132. button1 = "Yes",
  133. button2 = "No",
  134. OnAccept = function()
  135. TI_AddNPCToList(TI_NPCInQuestion.list, TI_NPCInQuestion.name, true);
  136. end,
  137. timeout=0,
  138. whileDead = 1,
  139. hideOnEscape = 1
  140. };
  141. end
  142. function TI_VarInit()
  143. if(not TI_status or TI_status.version ~= TI_VersionString) then
  144. TI_status = TI_copyTable(TI_DefaultStatus);
  145. TI_OptionsInit();
  146. end
  147. if(not TI_status.options or #TI_status.options == 0) then
  148. TI_OptionsInit();
  149. end
  150. if(not TI_NPCDB) then
  151. TI_NPCDB = {};
  152. end
  153. if(not TI_NPCIndex) then
  154. TI_NPCIndexGenerate();
  155. end
  156. TI_PopulateOptions("vars loaded");
  157. end
  158. function TI_OptionsInit()
  159. TI_status.options = {};
  160. for k,v in pairs(TI_GossipDefaults) do
  161. local temp = {};
  162. temp.name = v;
  163. temp.type = k;
  164. temp.state = false;
  165. table.insert(TI_status.options, temp);
  166. end
  167. end
  168. function TI_NPCIndexGenerate()
  169. TI_NPCIndex = {};
  170. for k,v in pairs(TI_NPCDB) do
  171. table.insert(TI_NPCIndex, k);
  172. end
  173. table.sort(TI_NPCIndex);
  174. end
  175. function TI_LoadEvents()
  176. for k,v in pairs(TI_events) do
  177. TurnIn:RegisterEvent(v);
  178. end
  179. end
  180. function TI_ResetPointers()
  181. TI_debug("resetting pointers")
  182. TI_activenumber = 1;
  183. TI_availnumber = 1;
  184. TI_specnum = 0;
  185. end
  186. function TI_UnloadEvents()
  187. for k,v in pairs(TI_events) do
  188. TurnIn:UnregisterEvent(v);
  189. end
  190. end
  191. function TI_Switch(state)
  192. if(state=="on") then
  193. TI_status.state = true;
  194. TI_LoadEvents();
  195. TI_message("Turn In On");
  196. elseif(state=="off") then
  197. TI_ResetPointers();
  198. TI_status.state = false;
  199. TI_UnloadEvents();
  200. TI_message("Turn In Off");
  201. elseif(state=="toggle") then
  202. if(TI_status.state) then
  203. TI_Switch("off");
  204. else
  205. TI_Switch("on");
  206. end
  207. end
  208. TI_StatusIndicatorUpdate();
  209. end
  210. function TI_SlashCmdHandler(cmd)
  211. cmdlist = {strsplit(" ", cmd)};
  212. local commands = {
  213. on = function ()
  214. TI_Switch("on");
  215. end,
  216. off = function ()
  217. TI_Switch("off");
  218. end,
  219. toggle = function ()
  220. TI_Switch("toggle");
  221. end,
  222. status = function ()
  223. if(TI_status.state) then
  224. TI_message("Turn In On");
  225. else
  226. TI_message("Turn In Off");
  227. end
  228. end,
  229. window = function ()
  230. TI_OptionsFrame:Show();
  231. end,
  232. config = function ()
  233. TI_OptionsFrame:Show();
  234. end,
  235. recent = function ()
  236. TI_TempNPCListWindow:Show();
  237. end,
  238. debug = function ()
  239. if(TI_status.debugstate) then
  240. TI_status.debugstate = false;
  241. TI_message("debug mode off");
  242. else
  243. TI_status.debugstate = true;
  244. TI_message("debug mode on");
  245. end
  246. end
  247. };
  248. if(commands[cmdlist[1]]) then
  249. commands[cmdlist[1]](cmdlist[2], cmdlist[3], cmdlist[4]);
  250. else
  251. 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");
  252. end
  253. end
  254. function TI_IsNPCOn(npcname, type)
  255. local opton = false;
  256. if(type ~= nil) then
  257. for k,v in pairs(TI_status.options) do
  258. if(v.type == type and v.state == true) then
  259. opton = true;
  260. end
  261. end
  262. else
  263. opton = true;
  264. end
  265. if(TI_NPCDB[npcname] == nil and TI_status.usedefault == true and opton == true) then
  266. TI_debug("case 1");
  267. return true;
  268. elseif(TI_NPCDB[npcname] ~= nil and TI_NPCDB[npcname].state) then
  269. TI_debug("case 2");
  270. return true;
  271. elseif(TI_NPCDB[npcname] ~= nil and TI_status.usedefault == true and not TI_NPCDB[npcname].state and opton == true) then
  272. TI_debug("case 4");
  273. return true;
  274. else
  275. TI_debug("case 3");
  276. return false;
  277. end
  278. end
  279. function TI_OnEvent(self, event, ...)
  280. if(event == "VARIABLES_LOADED") then
  281. TI_VarInit();
  282. if(TI_status.state) then
  283. TI_LoadEvents();
  284. end
  285. end
  286. if(TI_status.state and not IsShiftKeyDown()) then
  287. if(event == "QUEST_GREETING") then
  288. TI_debug("Quest Greeting");
  289. TI_lastquestframe = "greeting";
  290. if(QuestFrame:IsVisible()) then
  291. if(TI_gossipclosed) then
  292. TI_debug("resetting pointers");
  293. TI_gossipclosed = false;
  294. TI_ResetPointers();
  295. end
  296. TI_HandleGossipWindow("q");
  297. end
  298. end
  299. if(event == "GOSSIP_SHOW") then
  300. TI_debug("Gossip Show");
  301. if(GossipFrame:IsVisible()) then
  302. if(TI_gossipclosed) then
  303. TI_debug("resetting pointers");
  304. TI_gossipclosed = false;
  305. TI_ResetPointers();
  306. end
  307. TI_HandleGossipWindow("g");
  308. end
  309. end
  310. if(event == "GOSSIP_CLOSED") then
  311. TI_debug("Gossip Closed");
  312. if(not GossipFrame:IsVisible()) then
  313. TI_gossipclosed = true;
  314. end;
  315. end
  316. if(event == "QUEST_COMPLETE") then
  317. TI_debug("Quest Complete");
  318. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  319. if(not (GetNumQuestChoices() > 1)) then
  320. GetQuestReward(1);
  321. end
  322. end
  323. TI_ResetPointers();
  324. end
  325. if(event == "QUEST_PROGRESS") then
  326. TI_debug("Quest Progress");
  327. TI_gossipclosed = false;
  328. TI_lastquestframe = "progress";
  329. TI_HandleQuestProgress();
  330. end
  331. if(event == "QUEST_DETAIL") then
  332. TI_debug("Quest Detail");
  333. TI_gossipclosed = false;
  334. if(TI_IsNPCOn(UnitName("npc"), "availquest")) then
  335. TI_HandleAcceptQuest();
  336. end
  337. TI_ResetPointers();
  338. end
  339. if(event == "QUEST_FINISHED") then
  340. TI_debug("Quest Finished");
  341. if(not QuestFrame:IsVisible() and TI_lastquestframe == "greeting") then
  342. TI_debug("looks like the quest frame closed, resetting pointers on next open");
  343. TI_gossipclosed = true;
  344. end
  345. end
  346. end
  347. end
  348. function TI_HandleAcceptQuest()
  349. --QuestInfoFadingFrame_OnUpdate(QuestInfoFadingFrame, 1); -- does not exist anymore in 6.0
  350. QuestDetailAcceptButton_OnClick();
  351. end
  352. function TI_HandleQuestProgress()
  353. local questname = GetTitleText();
  354. local npcname = UnitName("npc");
  355. if(QuestFrame:IsVisible()) then
  356. if(TI_NPCDB[npcname]) then
  357. local thisnpc = TI_NPCDB[npcname];
  358. if(thisnpc.state) then
  359. for i,current in ipairs(thisnpc) do
  360. if(current.name == questname and current.state) then
  361. TI_CompleteQuest();
  362. end
  363. end
  364. else
  365. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  366. TI_CompleteQuest();
  367. end
  368. end
  369. else
  370. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  371. TI_CompleteQuest();
  372. end
  373. end
  374. end
  375. end
  376. function TI_CompleteQuest()
  377. if(IsQuestCompletable()) then
  378. TI_debug("quest is completable, completeing");
  379. CompleteQuest();
  380. TI_ResetPointers();
  381. else
  382. TI_debug("quest is not completable, declining");
  383. TI_availnumber = TI_availnumber + 1;
  384. QuestDetailDeclineButton_OnClick();
  385. end
  386. end
  387. function TI_GetQuests(type)
  388. local numQuests = (getglobal("GetNum"..type.."Quests"))();
  389. local qfn = getglobal("Get"..type.."Title");
  390. local ret = {};
  391. local i=1;
  392. for i=1,numQuests do
  393. local qname, isComplete = qfn(i);
  394. ret[i] = {name=qname, questID=i, isComplete=isComplete};
  395. end
  396. return ret;
  397. end
  398. function TI_HandleGossipWindow(gorq)
  399. local SAcQ;
  400. local SAvQ;
  401. local AvailableQuests;
  402. local ActiveQuests;
  403. local GossipOptions;
  404. TI_debug(gorq);
  405. if(gorq == "g") then
  406. AvailableQuests = TI_FunctionList.g.tabulateAvailable(TI_FunctionList.g.getavailquests());
  407. ActiveQuests = TI_FunctionList.g.tabulateActive(TI_FunctionList.g.getactivequests());
  408. GossipOptions = TI_FunctionList.g.tabulateOptions(TI_FunctionList.g.getoptions());
  409. SAcQ = TI_FunctionList.g.activequest;
  410. SAvQ = TI_FunctionList.g.availquest;
  411. elseif(gorq == "q") then
  412. AvailableQuests = TI_GetQuests("Available");
  413. ActiveQuests = TI_GetQuests("Active");
  414. GossipOptions = {};
  415. SAcQ=TI_FunctionList.q.activequest;
  416. SAvQ=TI_FunctionList.q.availquest;
  417. end
  418. local ListEntry = {};
  419. for i,v in ipairs(AvailableQuests) do
  420. local x={};
  421. x.name = v.name;
  422. x.gorq = gorq;
  423. x.args = i;
  424. x.type = "availquest";
  425. x.icon = v.icon;
  426. x.state = false;
  427. table.insert(ListEntry, x);
  428. end
  429. for i,v in ipairs(ActiveQuests) do
  430. local x={};
  431. x.name = v.name;
  432. x.gorq = gorq;
  433. x.args = i;
  434. x.type = "activequest";
  435. x.icon = v.icon;
  436. x.state = false;
  437. table.insert(ListEntry, x);
  438. end
  439. for i,v in ipairs(GossipOptions) do
  440. local x={};
  441. x.name = v.name;
  442. x.gorq = gorq;
  443. if x.orderIndex then
  444. x.args = v.orderIndex;
  445. else
  446. x.args = i;
  447. end
  448. x.type = v.type;
  449. x.icon = v.icon;
  450. x.state = false;
  451. table.insert(ListEntry, x);
  452. end
  453. ListEntry.state = false;
  454. local TotalOptions = #AvailableQuests+#ActiveQuests+#GossipOptions;
  455. if(TotalOptions < 1) then
  456. return;
  457. end
  458. local npcname = UnitName("npc");
  459. TI_AddNPCToTempList(npcname, ListEntry);
  460. if(TI_status.autoadd and (not TI_NPCDB[npcname])) then
  461. TI_debug("autoadd on, adding this NPC", TI_status.autoadd, TI_NPCDB[npcname]);
  462. TI_AddNPCToList(ListEntry, npcname);
  463. end
  464. -- If a NPC is in the Database but a new dialog option has appeared (new daily/completed quest) then add it to the DB
  465. if (TI_NPCDB[npcname]) then
  466. for k1, v1 in ipairs(ListEntry) do
  467. local found = false;
  468. for k2, v2 in ipairs(TI_NPCDB[npcname]) do
  469. if (v2.type == v1.type and v2.name == v1.name) then
  470. found = true;
  471. end
  472. end
  473. if (not found) then
  474. table.insert(TI_NPCDB[npcname], v1)
  475. TI_PopulateOptions("npclist updated");
  476. end
  477. end
  478. end
  479. if(TI_availnumber > TotalOptions or TI_activenumber > TotalOptions) then
  480. TI_debug("Out of available/active quests, giving up ");
  481. TI_ResetPointers();
  482. return;
  483. end
  484. TI_debug(npcname);
  485. if(TI_NPCDB[npcname]) then
  486. local thisnpc = TI_NPCDB[npcname];
  487. if(thisnpc.state) then
  488. TI_debug("npc is active, using his options");
  489. for i1,current in ipairs(thisnpc) do
  490. if (current.state == true) then
  491. TI_debug("Current Quest: "..current.name);
  492. if (TI_specnum == 0 or i1 > TI_specnum) then
  493. TI_specnum = i1;
  494. if (current.type == "availquest") then
  495. for i2,v2 in ipairs(AvailableQuests) do
  496. if (v2.name == current.name) then
  497. TI_debug(i1.."-Available Match Found: "..current.name);
  498. SAvQ(v2.questID);
  499. return;
  500. end
  501. end
  502. elseif (current.type == "activequest") then
  503. for i2,v2 in ipairs(ActiveQuests) do
  504. if (v2.name == current.name) then
  505. TI_debug(i1.."-Active Match Found: "..current.name..", "..current.type);
  506. SAcQ(v2.questID);
  507. return;
  508. end
  509. end
  510. else
  511. for i2,v2 in ipairs(GossipOptions) do
  512. if (v2.name == current.name) then
  513. TI_debug(i1.."-Gossip Match Found: "..current.name..", "..current.type);
  514. if(v2.args) then
  515. TI_FunctionList.g.gossip(v2.args);
  516. else
  517. TI_FunctionList.g.gossip(i2);
  518. end
  519. return;
  520. end
  521. end
  522. end
  523. end
  524. end
  525. end
  526. return;
  527. else
  528. TI_debug("npc in list, but not active");
  529. end
  530. else
  531. TI_debug("npc not in list");
  532. end
  533. if(TI_status.usedefault == false) then
  534. TI_debug("npc not in list, default set to off, returning.");
  535. return;
  536. end;
  537. TI_debug("using default config");
  538. for i,current in ipairs(TI_status.options) do
  539. if(current.state) then
  540. if(current.type == "availquest" and #AvailableQuests > 0 and TI_availnumber <= #AvailableQuests) then
  541. SAvQ(AvailableQuests[TI_availnumber].questID);
  542. TI_debug("Selecting Available Quest ".. TI_availnumber);
  543. return;
  544. elseif(current.type == "activequest" and #ActiveQuests > 0 and TI_activenumber <= #ActiveQuests) then
  545. while TI_activenumber <= #ActiveQuests do
  546. if ActiveQuests[TI_activenumber].isComplete then
  547. TI_debug("Selecting Active Quest ".. TI_activenumber .. " " .. ActiveQuests[TI_activenumber].name );
  548. SAcQ(ActiveQuests[TI_activenumber].questID);
  549. TI_ResetPointers();
  550. return;
  551. else
  552. TI_debug("Active Quest ".. TI_activenumber .. " " .. ActiveQuests[TI_activenumber].name .. " is not complete")
  553. TI_activenumber = TI_activenumber + 1;
  554. end
  555. end
  556. elseif(#GossipOptions > 0) then
  557. for j,val in ipairs(GossipOptions) do
  558. if(val.type == current.type) then
  559. TI_ResetPointers();
  560. TI_debug("Selecting Gossip Option "..j)
  561. TI_FunctionList.g.gossip(val.args);
  562. return;
  563. end
  564. end
  565. end
  566. end
  567. end
  568. end
  569. function TI_AddNPCToList(OptList, npcname, confirminquestion)
  570. if (npcname == nil) then
  571. npcname = UnitName("npc");
  572. end
  573. if(#OptList > 0) then
  574. if(TI_NPCDB[npcname] == nil) then
  575. TI_NPCDB[npcname] = TI_copyTable(OptList);
  576. table.insert(TI_NPCIndex, npcname);
  577. table.sort(TI_NPCIndex);
  578. TI_PopulateOptions("npclist updated");
  579. elseif(confirminquestion == true) then
  580. TI_NPCDB[npcname] = TI_copyTable(OptList);
  581. TI_PopulateOptions("npclist updated");
  582. else
  583. TI_NPCInQuestion = {name=npcname, list=OptList};
  584. StaticPopup_Show("TI_NPCINQUESTION", npcname);
  585. end
  586. end
  587. end
  588. function TI_AddNPCToTempList(name, list)
  589. local temp = {};
  590. temp.name = name;
  591. temp.list = list;
  592. local subZone = GetSubZoneText();
  593. local realZone = GetRealZoneText();
  594. if(subZone == "") then
  595. temp.location = realZone;
  596. else
  597. temp.location = subZone .. ", " .. realZone;
  598. end
  599. table.insert(TI_TempNPCList, 1, temp);
  600. if(#TI_TempNPCList > TI_TempNPCListMaxSize) then
  601. table.remove(TI_TempNPCList, TI_TempNPCListMaxSize);
  602. end
  603. TI_TempNPCListUpdate();
  604. end
  605. function TI_DeleteTempNPCIndex(index)
  606. table.remove(TI_TempNPCList, index);
  607. TI_TempNPCListUpdate();
  608. end
  609. function TI_AddTempNPCIndex(index)
  610. TI_AddNPCToList(TI_TempNPCList[index].list, TI_TempNPCList[index].name);
  611. end
  612. function TI_DeleteNPC(index)
  613. local name = TI_NPCIndex[index];
  614. table.remove(TI_NPCIndex, index);
  615. TI_NPCDB[name] = nil;
  616. end
  617. function TI_StripDescriptors(...)
  618. local x = {};
  619. local arg = {...};
  620. for i=1, #arg, 2 do
  621. table.insert(x,arg[i]);
  622. end
  623. return x;
  624. end
  625. function TI_TabulateGossipOptions_Classic(...)
  626. local x = {};
  627. local arg = {...};
  628. for i=1, #arg, 2 do
  629. local temp = {};
  630. temp.name = arg[i];
  631. temp.type = arg[i+1];
  632. table.insert(x, temp);
  633. end
  634. return x;
  635. end
  636. function TI_TabulateGossipQuestUIInfo_Retail(gquis)
  637. local x = {};
  638. for i,gqui in ipairs(gquis) do
  639. local temp = {};
  640. temp.name = gqui.title;
  641. temp.icon = QuestUtil.GetQuestIconOffer(
  642. gqui.isLegendary,
  643. gqui.frequency,
  644. gqui.isRepeatable,
  645. false,
  646. false
  647. );
  648. temp.questID = gqui.questID;
  649. temp.isComplete = gqui.isComplete;
  650. table.insert(x, temp);
  651. end
  652. return x;
  653. end
  654. function TI_TabulateGossipUIInfo_Retail(guis)
  655. local x = {};
  656. table.sort(guis, GossipOptionSort);
  657. for i,gui in ipairs(guis) do
  658. local temp = {};
  659. temp.name = gui.name;
  660. local gossipType = TI_TranslateIconToType(gui.icon)
  661. if gossipType == "chatbubble" then
  662. gossipType = "gossip"
  663. end
  664. temp.type = gossipType;
  665. temp.icon = gui.icon;
  666. temp.gossipOptionID = gui.gossipOptionID
  667. temp.orderIndex = gui.orderIndex
  668. if (TI_IsRetail()) then
  669. temp.args = gui.orderIndex
  670. else
  671. temp.args = i
  672. end
  673. table.insert(x, temp);
  674. end
  675. return x;
  676. end
  677. function TI_TabulateGossipAvailableQuests_Classic(gquis)
  678. local x = {};
  679. for i,gqui in ipairs(gquis) do
  680. local temp = {};
  681. temp.name = gqui.title;
  682. if ( gqui.repeatable ) then
  683. temp.icon = "Interface\\GossipFrame\\DailyQuestIcon";
  684. elseif ( gqui.isLegendary ) then
  685. temp.icon = "Interface\\GossipFrame\\AvailableLegendaryQuestIcon";
  686. else
  687. temp.icon = "Interface\\GossipFrame\\AvailableQuestIcon";
  688. end
  689. temp.questID = gqui.questID;
  690. temp.isComplete = gqui.isComplete;
  691. table.insert(x, temp);
  692. end
  693. return x;
  694. end
  695. function TI_TabulateGossipActiveQuests_Classic(gquis)
  696. local x = {};
  697. for i,gqui in ipairs(gquis) do
  698. local temp = {};
  699. temp.name = gqui.title;
  700. if ( gqui.repeatable ) then
  701. temp.icon = "Interface\\GossipFrame\\DailyQuestIcon";
  702. elseif ( gqui.isLegendary ) then
  703. temp.icon = "Interface\\GossipFrame\\AvailableLegendaryQuestIcon";
  704. else
  705. temp.icon = "Interface\\GossipFrame\\AvailableQuestIcon";
  706. end
  707. temp.questID = gqui.questID;
  708. temp.isComplete = gqui.isComplete;
  709. table.insert(x, temp);
  710. end
  711. return x;
  712. end
  713. -- set up functions by release type
  714. if (TI_IsRetail()) then
  715. TI_FunctionList = {
  716. g = {
  717. availquest = C_GossipInfo.SelectAvailableQuest,
  718. activequest = C_GossipInfo.SelectActiveQuest,
  719. gossip = C_GossipInfo.SelectOptionByIndex,
  720. getavailquests = C_GossipInfo.GetAvailableQuests,
  721. getactivequests = C_GossipInfo.GetActiveQuests,
  722. getoptions = C_GossipInfo.GetOptions,
  723. tabulateAvailable = TI_TabulateGossipQuestUIInfo_Retail,
  724. tabulateActive = TI_TabulateGossipQuestUIInfo_Retail,
  725. tabulateOptions = TI_TabulateGossipUIInfo_Retail,
  726. },
  727. q = {
  728. activequest = SelectActiveQuest,
  729. availquest = SelectAvailableQuest,
  730. }
  731. };
  732. else
  733. TI_FunctionList = {
  734. g = {
  735. availquest = C_GossipInfo.SelectAvailableQuest,
  736. activequest = C_GossipInfo.SelectActiveQuest,
  737. gossip = SelectGossipOption,
  738. getavailquests = C_GossipInfo.GetAvailableQuests,
  739. getactivequests = C_GossipInfo.GetActiveQuests,
  740. getoptions = C_GossipInfo.GetOptions,
  741. tabulateAvailable = TI_TabulateGossipAvailableQuests_Classic,
  742. tabulateActive = TI_TabulateGossipActiveQuests_Classic,
  743. tabulateOptions = TI_TabulateGossipUIInfo_Retail,
  744. },
  745. q = {
  746. activequest = SelectActiveQuest,
  747. availquest = SelectAvailableQuest,
  748. }
  749. };
  750. end
  751. --[[this function stolen from WhisperCast by Sarris, whom I love dearly for his contribution to Paladins everywhere.
  752. ]]
  753. function TI_copyTable( src )
  754. local copy = {}
  755. for k1,v1 in pairs(src) do
  756. if ( type(v1) == "table" ) then
  757. copy[k1]=TI_copyTable(v1)
  758. else
  759. copy[k1]=v1
  760. end
  761. end
  762. return copy
  763. end
  764. function toggle(arg)
  765. if(arg) then
  766. return false;
  767. else
  768. return true;
  769. end
  770. end