aggixx

Untitled

Dec 12th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.67 KB | None | 0 0
  1. -- Load the libraries
  2. local ScrollingTable = LibStub("ScrollingTable")
  3. local libSerialize = LibStub:GetLibrary("AceSerializer-3.0")
  4. local libCompress = LibStub:GetLibrary("LibCompress")
  5. local libEncode = libCompress:GetAddonEncodeTable()
  6.  
  7. -- Declare local variables
  8. local hyperlinkPattern = "\124%x+\124Hitem:%d+:%d+:%d+:%d+:%d+:%d+:%-?%d+:%-?%d+:?%d*:?%d*:?%d*:?%d*:?%d*:?%d*:?%d*\124h.+\124h\124r"
  9.  
  10. local table_mainData = {}
  11. local table_bids = {}
  12. local table_itemQuery = {}
  13. local table_expTimes = {}
  14. local table_nameAssociations = {}
  15. local table_icons = {}
  16. local table_who = {}
  17.  
  18. local debugOn = false
  19. local lastLootSetting = 0
  20. local hasBeenLooted = {}
  21. local expTime = 15 -- TODO: Add this as an option
  22. local tableMode = 0
  23.  
  24. local showAfterCombat
  25. local iconSelect
  26. local endPrompt
  27. local bidPrompt
  28. local promptBidValue
  29. local windowPosition
  30. local ALTsetting
  31. local ALsetting
  32. local addonVersion
  33.  
  34. --helper functions
  35. local function compress(input)
  36. local serialized, msg = libSerialize:Serialize(input)
  37. if not serialized then
  38. if debugOn then print("RT: Serialization of data failed!") end
  39. return
  40. end
  41. --[[local compressed, msg = libCompress:CompressHuffman(serialized)
  42. if not compressed then
  43. print("RT: Compression of data failed!")
  44. return
  45. end
  46. local encoded, msg = libEncode:Encode(compressed)--]]
  47. local encoded, msg = libEncode:Encode(serialized)
  48. if not encoded then
  49. if debugOn then print("RT: Encoding of data failed!") end
  50. return
  51. end
  52. return encoded, msg
  53. end
  54.  
  55. local function decompress(input)
  56. -- Decode the compressed data
  57. local one = libEncode:Decode(input)
  58. --Decompress the decoded data
  59. --[[local two, message = libCompress:Decompress(one)
  60. if not two then
  61. print("RT: Decompression of data failed: "..message)
  62. return
  63. end
  64. -- Deserialize the decompressed data
  65. local success, final = libSerialize:Deserialize(two)--]]
  66. local success, final = libSerialize:Deserialize(one)
  67. if not success then
  68. if debugOn then print("RT: Deserialization of data failed: "..final) end
  69. return
  70. end
  71. return final
  72. end
  73.  
  74. local function str_split(delimiter, text)
  75. local list = {}
  76. local pos = 1
  77. if strfind("", delimiter, 1) then -- this would result in endless loops
  78. error("delimiter matches empty string!")
  79. end
  80. while 1 do
  81. local first, last = strfind(text, delimiter, pos)
  82. if first then -- found?
  83. tinsert(list, strsub(text, pos, first-1))
  84. pos = last+1
  85. else
  86. tinsert(list, strsub(text, pos))
  87. break
  88. end
  89. end
  90. return list
  91. end
  92.  
  93. local function stripItemData(itemLink)
  94. local _, _, Color, Ltype, Id, Enchant, Gem1, Gem2, Gem3, Gem4, Suffix, Unique, LinkLvl, reforging, Name = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*):%d+|?h?%[?([^%[%]]*)%]?|?h?|?r?")
  95. return "|"..Color.."|Hitem:"..Id..":"..Suffix.."|h["..Name.."]|h|r"
  96. end
  97.  
  98. local function isNameInGuild(name)
  99. SetGuildRosterShowOffline(false)
  100. local _, onlineguildies = GetNumGuildMembers()
  101. for j=1,onlineguildies do
  102. local jname = GetGuildRosterInfo(j)
  103. if jname == name then
  104. return true
  105. end
  106. end
  107. end
  108.  
  109. local function isGuildGroup()
  110. GuildRoster()
  111. local groupType
  112. if IsInRaid() then
  113. groupType = "raid"
  114. else
  115. groupType = "party"
  116. end
  117. local raidsize = GetNumGroupMembers()
  118. local numguildies = 0
  119. local numOffline = 0
  120. for i=1,raidsize do
  121. local iname = GetRaidRosterInfo(i)
  122. if isNameInGuild(iname) then
  123. numguildies = numguildies + 1
  124. end
  125. if not UnitIsConnected(groupType..i) then
  126. numOffline = numOffline + 1
  127. end
  128. end
  129. if (numguildies/(raidsize-numOffline) > 0.60) then
  130. return true
  131. else
  132. return false
  133. end
  134. end
  135.  
  136. local function StaticDataSave(data)
  137. promptBidValue = data
  138. end
  139.  
  140. --Create GUI elements
  141. local cols = {
  142. {
  143. ["name"] = "Name",
  144. ["width"] = 200,
  145. ["align"] = "LEFT",
  146. ["color"] = {
  147. ["r"] = 1.0,
  148. ["g"] = 1.0,
  149. ["b"] = 1.0,
  150. ["a"] = 1.0
  151. },
  152. ["colorargs"] = nil,
  153. ["defaultsort"] = "asc",
  154. ["DoCellUpdate"] = nil,
  155. },
  156. {
  157. ["name"] = "Status",
  158. ["width"] = 60,
  159. ["align"] = "LEFT",
  160. ["color"] = {
  161. ["r"] = 1.0,
  162. ["g"] = 1.0,
  163. ["b"] = 1.0,
  164. ["a"] = 1.0
  165. },
  166. ["colorargs"] = nil,
  167. ["defaultsort"] = "dsc",
  168. ["DoCellUpdate"] = nil,
  169. },
  170. {
  171. ["name"] = "Winners",
  172. ["width"] = 150,
  173. ["align"] = "LEFT",
  174. ["color"] = {
  175. ["r"] = 1.0,
  176. ["g"] = 1.0,
  177. ["b"] = 1.0,
  178. ["a"] = 1.0
  179. },
  180. ["colorargs"] = nil,
  181. ["defaultsort"] = "dsc",
  182. ["DoCellUpdate"] = nil,
  183. }
  184. }
  185. FA_RTframe = CreateFrame("frame", "FALoot")
  186. FA_RTframe:SetBackdrop({
  187. bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  188. tile = true,
  189. tileSize = 16
  190. })
  191. FA_RTframe:SetBackdropColor(0, 0, 0, 0.6)
  192. FA_RTframe:SetWidth(460)
  193. FA_RTframe:SetHeight(235)
  194. FA_RTframe:SetPoint("CENTER", 0, 100)
  195. FA_RTframe:SetMovable(true)
  196. FA_RTframe:SetScript("OnMouseDown", function(self, button)
  197. if button == "LeftButton" then
  198. self:StartMoving()
  199. end
  200. end)
  201. FA_RTframe:SetScript("OnMouseUp", function(self, button)
  202. if button == "LeftButton" then
  203. self:StopMovingOrSizing()
  204. end
  205. end)
  206. FA_RTframe:Hide()
  207. FA_RTbutton1 = CreateFrame("button", "FA_RTbutton", FA_RTframe)
  208. FA_RTbutton1:SetPoint("BOTTOMLEFT", FA_RTframe, "BOTTOMLEFT", 11, -2)
  209. FA_RTbutton1:SetNormalTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Up.png")
  210. FA_RTbutton1:SetPushedTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Down.png")
  211. FA_RTbutton1:SetDisabledTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Disabled.png")
  212. FA_RTbutton1:SetHeight(25)
  213. FA_RTbutton1:SetWidth(60)
  214. FA_RTbutton1text = FA_RTbutton1:CreateFontString("FA_RTbutton_text")
  215. FA_RTbutton1text:SetPoint("CENTER", FA_RTbutton1, "CENTER", 0, 4)
  216. FA_RTbutton1text:SetFont(GameFontNormal:GetFont(), 10, "")
  217. FA_RTbutton1text:SetText("Mode")
  218. FA_RTbutton1text:SetTextColor(1, 1, 1)
  219. FA_RTbutton1:Show()
  220.  
  221. FA_RTbutton2 = CreateFrame("button", "FA_RTbutton", FA_RTframe)
  222. FA_RTbutton2:SetPoint("LEFT", FA_RTbutton1, "RIGHT", 5, 0)
  223. FA_RTbutton2:SetNormalTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Up.png")
  224. FA_RTbutton2:SetPushedTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Down.png")
  225. FA_RTbutton2:SetDisabledTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Disabled.png")
  226. FA_RTbutton2:SetHeight(25)
  227. FA_RTbutton2:SetWidth(60)
  228. FA_RTbutton2text = FA_RTbutton2:CreateFontString("FA_RTbutton_text")
  229. FA_RTbutton2text:SetPoint("CENTER", FA_RTbutton2, "CENTER", 0, 4)
  230. FA_RTbutton2text:SetFont(GameFontNormal:GetFont(), 10, "")
  231. FA_RTbutton2text:SetText("Bid")
  232. FA_RTbutton2text:SetTextColor(1, 1, 1)
  233. FA_RTbutton2:Show()
  234.  
  235. FA_RTbutton3 = CreateFrame("button", "FA_RTbutton", FA_RTframe)
  236. FA_RTbutton3:SetPoint("LEFT", FA_RTbutton2, "RIGHT", 5, 0)
  237. FA_RTbutton3:SetNormalTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Up.png")
  238. FA_RTbutton3:SetPushedTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Down.png")
  239. FA_RTbutton3:SetDisabledTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Disabled.png")
  240. FA_RTbutton3:SetHeight(25)
  241. FA_RTbutton3:SetWidth(60)
  242. FA_RTbutton3text = FA_RTbutton3:CreateFontString("FA_RTbutton_text")
  243. FA_RTbutton3text:SetPoint("CENTER", FA_RTbutton3, "CENTER", 0, 4)
  244. FA_RTbutton3text:SetFont(GameFontNormal:GetFont(), 10, "")
  245. FA_RTbutton3text:SetText("Edit")
  246. FA_RTbutton3text:SetTextColor(1, 1, 1)
  247. FA_RTbutton3:Show()
  248. FA_RTbutton3:SetScript("OnMouseUp", function(self, button)
  249. if button == "LeftButton" then
  250. if FA_RTscrollingtable:GetSelection() then
  251. StaticPopupDialogs["FA_RTTEXT_EDIT"]["text"] = "Edit Winners for "..table_mainData[FA_RTscrollingtable:GetSelection()]["cols"][1]["value"]..":"
  252. StaticPopup_Show("FA_RTTEXT_EDIT")
  253. end
  254. end
  255. end)
  256.  
  257. FA_RTbutton4 = CreateFrame("button", "FA_RTbutton", FA_RTframe)
  258. FA_RTbutton4:SetPoint("TOPRIGHT", FA_RTframe, "TOPRIGHT", -12, -5)
  259. FA_RTbutton4:SetNormalTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Up.png")
  260. FA_RTbutton4:SetPushedTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Down.png")
  261. FA_RTbutton4:SetDisabledTexture("Interface\\BUTTONS\\UI-DialogBox-Button-Disabled.png")
  262. FA_RTbutton4:SetHeight(25)
  263. FA_RTbutton4:SetWidth(15)
  264. FA_RTbutton4text = FA_RTbutton3:CreateFontString("FA_RTbutton_text")
  265. FA_RTbutton4text:SetPoint("CENTER", FA_RTbutton4, "CENTER", 0, 4)
  266. FA_RTbutton4text:SetFont(GameFontNormal:GetFont(), 10, "")
  267. FA_RTbutton4text:SetText("X")
  268. FA_RTbutton4text:SetTextColor(1, 1, 1)
  269. FA_RTbutton4:Show()
  270. FA_RTbutton4:SetScript("OnMouseUp", function(self, button)
  271. self:GetParent():Hide()
  272. end)
  273.  
  274. FA_RTscrollingtable = ScrollingTable:CreateST(cols, 9, nil, {["r"] = 0, ["g"] = 1, ["b"] = 0, ["a"] = 0.3}, FA_RTframe)
  275. FA_RTscrollingtable:EnableSelection(true)
  276. FA_RTscrollingtable.frame:SetPoint("CENTER", FA_RTframe, "CENTER", 0, -22.5)
  277. FA_RTicons = CreateFrame("frame", "FA_RTicons", FA_RTframe)
  278. FA_RTicons:SetHeight(30)
  279. FA_RTicons:SetWidth(400)
  280. FA_RTicons:SetPoint("BOTTOM", FA_RTscrollingtable.frame, "TOP", 0, 22.5)
  281. FA_RTicons:Show()
  282. --
  283. local cols2 = {
  284. {
  285. ["name"] = "Date",
  286. ["width"] = 105,
  287. ["align"] = "LEFT",
  288. ["color"] = {
  289. ["r"] = 1.0,
  290. ["g"] = 1.0,
  291. ["b"] = 1.0,
  292. ["a"] = 1.0
  293. },
  294. ["colorargs"] = nil,
  295. ["defaultsort"] = "asc",
  296. ["DoCellUpdate"] = nil,
  297. },
  298. {
  299. ["name"] = "Name",
  300. ["width"] = 155,
  301. ["align"] = "LEFT",
  302. ["color"] = {
  303. ["r"] = 1.0,
  304. ["g"] = 1.0,
  305. ["b"] = 1.0,
  306. ["a"] = 1.0
  307. },
  308. ["colorargs"] = nil,
  309. ["defaultsort"] = "dsc",
  310. ["DoCellUpdate"] = nil,
  311. },
  312. {
  313. ["name"] = "Winners",
  314. ["width"] = 150,
  315. ["align"] = "LEFT",
  316. ["color"] = {
  317. ["r"] = 1.0,
  318. ["g"] = 1.0,
  319. ["b"] = 1.0,
  320. ["a"] = 1.0
  321. },
  322. ["colorargs"] = nil,
  323. ["defaultsort"] = "dsc",
  324. ["DoCellUpdate"] = nil,
  325. }
  326. }
  327. FA_RTscrollingtable2 = ScrollingTable:CreateST(cols2, 9, nil, {["r"] = 0, ["g"] = 1, ["b"] = 0, ["a"] = 0.3}, FA_RTframe)
  328. FA_RTscrollingtable2.frame:SetPoint("CENTER", FA_RTframe, "CENTER", 0, -22.5)
  329. FA_RTscrollingtable2:Hide()
  330. --
  331. local cols3 = {
  332. {
  333. ["name"] = "Name",
  334. ["width"] = 150,
  335. ["align"] = "LEFT",
  336. ["color"] = {
  337. ["r"] = 1.0,
  338. ["g"] = 1.0,
  339. ["b"] = 1.0,
  340. ["a"] = 1.0
  341. },
  342. ["colorargs"] = nil,
  343. ["defaultsort"] = "asc",
  344. ["DoCellUpdate"] = nil,
  345. },
  346. {
  347. ["name"] = "Bid",
  348. ["width"] = 30,
  349. ["align"] = "LEFT",
  350. ["color"] = {
  351. ["r"] = 1.0,
  352. ["g"] = 1.0,
  353. ["b"] = 1.0,
  354. ["a"] = 1.0
  355. },
  356. ["colorargs"] = nil,
  357. ["defaultsort"] = "dsc",
  358. ["DoCellUpdate"] = nil,
  359. },
  360. {
  361. ["name"] = "Status",
  362. ["width"] = 80,
  363. ["align"] = "LEFT",
  364. ["color"] = {
  365. ["r"] = 1.0,
  366. ["g"] = 1.0,
  367. ["b"] = 1.0,
  368. ["a"] = 1.0
  369. },
  370. ["colorargs"] = nil,
  371. ["defaultsort"] = "dsc",
  372. ["DoCellUpdate"] = nil,
  373. }
  374. }
  375. FA_RTbidframe = CreateFrame("frame", "FALoot_bid", FA_RTframe)
  376. FA_RTbidframe:SetBackdrop({
  377. bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  378. tile = true,
  379. tileSize = 16
  380. })
  381. FA_RTbidframe:SetBackdropColor(0, 0, 0, 0.6)
  382. FA_RTbidframe:SetWidth(295)
  383. FA_RTbidframe:SetHeight(75)
  384. FA_RTbidframe:SetPoint("TOP", FA_RTframe, "BOTTOM", 0, 0)
  385. FA_RTbidframe:Hide()
  386. FA_RTscrollingtable3 = ScrollingTable:CreateST(cols3, 3, nil, {["r"] = 0, ["g"] = 1, ["b"] = 0, ["a"] = 0.3}, FA_RTbidframe)
  387. FA_RTscrollingtable3.frame:SetPoint("CENTER", FA_RTbidframe, "CENTER", 0, -8)
  388. FA_RTscrollingtable3:Show()
  389. FA_RTscrollingtable3:SetData(table_bids, true)
  390.  
  391. for i=1,13 do
  392. table_icons[i] = CreateFrame("frame", "FA_RTicon"..tostring(i), FA_RTicons)
  393. table_icons[i]:SetWidth(30)
  394. table_icons[i]:SetHeight(30)
  395. table_icons[i]:Hide()
  396. end
  397.  
  398. local function modeSet(num)
  399. if num == 0 then
  400. tableMode = 0
  401. FA_RTscrollingtable:Show()
  402. FA_RTscrollingtable2:Hide()
  403. elseif num == 1 then
  404. tableMode = 1
  405. FA_RTscrollingtable2:Show()
  406. FA_RTscrollingtable:Hide()
  407. end
  408. end
  409.  
  410. FA_RTbutton1:SetScript("OnMouseUp", function(self, button) -- This needs to be after modeSet otherwise we get errors.
  411. if tableMode == 1 then
  412. modeSet(0)
  413. elseif tableMode == 0 then
  414. modeSet(1)
  415. end
  416. end)
  417.  
  418. local function generateIcons()
  419. local lasticon = nil -- reference value for anchoring to the most recently constructed icon
  420. local firsticon = nil -- reference value for anchoring the first constructed icon
  421. local k = 0 -- this variable contains the number of the icon we're currently constructing, necessary because we need to be able to create multiple icons per entry in the table
  422. for i=1,13 do -- loop through the table of icons and reset everything
  423. table_icons[i]:Hide()
  424. table_icons[i]:ClearAllPoints()
  425. table_icons[i]:SetBackdrop({
  426. bgFile = nil,
  427. })
  428. table_icons[i]:SetScript("OnEnter", nil)
  429. table_icons[i]:SetScript("OnLeave", nil)
  430. end
  431. for i=1,#table_mainData do -- loop through each row of data
  432. local itemIcon = GetItemIcon(table_mainData[i]["cols"][1]["value"]) -- retrieve path to item icon
  433. local itemCount = tonumber(string.match(table_mainData[i]["cols"][1]["value"], "]\124h\124rx(%d+)")) or 1 -- parse how many there are of this item so we know how many icons to create
  434. for j=1,itemCount do
  435. if k < #table_icons then -- if we're constructing an icon number that's higher than what we're setup to display then just skip it
  436. k = k + 1 -- increment k by 1 before starting to construct
  437. table_icons[k]:SetBackdrop({ -- set the texture of the icon
  438. bgFile = itemIcon,
  439. })
  440. table_icons[k]:SetScript("OnEnter", function(self, button) -- set code that triggers on mouse enter
  441. local iconNum = tonumber(string.match(self:GetName(), "%d+$"))
  442. local total = 0
  443. local id
  444. for i=1,#table_mainData do -- figure out what row of data associates to this icon by counting up the quanities of each row
  445. local quantity = tonumber(string.match(table_mainData[i]["cols"][1]["value"], "]\124h\124rx(%d+)")) or 1
  446. total = total + quantity
  447. if total >= iconNum then
  448. id = i
  449. break
  450. end
  451. end
  452.  
  453. --table select stuff
  454. iconSelect = FA_RTscrollingtable:GetSelection() -- store what row was selected so we can restore it later
  455. FA_RTscrollingtable:SetSelection(id) -- select the row that correlates to the icon
  456.  
  457. --tooltip stuff
  458. GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  459. GameTooltip:SetHyperlink(string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern))
  460. GameTooltip:Show()
  461. end)
  462. table_icons[k]:SetScript("OnLeave", function(self, button) -- set code that triggers on mouse exit
  463. --table select stuff
  464. FA_RTscrollingtable:SetSelection(iconSelect) -- restore the row that was selected before we mousedover this icon
  465. iconSelect = nil
  466.  
  467. --tooltip stuff
  468. GameTooltip:Hide()
  469. end)
  470. table_icons[k]:SetScript("OnMouseUp", function(self, button) -- set code that triggers on clicks
  471. if button == "LeftButton" then -- left click: Selects the clicked row
  472. local iconNum = tonumber(string.match(self:GetName(), "%d+$"))
  473. local total = 0
  474. local id
  475. for i=1,#table_mainData do -- figure out what row of data associates to this icon by counting up the quanities of each row
  476. local quantity = tonumber(string.match(table_mainData[i]["cols"][1]["value"], "]\124h\124rx(%d+)")) or 1
  477. total = total + quantity
  478. if total >= iconNum then
  479. id = i
  480. break
  481. end
  482. end
  483.  
  484. --table select stuff
  485. iconSelect = id
  486. end
  487. if button == "RightButton" then -- right click: Ends the item for everyone in the raid. Requires RA or RL.
  488. if UnitIsGroupAssistant("PLAYER") or UnitIsGroupLeader("PLAYER") or not UnitInRaid("PLAYER") then
  489. local iconNum = tonumber(string.match(self:GetName(), "%d+$"))
  490. local total = 0
  491. local id
  492. for i=1,#table_mainData do -- figure out what row of data associates to this icon by counting up the quanities of each row
  493. local quantity = tonumber(string.match(table_mainData[i]["cols"][1]["value"], "]\124h\124rx(%d+)")) or 1
  494. total = total + quantity
  495. if total >= iconNum then
  496. id = i
  497. break
  498. end
  499. end
  500.  
  501. --remove command stuff
  502. endPrompt = coroutine.create( function(self)
  503. local msg = stripItemData(string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern))
  504. StaticPopup_Show("FA_RTEND_CONFIRM")
  505. coroutine.yield()
  506. SendAddonMessage("FA_RT", compress({"end", addonVersion, msg}), "RAID")
  507. table_mainData[id]["cols"][2]["value"] = "Ended"
  508. table_mainData[id]["cols"][2]["color"]["r"] = 0.5
  509. table_mainData[id]["cols"][2]["color"]["g"] = 0.5
  510. table_mainData[id]["cols"][2]["color"]["b"] = 0.5
  511. table_mainData[id]["cols"][2]["color"]["a"] = 1
  512. FA_RTscrollingtable:SetData(table_mainData, false)
  513. table.insert(table_expTimes, {string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern), GetTime()})
  514. end)
  515. coroutine.resume(endPrompt)
  516. end
  517. end
  518. end)
  519. if lasticon then -- if this isn't the first icon then anchor it to the previous icon
  520. table_icons[k]:SetPoint("LEFT", lasticon, "RIGHT", 1, 0)
  521. end
  522. table_icons[k]:Show() -- show the icon we just constructed
  523. lasticon = table_icons[k] -- set the icon we just constructed as the most recently constructed icon
  524. end
  525. end
  526. end
  527. table_icons[1]:SetPoint("LEFT", FA_RTicons, "LEFT", (401-(k*31))/2, 0) -- anchor the first icon in the row so that the row is centered in the window
  528. end
  529.  
  530. SLASH_RT1 = "/rt"
  531. local function slashparse(msg, editbox)
  532. if msg == "" then
  533. FA_RTframe:Show()
  534. else
  535. local msg = str_split(" ", msg)
  536. if msg[1]:lower() == "debug" then
  537. if #msg == 2 then
  538. if msg[2]:lower() == "true" or msg[2]:lower() == "false" then
  539. if msg[2]:lower() == "false" then
  540. debugOn = false
  541. else
  542. debugOn = true
  543. end
  544. else
  545. print("Invalid syntax for /rt "..msg[1]:lower()..". Invalid value for parameter #2.")
  546. end
  547. else
  548. print("Invalid syntax for /rt "..msg[1]:lower()..". Incorrect number of parameters.")
  549. end
  550. elseif msg[1]:lower() == "who" then
  551. if #msg == 1 then
  552. SendAddonMessage("FA_RT", compress({"who", "query"}), "RAID")
  553. else
  554. print("Invalid syntax for /rt "..msg[1]:lower()..". Incorrect number of parameters.")
  555. end
  556. end
  557. end
  558. end
  559. SlashCmdList["RT"] = slashparse
  560. SLASH_FAROLL1 = "/faroll"
  561. local function faRoll(value)
  562. value = tonumber(value)
  563. if value % 2 ~= 0 then
  564. print("You are not allowed to bid odd numbers or non-integers. Your bid has been rounded down to the nearest even integer.")
  565. value = math.floor(value)
  566. if value % 2 == 1 then
  567. value = value - 1
  568. end
  569. end
  570. if value > 30 then
  571. RandomRoll((value-30)/2, ((value-30)/2)+30)
  572. elseif value == 30 or value == 20 or value == 10 then
  573. RandomRoll(1, value)
  574. else
  575. print("Invalid roll value!")
  576. end
  577. end
  578. SlashCmdList["FAROLL"] = faRoll
  579.  
  580. local function FA_RTbid(itemLink, bid)
  581. bid = tostring(bid)
  582. if debugOn then print("FA_RTbid("..itemLink..", "..bid..")") end
  583. local name = nil
  584. for i=1,#table_nameAssociations do
  585. if stripItemData(table_nameAssociations[i][1]) == stripItemData(itemLink) then
  586. name = table_nameAssociations[i][2]
  587. break
  588. end
  589. end
  590. local id = nil
  591. for i=1,#table_mainData do
  592. if stripItemData(string.match(table_mainData[i]["cols"][1]["value"], hyperlinkPattern)) == stripItemData(itemLink) then
  593. id = i
  594. break
  595. end
  596. end
  597. if id == nil then
  598. if debugOn then print("bid(): ID returned nil, aborting.") end
  599. return
  600. end
  601. local sent = true
  602. if name == nil then sent = false end
  603. if string.match(table_mainData[id]["cols"][2]["value"], "(Tells)") then
  604. local at = tonumber(string.match(table_mainData[id]["cols"][2]["value"], "^%d%d"))
  605. if at == tonumber(bid) or (at == 30 and tonumber(bid) > 30) then
  606. SendChatMessage(tostring(bid), "WHISPER", nil, name)
  607. table.insert(table_bids, {itemLink, bid, "Waiting to roll..."})
  608. else
  609. sent = false
  610. end
  611. else
  612. sent = false
  613. end
  614. if sent == false then
  615. table.insert(table_bids, {itemLink, bid, "Waiting to bid..."})
  616. FA_RTscrollingtable3:SetData(table_bids, true)
  617. if debugOn then print("FA_RTbid(): Queued bid.") end
  618. else
  619. if debugOn then print("FA_RTbid(): Sent bid.") end
  620. end
  621. end
  622.  
  623. StaticPopupDialogs["BID_AMOUNT_QUERY"] = {
  624. text = "How much would you like to bid?",
  625. button1 = "Bid",
  626. button2 = CANCEL,
  627. timeout = 0,
  628. whileDead = true,
  629. hideOnEscape = true,
  630. OnShow = function (self, data)
  631. self.editBox:SetText("")
  632. end,
  633. OnAccept = function (self2, data, data2)
  634. StaticDataSave(self2.editBox:GetText())
  635. coroutine.resume(bidPrompt)
  636. end,
  637. hasEditBox = true,
  638. enterClicksFirstButton = 1
  639. }
  640.  
  641. FA_RTbutton2:SetScript("OnMouseUp", function(self, button)
  642. if button == "LeftButton" then
  643. local id = FA_RTscrollingtable:GetSelection()
  644. local link = string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern)
  645. bidPrompt = coroutine.create( function(self)
  646. StaticPopupDialogs["BID_AMOUNT_QUERY"]["text"] = "How much would you like to bid for "..string.match(table_mainData[FA_RTscrollingtable:GetSelection()]["cols"][1]["value"], hyperlinkPattern).."?"
  647. StaticPopup_Show("BID_AMOUNT_QUERY")
  648. if debugOn then print("Querying for bid, coroutine paused.") end
  649. coroutine.yield()
  650. if debugOn then print("Bid recieved, resuming coroutine.") end
  651. promptBidValue = tonumber(promptBidValue)
  652. if promptBidValue < 30 and promptBidValue ~= 10 and promptBidValue ~= 20 then
  653. print("You must bid 10, 20, 30, or a value greater than 30. Your bid has been cancelled.")
  654. return
  655. end
  656. if promptBidValue % 2 ~= 0 then
  657. print("You are not allowed to bid odd numbers or non-integers. Your bid has been rounded down to the nearest even integer.")
  658. promptBidValue = math.floor(promptBidValue)
  659. if promptBidValue % 2 == 1 then
  660. promptBidValue = promptBidValue - 1
  661. end
  662. end
  663. if debugOn then print("Passed info onto FA_RTbid().") end
  664. FA_RTbid(link, promptBidValue)
  665. end)
  666. coroutine.resume(bidPrompt)
  667. end
  668. end)
  669.  
  670. StaticPopupDialogs["FA_RTEND_CONFIRM"] = {
  671. text = "Are you sure you want to manually end this item for all players in the raid?",
  672. button1 = YES,
  673. button2 = CANCEL,
  674. timeout = 0,
  675. whileDead = true,
  676. hideOnEscape = true,
  677. OnAccept = function()
  678. coroutine.resume(endPrompt)
  679. end,
  680. enterClicksFirstButton = 1
  681. }
  682. StaticPopupDialogs["FA_RTTEXT_EDIT"] = {
  683. text = "",
  684. button1 = ACCEPT,
  685. button2 = CANCEL,
  686. timeout = 0,
  687. whileDead = true,
  688. hideOnEscape = true,
  689. hasEditBox = true,
  690. OnShow = function(self)
  691. self.editBox:SetText(table_mainData[FA_RTscrollingtable:GetSelection()]["cols"][3]["value"] or "")
  692. end,
  693. OnAccept = function(self)
  694. table_mainData[FA_RTscrollingtable:GetSelection()]["cols"][3]["value"] = self.editBox:GetText()
  695. FA_RTscrollingtable:SetData(table_mainData, false)
  696. end,
  697. enterClicksFirstButton = 1
  698. }
  699.  
  700. local function valueFormat(itemLink, value)
  701. if debugOn then print("valueFormat("..itemLink..", "..tostring(value)..")") end
  702. local id
  703. for i=1,#table_mainData do
  704. if stripItemData(string.match(table_mainData[i]["cols"][1]["value"], hyperlinkPattern)) == stripItemData(itemLink) then
  705. id = i
  706. if debugOn then print("valueFormat(): Found match in data table. ID #"..id) end
  707. break
  708. end
  709. end
  710. if not id then
  711. if debugOn then print("valueFormat(): No match found in data table. Aborting.") end
  712. return
  713. end
  714. local message_value = string.match(value, "[321]0")
  715. local table_value = string.match(table_mainData[id]["cols"][2]["value"], "[321]0")
  716. if message_value then
  717. table_mainData[id]["cols"][2]["value"] = message_value.." (Tells)"
  718. table_mainData[id]["cols"][2]["color"]["r"] = 0
  719. table_mainData[id]["cols"][2]["color"]["g"] = 1
  720. table_mainData[id]["cols"][2]["color"]["b"] = 0
  721. table_mainData[id]["cols"][2]["color"]["a"] = 1
  722. elseif string.match(string.lower(value), "roll") then
  723. if table_value then
  724. table_mainData[id]["cols"][2]["value"] = table_value.." (Rolls)"
  725. end
  726. table_mainData[id]["cols"][2]["color"]["r"] = 1
  727. table_mainData[id]["cols"][2]["color"]["g"] = 0
  728. table_mainData[id]["cols"][2]["color"]["b"] = 0
  729. table_mainData[id]["cols"][2]["color"]["a"] = 1
  730. else
  731. if table_mainData[id]["cols"][3]["value"] ~= "" then
  732. table_mainData[id]["cols"][3]["value"] = table_mainData[id]["cols"][3]["value"]..", "
  733. end
  734. if string.match(table_mainData[id]["cols"][2]["value"], "30") then
  735. table_mainData[id]["cols"][3]["value"] = table_mainData[id]["cols"][3]["value"]..string.gsub(value, ",", " (30+),").." (30+)"
  736. elseif string.match(table_mainData[id]["cols"][2]["value"], "20") then
  737. table_mainData[id]["cols"][3]["value"] = table_mainData[id]["cols"][3]["value"]..string.gsub(value, ",", " (20),").." (20)"
  738. elseif string.match(table_mainData[id]["cols"][2]["value"], "10") then
  739. table_mainData[id]["cols"][3]["value"] = table_mainData[id]["cols"][3]["value"]..string.gsub(value, ",", " (10),").." (10)"
  740. end
  741. end
  742. if table_mainData[id]["cols"][3]["value"] == "" then
  743. wincount = 0
  744. else
  745. wincount = #str_split(",", table_mainData[id]["cols"][3]["value"])
  746. end
  747. itemcount = str_split("]\124h\124rx", table_mainData[id]["cols"][1]["value"])
  748. if #itemcount == 2 then
  749. itemcount = itemcount[2]
  750. else
  751. itemcount = "1"
  752. end
  753. itemcount = tonumber(itemcount)
  754. if wincount == itemcount then
  755. table_mainData[id]["cols"][2]["value"] = "Ended"
  756. table_mainData[id]["cols"][2]["color"]["r"] = 0.5
  757. table_mainData[id]["cols"][2]["color"]["g"] = 0.5
  758. table_mainData[id]["cols"][2]["color"]["b"] = 0.5
  759. table_mainData[id]["cols"][2]["color"]["a"] = 1
  760. table.insert(table_expTimes, {string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern), GetTime()})
  761. end
  762. FA_RTscrollingtable:SetData(table_mainData, false)
  763. end
  764.  
  765. local function addToLootWindow(itemLink)
  766. if debugOn then print("addToLootWindow("..itemLink..")") end
  767. local id
  768. for i=1,#table_mainData do
  769. local match = string.match(table_mainData[i]["cols"][1]["value"], hyperlinkPattern)
  770. if match == nil then
  771. print("Error: match returned nil. i="..i)
  772. DevTools_Dump(table_mainData[i])
  773. end
  774. local link1 = stripItemData(match)
  775. local link2 = stripItemData(itemLink)
  776. if link1 == link2 then
  777. id = i
  778. if debugOn then print("addToLootWindow(): Found match in data table. ID #"..id) end
  779. break
  780. end
  781. end
  782. if id then
  783. local quantity = tonumber(string.match(table_mainData[id]["cols"][1]["value"], "]\124h\124rx(%d+)")) or 1
  784. table_mainData[id]["cols"][1]["value"] = string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern).."x"..tostring(quantity+1)
  785. else
  786. local cell1 = {
  787. ["value"] = itemLink,
  788. ["args"] = nil,
  789. ["color"] = {
  790. ["r"] = 1.0,
  791. ["g"] = 1.0,
  792. ["b"] = 1.0,
  793. ["a"] = 1.0,
  794. },
  795. ["colorargs"] = nil,
  796. ["DoCellUpdate"] = nil,
  797. }
  798. local cell2 = {
  799. ["value"] = "30",
  800. ["args"] = nil,
  801. ["color"] = {
  802. ["r"] = 0.5,
  803. ["g"] = 0.5,
  804. ["b"] = 0.5,
  805. ["a"] = 1.0,
  806. },
  807. ["colorargs"] = nil,
  808. ["DoCellUpdate"] = nil,
  809. }
  810. local cell3 = {
  811. ["value"] = "",
  812. ["args"] = nil,
  813. ["color"] = {
  814. ["r"] = 1.0,
  815. ["g"] = 1.0,
  816. ["b"] = 1.0,
  817. ["a"] = 1.0,
  818. },
  819. ["colorargs"] = nil,
  820. ["DoCellUpdate"] = nil,
  821. }
  822. table.insert(table_mainData, {
  823. ["cols"] = {cell1, cell2, cell3},
  824. ["color"] = {
  825. ["r"] = 1.0,
  826. ["g"] = 0.0,
  827. ["b"] = 0.0,
  828. ["a"] = 1.0,
  829. },
  830. ["colorargs"] = nil,
  831. ["DoCellUpdate"] = nil,
  832. })
  833. end
  834. FA_RTscrollingtable:SetData(table_mainData, false)
  835. generateIcons()
  836. if not FA_RTframe:IsShown() then
  837. if UnitAffectingCombat("PLAYER") then
  838. showAfterCombat = true
  839. print("RT: "..itemLink.." was found but the player is in combat.")
  840. else
  841. FA_RTframe:Show()
  842. end
  843. end
  844. end
  845.  
  846. local function cacheItem(itemLink)
  847. if debugOn then print("cacheItem("..itemLink..")") end
  848. itemName = GetItemInfo(itemLink)
  849. if itemName == nil then -- check if item is cached or if we need to query it from the server
  850. if debugOn then print("cacheItem(): Item info for item "..itemLink.." requested from server.") end
  851. table.insert(table_itemQuery, itemLink) -- add to the query queue
  852. else
  853. if debugOn then print("cacheItem(): Item already cached, adding to loot window.") end
  854. addToLootWindow(itemLink) -- item is already cached so we can just add it now
  855. end
  856. end
  857.  
  858. local function removeFromLootWindow(itemLink)
  859. id = nil
  860. for i=1,#table_mainData do
  861. link1 = stripItemData(string.match(table_mainData[i]["cols"][1]["value"], hyperlinkPattern))
  862. link2 = stripItemData(itemLink)
  863. if link1 == link2 then
  864. id = i
  865. if debugOn then print("removeFromLootWindow(): Found match in data table. ID #"..id) end
  866. break
  867. end
  868. end
  869. if id == nil then
  870. if debugOn then print("removeFromLootWindow(): No match found in data table. Aborting.") end
  871. return
  872. end
  873. table.remove(table_mainData, id)
  874. FA_RTscrollingtable:SetData(table_mainData, false)
  875.  
  876. --clear name association entries for this item
  877. local table_size = #table_nameAssociations
  878. for i=0,table_size-1 do
  879. if stripItemData(string.match(table_nameAssociations[table_size-i][1], hyperlinkPattern)) == stripItemData(itemLink) then
  880. table.remove(table_nameAssociations, table_size-i)
  881. end
  882. end
  883.  
  884. --clear queued bids or rolls for this item
  885. local table_size = #table_bids
  886. for i=0,table_size-1 do
  887. if stripItemData(string.match(table_bids[table_size-i][1], hyperlinkPattern)) == stripItemData(itemLink) then
  888. table.remove(table_bids, table_size-i)
  889. end
  890. end
  891. generateIcons()
  892. end
  893.  
  894. local function onUpdate(self,elapsed)
  895. --check if it's time to remove any expired items
  896. local tableSize = #table_expTimes
  897. local currentTime = GetTime()
  898. for i=0,tableSize-1 do -- loop backwards through table of all expired items
  899. if currentTime >= table_expTimes[tableSize-i][2] + expTime then
  900. local id
  901. for j=1,#table_mainData do -- loop through data table
  902. if stripItemData(string.match(table_mainData[j]["cols"][1]["value"], hyperlinkPattern)) == stripItemData(table_expTimes[tableSize-i][1]) then
  903. id = j
  904. if debugOn then print("onUpdate/remove: Found match in data table. ID #"..id) end
  905. break
  906. end
  907. end
  908. if id then
  909. table.insert(history, 1, {date(), table_mainData[id]["cols"][1]["value"], table_mainData[id]["cols"][3]["value"]}) -- add entry to history table
  910. FA_RTscrollingtable2:SetData(history, true)
  911.  
  912. removeFromLootWindow(table_expTimes[tableSize-i][1]) -- remove entry from data table
  913. FA_RTscrollingtable:SetData(table_mainData, false)
  914.  
  915. table.remove(table_expTimes, tableSize-i)
  916. else
  917. table.remove(table_expTimes, tableSize-i)
  918. if debugOn then print("onUpdate/remove: Found and removed invalid table_expTimes entry. ID #"..tableSize-i) end
  919. end
  920. end
  921. end
  922.  
  923. --enable/disable buttons
  924. -- TODO: Make this so it doesn't flash in interaction with iconSelect
  925. if FA_RTscrollingtable:GetSelection() and not iconSelect then
  926. FA_RTbutton2:Enable()
  927. if UnitIsGroupAssistant("PLAYER") or UnitIsGroupLeader("PLAYER") or not UnitInRaid("PLAYER") then
  928. FA_RTbutton3:Enable()
  929. end
  930. else
  931. FA_RTbutton2:Disable()
  932. FA_RTbutton3:Disable()
  933. end
  934.  
  935. -- showAfterCombat
  936. if showAfterCombat then
  937. if not UnitAffectingCombat("PLAYER") then
  938. FA_RTframe:Show()
  939. showAfterCombat = false
  940. end
  941. end
  942.  
  943. -- /rt who stuff
  944. if table_who and table_who["time"] and table_who["time"]+1 <= currentTime then
  945. for i=1,#table_who do
  946. local s = table_who[i]..": "
  947. for j=1,#table_who[table_who[i]] do
  948. if j > 1 then
  949. s = s..", "
  950. end
  951. s = s..table_who[table_who[i]][j]
  952. end
  953. print(s)
  954. end
  955. table_who = {}
  956. end
  957.  
  958. -- table_bids stuff
  959. -- FIXME: cpu excessive
  960. -- TODO: fix
  961. FA_RTscrollingtable3:SetData(table_bids, true)
  962. if #table_bids == 0 then
  963. FA_RTbidframe:Hide()
  964. else
  965. FA_RTbidframe:Show()
  966. end
  967. local table_size = #table_bids
  968. for i=0,table_size-1 do
  969. local id = nil
  970. for j=1,#table_mainData do
  971. if stripItemData(table_bids[table_size-i][1]) == stripItemData(string.match(table_mainData[j]["cols"][1]["value"], hyperlinkPattern)) then
  972. id = j
  973. end
  974. end
  975. local name = nil
  976. for j=1,#table_nameAssociations do
  977. if stripItemData(table_nameAssociations[j][1]) == stripItemData(table_bids[table_size-i][1]) then
  978. name = table_nameAssociations[j][2]
  979. break
  980. end
  981. end
  982. local bid = table_bids[table_size-i][2]
  983. local executed = false
  984. if string.match(table_mainData[id]["cols"][2]["value"], "(Tells)") and table_bids[table_size-i][3] == "Waiting to bid..." then
  985. local at = tonumber(string.match(table_mainData[id]["cols"][2]["value"], "^%d%d"))
  986. if at == tonumber(bid) then
  987. SendChatMessage(tostring(bid), "WHISPER", nil, name)
  988. executed = 1
  989. elseif at == 30 and tonumber(bid) > 30 then
  990. SendChatMessage(tostring(bid), "WHISPER", nil, name)
  991. executed = 1
  992. end
  993. elseif string.match(table_mainData[id]["cols"][2]["value"], "(Rolls)") and table_bids[table_size-i][3] == "Waiting to roll..." then
  994. local at = tonumber(string.match(table_mainData[id]["cols"][2]["value"], "^%d%d"))
  995. if at == tonumber(bid) then
  996. faRoll(bid)
  997. executed = 2
  998. elseif at == 30 and tonumber(bid) > 30 then
  999. faRoll(bid)
  1000. executed = 2
  1001. end
  1002. end
  1003. if executed == 2 then
  1004. table.remove(table_bids, table_size-i)
  1005. FA_RTscrollingtable3:SetData(table_bids, true)
  1006. elseif executed == 1 then
  1007. table_bids[table_size-i][3] = "Waiting to roll..."
  1008. FA_RTscrollingtable3:SetData(table_bids, true)
  1009. end
  1010. end
  1011. end
  1012.  
  1013. local ouframe = CreateFrame("frame")
  1014. ouframe:SetScript("OnUpdate", onUpdate)
  1015.  
  1016. local function ReportLoot()
  1017. if debugOn then print("ReportLoot()") end
  1018. local _, isInInstance = IsInInstance()
  1019. if isInInstance == "raid" or debugOn then
  1020. for i=1,GetNumLootItems() do -- loop through all items in the window
  1021. local shouldAnnounce = true
  1022. local mobID = GetLootSourceInfo(i) -- retrieve GUID of the mob that holds the item
  1023. local link = GetLootSlotLink(i) -- retrieve link of item
  1024. if link then
  1025. if mobID then -- check if the item exists and isn't gold
  1026. for i=1,#hasBeenLooted do -- check if the mob this item is on has been looted before
  1027. if debugOn then print("Comparing "..hasBeenLooted[i].." to "..mobID) end
  1028. if hasBeenLooted[i] == mobID then
  1029. shouldAnnounce = false
  1030. break
  1031. end
  1032. end
  1033. else
  1034. shouldAnnounce = false
  1035. end
  1036. local _, _, quality = GetItemInfo(link)
  1037. if quality ~= 4 and not debugOn then -- TODO: Add customizable quality filters
  1038. shouldAnnounce = false
  1039. end
  1040. if shouldAnnounce then
  1041. cacheItem(link) -- add this item to the window
  1042. SendAddonMessage("FA_RT", compress({"report", addonVersion, mobID, link}), "RAID") -- send addon message to tell others to add this to their window
  1043. if debugOn then print("ReportLoot(): \"FA_RT\", \"report"..addonVersion..":"..mobID.."^^"..link.."\"") end
  1044. end
  1045. else
  1046. if debugOn then print("ReportLoot(): Link from slot #"..i.." is invalid.") end
  1047. end
  1048. end
  1049.  
  1050. -- now add all the GUIDs that we just looted to hasBeenLooted table
  1051. for i=1,GetNumLootItems() do --loop through list of items
  1052. local source = {GetLootSourceInfo(i)}
  1053. for j=1,#source/2 do -- loop through list of sources for each item
  1054. local shouldAnnounce = true
  1055. for k=1,#hasBeenLooted do -- check if this mob is not on the hasBeenLooted table yet
  1056. if hasBeenLooted[k] == source[(j*2)-1] then shouldAnnounce = false end
  1057. break
  1058. end
  1059. if shouldAnnounce then
  1060. table.insert(hasBeenLooted, source[(j*2)-1]) -- add this mob to hasBeenLooted
  1061. SendAddonMessage("FA_RT", compress({"mobID", addonVersion, source[(j*2)-1]}), "RAID") -- send addon message to tell others to add this mob to hasBeenLooted
  1062. if debugOn then print("ReportLoot(): \"FA_RT\", \"mobID"..addonVersion..":"..source[(j*2)-1].."\"") end
  1063. end
  1064. end
  1065. end
  1066. end
  1067. end
  1068.  
  1069. local function setAutoLoot()
  1070. if GetLootMethod() == "freeforall" or debugOn then
  1071. if isGuildGroup() then
  1072. if not UnitIsGroupAssistant("PLAYER") and not UnitIsGroupLeader("PLAYER") then
  1073. if lastLootSetting == 0 then
  1074. lastLootSetting = 1
  1075. ALsetting = GetCVar("autoLootDefault")
  1076. ALTsetting = GetModifiedClick("AUTOLOOTTOGGLE")
  1077. SetModifiedClick("AUTOLOOTTOGGLE", "NONE")
  1078. SetCVar( "autoLootDefault", 0 )
  1079. print("RT: Autoloot is now off.")
  1080. end
  1081. end
  1082. else
  1083. if lastLootSetting == 1 then
  1084. lastLootSetting = 0
  1085. SetModifiedClick("AUTOLOOTTOGGLE", ALTsetting)
  1086. SetCVar( "autoLootDefault", ALsetting )
  1087. print("RT: Autoloot has been restored to your previous settings.")
  1088. end
  1089. end
  1090. else
  1091. if lastLootSetting == 1 then
  1092. lastLootSetting = 0
  1093. SetModifiedClick("AUTOLOOTTOGGLE", ALTsetting)
  1094. SetCVar( "autoLootDefault", ALsetting )
  1095. print("RT: Autoloot has been restored to your previous settings.")
  1096. end
  1097. end
  1098. end
  1099.  
  1100. local function setGeneralVis()
  1101. if (isGuildGroup() == true) then
  1102. if (IsResting() == false) then
  1103. ChatFrame_RemoveChannel(DEFAULT_CHAT_FRAME, "General")
  1104. else
  1105. ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, "General")
  1106. end
  1107. else
  1108. ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, "General")
  1109. end
  1110. end
  1111.  
  1112. --local function parseChat(msg, author)
  1113. function parseChat(msg, author)
  1114. if debugOn then print("parseChat("..msg..", "..tostring(author)..")") end
  1115. local rank = 0
  1116. if not debugOn then
  1117. for i=1,40 do
  1118. local name, rank_ = GetRaidRosterInfo(i)
  1119. if name == author then
  1120. rank = rank_
  1121. break
  1122. end
  1123. end
  1124. end
  1125. if rank > 0 or debugOn then
  1126. local link = string.match(msg, hyperlinkPattern)
  1127. if link then
  1128. local note = string.gsub(msg, "x%d+", "")
  1129. local note = string.match(note, "]|h|r%s*(.+)")
  1130. local shouldadd = true
  1131. for i=1,#table_nameAssociations do
  1132. if table_nameAssociations[i][1] == link then shouldadd = false end
  1133. end
  1134. if shouldadd == true then
  1135. table.insert(table_nameAssociations, {link, author})
  1136. end
  1137. if debugOn then print(link) end
  1138. if debugOn then print(note) end
  1139. if note then
  1140. valueFormat(link, note)
  1141. end
  1142. end
  1143. end
  1144. end
  1145.  
  1146. local frame, events = CreateFrame("Frame"), {}
  1147. function events:ADDON_LOADED(name)
  1148. ALsetting = GetCVar("autoLootDefault")
  1149. if name == "FARaidTools" then
  1150. _, _, addonVersion = GetAddOnInfo("FARaidTools")
  1151. if optionsTable ~= nil then -- if options loaded, then load into local variables
  1152. -- individual option checks
  1153. if optionsTable[1] ~= nil then
  1154. windowPosition = optionsTable[1]
  1155. else
  1156. windowPosition = {0, 0, "CENTER"}
  1157. end
  1158. if optionsTable[2] ~= nil then
  1159. ALTsetting = optionsTable[2]
  1160. else
  1161. ALTsetting = "SHIFT"
  1162. end
  1163. else -- if not, set to default values
  1164. windowPosition = {0, 0, "CENTER"}
  1165. ALTsetting = "SHIFT"
  1166. end
  1167. history = history or {}
  1168. FA_RTscrollingtable2:SetData(history, true)
  1169. RegisterAddonMessagePrefix("FA_RT")
  1170. end
  1171. end
  1172. function events:PLAYER_LOGOUT(...)
  1173. SetModifiedClick("AUTOLOOTTOGGLE", ALTsetting)
  1174. SetCVar( "autoLootDefault", ALsetting )
  1175. optionsTable = {{lootwindowpositionX, lootwindowpositionY, relativePoint}, gReportThreshold}
  1176. end
  1177. function events:GET_ITEM_INFO_RECEIVED(...)
  1178. local list_size = #table_itemQuery
  1179. for i=0,list_size-1 do -- loop backwards through list of items waiting to be cached
  1180. if GetItemInfo(table_itemQuery[list_size-i]) then -- check if this item in the list is cached yet
  1181. addToLootWindow(table_itemQuery[list_size-i]) -- it's ready so add it to the loot window
  1182. table.remove(table_itemQuery, list_size-i) -- remove the entry from the query list
  1183. if debugOn then print("GET_ITEM_INFO_RECEIVED: Adding item #"..list_size-i.." to loot window.") end
  1184. end
  1185. end
  1186. end
  1187. function events:PLAYER_ENTERING_WORLD(...)
  1188. setAutoLoot()
  1189. end
  1190. function events:RAID_ROSTER_UPDATE(...)
  1191. setAutoLoot()
  1192. end
  1193. function events:LOOT_OPENED(...)
  1194. if isGuildGroup() or debugOn then
  1195. ReportLoot()
  1196. end
  1197. end
  1198. function events:CHAT_MSG_ADDON(prefix, msg, source, sender)
  1199. --if debugOn then print("CHAT_MSG_ADDON: "..prefix..", "..msg..", "..source..", "..sender) end
  1200. if prefix == "FA_RT" then
  1201. if debugOn then print("Recieved message.") end
  1202. local msg = decompress(msg)
  1203. if debugOn then DevTools_Dump(msg) end
  1204. if msg then
  1205. if source == "RAID" then
  1206. if msg[1] == "who" then
  1207. if msg[2] == "query" then
  1208. SendAddonMessage("FA_RT", compress({"who", "response", addonVersion}), "WHISPER", sender)
  1209. end
  1210. end
  1211. if sender ~= UnitName("PLAYER") then -- requests sent from the player are handled internally so testing can be done while not in a raid group, so let's ignore any messages sent by the player.
  1212. if msg[1] == "report" and msg[2] == addonVersion then
  1213. local shouldAdd = true
  1214. for i=1,#hasBeenLooted do -- check if mobID has already been looted
  1215. if hasBeenLooted[i] == msg[3] then
  1216. shouldAdd = false
  1217. break
  1218. end
  1219. end
  1220. if shouldAdd then
  1221. cacheItem(msg[4])
  1222. end
  1223. elseif msg[1] == "mobID" and msg[2] == addonVersion then
  1224. local shouldAdd = true
  1225. for i=1,#hasBeenLooted do -- check if this mob is not on the hasBeenLooted table yet
  1226. if hasBeenLooted[i] == msg[3] then shouldAdd = false end
  1227. break
  1228. end
  1229. if shouldAdd then
  1230. table.insert(hasBeenLooted, msg[3])
  1231. end
  1232. elseif msg[1] == "end" and msg[2] == addonVersion then
  1233. local id
  1234. for i=1,#table_mainData do
  1235. local link = stripItemData(string.match(table_mainData[i]["cols"][1]["value"], hyperlinkPattern))
  1236. local link2 = stripItemData(msg[3])
  1237. if link == link2 then
  1238. id = i
  1239. break
  1240. end
  1241. end
  1242. if id then
  1243. table_mainData[id]["cols"][2]["value"] = "Ended"
  1244. table_mainData[id]["cols"][2]["color"]["r"] = 0.5
  1245. table_mainData[id]["cols"][2]["color"]["g"] = 0.5
  1246. table_mainData[id]["cols"][2]["color"]["b"] = 0.5
  1247. table_mainData[id]["cols"][2]["color"]["a"] = 1
  1248. FA_RTscrollingtable:SetData(table_mainData, false)
  1249. table.insert(table_expTimes, {string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern), GetTime()})
  1250. else
  1251. return
  1252. end
  1253. end
  1254. end
  1255. elseif source == "WHISPER" then
  1256. if msg[1] == "who" and msg[2] == "response" then
  1257. local table_who = table_who or {}
  1258. if msg[3] then
  1259. if debugOn then print("Who response recieved from "..sender..".") end
  1260. if not table_who[msg[3]] then
  1261. table_who[msg[3]] = {}
  1262. table.insert(table_who, msg[3])
  1263. end
  1264. table.insert(table_who[msg[3]], sender)
  1265. end
  1266. table_who["time"] = GetTime()
  1267. end
  1268. end
  1269. else
  1270. if debugOn then print("Recieved malformed addon message.") end
  1271. end
  1272. end
  1273. end
  1274. function events:CHAT_MSG_RAID(msg, author)
  1275. parseChat(msg, author)
  1276. end
  1277. function events:CHAT_MSG_RAID_LEADER(msg, author)
  1278. parseChat(msg, author)
  1279. end
  1280. frame:SetScript("OnEvent", function(self, event, ...)
  1281. events[event](self, ...) -- call one of the functions above
  1282. end)
  1283. for k, v in pairs(events) do
  1284. frame:RegisterEvent(k) -- Register all events for which handlers have been defined
  1285. end
  1286.  
  1287. if debugOn then
  1288. cacheItem("\124cffa335ee\124Hitem:71472:0:0:0:0:0:0:0:0\124h[Flowform Choker]\124h\124r")
  1289. cacheItem("\124cffa335ee\124Hitem:71466:0:0:0:0:0:0:0:0\124h[Fandral's Flamescythe]\124h\124r")
  1290. cacheItem("\124cffa335ee\124Hitem:71466:0:0:0:0:0:0:0:0\124h[Fandral's Flamescythe]\124h\124r")
  1291. cacheItem("\124cffa335ee\124Hitem:71781:0:0:0:0:0:0:0:0\124h[Zoid's Firelit Greatsword]\124h\124r")
  1292. cacheItem("\124cffa335ee\124Hitem:71469:0:0:0:0:0:0:0:0\124h[Breastplate of Shifting Visions]\124h\124r")
  1293. cacheItem("\124cffa335ee\124Hitem:71475:0:0:0:0:0:0:0:0\124h[Treads of the Penitent Man]\124h\124r")
  1294. cacheItem("\124cffa335ee\124Hitem:71673:0:0:0:0:0:0:0:0\124h[Shoulders of the Fiery Vanquisher]\124h\124r")
  1295. cacheItem("\124cffa335ee\124Hitem:71673:0:0:0:0:0:0:0:0\124h[Shoulders of the Fiery Vanquisher]\124h\124r")
  1296. cacheItem("\124cffa335ee\124Hitem:71687:0:0:0:0:0:0:0:0\124h[Shoulders of the Fiery Protector]\124h\124r")
  1297. parseChat("\124cffa335ee\124Hitem:71466:0:0:0:0:0:0:0:0\124h[Fandral's Flamescythe]\124h\124r 30", UnitName("PLAYER"))
  1298. end
Advertisement
Add Comment
Please, Sign In to add comment