Advertisement
Guest User

EAiLVLTT

a guest
Oct 29th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.71 KB | None | 0 0
  1. -----------------------------------------------
  2. -- INITIALIZE SETTINGS / LOAD ACE LIBRARIES --
  3. -----------------------------------------------
  4.  
  5. local addonName = ...
  6. local VERSION = GetAddOnMetadata(addonName, "Version")
  7. local PREFIX = "EAILT"
  8.  
  9. local addon = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0", "AceComm-3.0", "AceSerializer-3.0", "AceConsole-3.0")
  10. local LibQTip = LibStub("LibQTip-1.0")
  11. local AceGUI = LibStub("AceGUI-3.0")
  12.  
  13. UnitItemLevelDB = {} -- Global table of data so other addons can use our information.
  14. lastInspectRequest = 0 -- Global variable so other addons can use our inspect times to throttle themselves.
  15.  
  16. local defaults = {
  17. profile = {
  18. decimal_places = 1, -- (0-9) number of decimal places (IE 400.543 or 400.5) to show on item levels.
  19. show_spec = true, -- (true/false) toggle showing talent spec on mouseover.
  20. show_items = false, -- (true/false) toggle showing list of slots with ilvl on tooltip.
  21. inspectDelay = 1, -- Time (in seconds) to delay between calls to NotifyInspect(unit) [The function which sends requests for player information to the server]
  22. },
  23. }
  24.  
  25. function addon:OnInitialize()
  26. addon.settings = LibStub("AceDB-3.0"):New(addonName.."DB", defaults, true)
  27.  
  28. addon.invSlots = {
  29. [1] = "Helm",
  30. [2] = "Neck",
  31. [3] = "Shoulders",
  32. [5] = "Chest",
  33. [6] = "Belt",
  34. [7] = "Legs",
  35. [8] = "Boots",
  36. [9] = "Bracers",
  37. [10] = "Gloves",
  38. [11] = "Ring 1",
  39. [12] = "Ring 2",
  40. [13] = "Trinket 1",
  41. [14] = "Trinket 2",
  42. [15] = "Cloak",
  43. [16] = "Artifact",
  44. [16] = "Off Hand",
  45. }
  46.  
  47. addon.itemUpgrade = {
  48. ["0"]=0,
  49. ["1"]=8,
  50. ["373"]=4,
  51. ["374"]=8,
  52. ["375"]=4,
  53. ["376"]=4,
  54. ["377"]=4,
  55. ["379"]=4,
  56. ["380"]=4,
  57. ["445"]=0,
  58. ["446"]=4,
  59. ["447"]=8,
  60. ["451"]=0,
  61. ["452"]=8,
  62. ["453"]=0,
  63. ["454"]=4,
  64. ["455"]=8,
  65. ["456"]=0,
  66. ["457"]=8,
  67. ["458"]=0,
  68. ["459"]=4,
  69. ["460"]=8,
  70. ["461"]=12,
  71. ["462"]=16,
  72. ["466"]=4,
  73. ["467"]=8,
  74. }
  75.  
  76. addon:RegisterComm(PREFIX)
  77. end
  78.  
  79. -----------------------------------------------
  80. -- SLASH COMMAND FUNCTION(S) --
  81. -----------------------------------------------
  82.  
  83. function addon:SlashCommand(cmd, self)
  84. addon:ShowGUI()
  85.  
  86. --[[
  87. local i, arg, args = 1, nil, {}
  88.  
  89. while addon:GetArgs(cmd, 1, i) do
  90. arg, i = addon:GetArgs(cmd, 1, i)
  91. table.insert(args, arg)
  92. end
  93.  
  94. if #args >= 1 then
  95. if args[1] == "show" then
  96. if #args < 2 then
  97. print("/eailt show [spec/items]")
  98. else
  99. if args[2] == "spec" then
  100. if addon.settings.profile.show_spec == true then
  101. addon.settings.profile.show_spec = false
  102. else
  103. addon.settings.profile.show_spec = true
  104. end
  105. print("EAILT show specialization: "..addon.settings.profile.show_spec)
  106. elseif args[2] == "items" then
  107. if addon.settings.profile.show_items == true then
  108. addon.settings.profile.show_items = false
  109. else
  110. addon.settings.profile.show_items = true
  111. end
  112. print("EAILT show item list: "..addon.settings.profile.show_items)
  113. else
  114. print("/eailt show [spec/items]")
  115. end
  116. end
  117. elseif args[1] == "decimal" then
  118. if #args < 2 then
  119. print("/eailt decimal [0-9]")
  120. else
  121. if args[2]:tonumber() > 9 or args[2]:tonumber() < 0 then
  122. print("/eailt decimal [0-9]")
  123. print(" current: "..addon.settings.profile.decimal_places)
  124. print(" default: "..defaults.profile.decimal_places)
  125. else
  126. addon.settings.profile.decimal_places = args[2]:tonumber()
  127. end
  128. end
  129. elseif args[1] == "delay" then
  130. if #args < 2 then
  131. print("/eailt delay [0-9]")
  132. print(" current: "..addon.settings.profile.inspectDelay)
  133. print(" default: "..defaults.profile.inspectDelay)
  134. else
  135. if args[2]:tonumber() > 9 or args[2]:tonumber() < 0 then
  136. print("/eailt delay [0-9]")
  137. else
  138. addon.settings.profile.inspectDelay = args[2]:tonumber()
  139. print("EAILT inspect delay: "..addon.settings.profile.inspectDelay)
  140. end
  141. end
  142. elseif args[1] == "reset" then
  143. -- reset to default settings
  144. elseif args[1] == "config" then
  145. addon:ShowGUI()
  146. else
  147. -- print options list
  148. print("/eailt - Display this help.")
  149. print(" config - open the GUI interface.")
  150. print(" show spec - toggle showing specialization in tooltip.")
  151. print(" show items - toggle showing items list in tooltip.")
  152. print(" decimal # - set number of decimal places to show in item levels.")
  153. print(" delay # - set number of seconds between inspect requests.")
  154. print(" reset - reset all settings back to default.")
  155. end
  156. else
  157. -- print options list
  158. print("/eailt - Display this help.")
  159. print(" config - open the GUI interface.")
  160. print(" show spec - toggle showing specialization in tooltip.")
  161. print(" show items - toggle showing items list in tooltip.")
  162. print(" decimal # - set number of decimal places to show in item levels.")
  163. print(" delay # - set number of seconds between inspect requests.")
  164. print(" reset - reset all settings back to default.")
  165. end
  166.  
  167. addon:UpdateLDBText()
  168. ]]
  169. end
  170.  
  171. -----------------------------------------------
  172. -- AceGUI-3.0 --
  173. -----------------------------------------------
  174.  
  175. function addon:ShowGUI()
  176. local frame = AceGUI:Create("Frame")
  177. frame:SetTitle("Equipped Average Item Level Tooltip")
  178. frame:SetStatusText("Version "..VERSION.." by Isoloedlk of US-Khaz Modan")
  179. frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
  180. frame:SetWidth(500)
  181. frame:SetHeight(150)
  182. frame:SetLayout("Flow")
  183.  
  184. local check = AceGUI:Create("CheckBox")
  185. check:SetLabel("Show Specialization")
  186. check:SetValue(addon.settings.profile.show_spec)
  187. check:SetCallback("OnValueChanged", function(self, method, value) addon.settings.profile.show_spec = value end)
  188. --check:SetCallback("OnValueChanged", function(...) print(...) end)
  189. frame:AddChild(check)
  190.  
  191. local check = AceGUI:Create("CheckBox")
  192. check:SetLabel("Show Item List")
  193. check:SetValue(addon.settings.profile.show_items)
  194. check:SetCallback("OnValueChanged", function(self, method, value) addon.settings.profile.show_items = value end)
  195. --check:SetCallback("OnValueChanged", function(...) print(...) end)
  196. frame:AddChild(check)
  197.  
  198. local slider = AceGUI:Create("Slider")
  199. slider:SetLabel("Decimal Places")
  200. slider:SetSliderValues(0, 9, 1)
  201. slider:SetValue(addon.settings.profile.decimal_places)
  202. slider:SetCallback("OnValueChanged", function(self, method, value) addon.settings.profile.decimal_places = value end)
  203. --slider:SetCallback("OnValueChanged", function(...) print(...) end)
  204. frame:AddChild(slider)
  205.  
  206. local slider = AceGUI:Create("Slider")
  207. slider:SetLabel("Inspect Request Delay")
  208. slider:SetSliderValues(0, 9, 1)
  209. slider:SetValue(addon.settings.profile.inspectDelay)
  210. slider:SetCallback("OnValueChanged", function(self, method, value) addon.settings.profile.inspectDelay = value end)
  211. --slider:SetCallback("OnValueChanged", function(...) print(...) end)
  212. frame:AddChild(slider)
  213. end
  214. -----------------------------------------------
  215. -- GENERAL FUNCTIONS --
  216. -----------------------------------------------
  217.  
  218. function addon:print(msg)
  219. DEFAULT_CHAT_FRAME:AddMessage("|cffaaffcc[EAILT]:|r "..msg)
  220. end
  221.  
  222. function addon:IsPvP()
  223. local retVal = false
  224. local instanceType = select(2, IsInInstance())
  225.  
  226. if instanceType == "arena" or instanceType == "pvp" then
  227. retVal = true
  228. end
  229.  
  230. return retVal, instanceType
  231. end
  232.  
  233. function addon:showSpecFilter()
  234. local filter = {
  235. bTooltip = false,
  236. TipTacTalents = false,
  237. }
  238.  
  239. for k, v in pairs(filter) do
  240. if k == "TipTacTalents" and TipTac_Config then
  241. if TipTac_Config.showTalents == true and addon.settings.profile.show_spec == true then
  242. filter[k] = true
  243. elseif TipTac_Config.showTalents == false and addon.settings.profile.show_spec == true then
  244. filter[k] = false
  245. end
  246. else
  247. filter[k] = IsAddOnLoaded(k)
  248. end
  249. end
  250.  
  251. for k, v in pairs(filter) do
  252. if v == true then return true end
  253. end
  254. end
  255.  
  256. -----------------------------------------------
  257. -- MATH FUNCTIONS --
  258. -----------------------------------------------
  259.  
  260. function addon:Round(num)
  261. return tonumber(string.format("%."..addon.settings.profile.decimal_places.."f", num))
  262. end
  263.  
  264. -----------------------------------------------
  265. -- TABLE FUNCTIONS --
  266. -----------------------------------------------
  267.  
  268. function addon:insert(val, key)
  269. local index = addon:search('guid', val.guid)
  270.  
  271. if index then
  272. UnitItemLevelDB[index] = val
  273. else
  274. if key then
  275. table.insert(UnitItemLevelDB, key, val)
  276. else
  277. table.insert(UnitItemLevelDB, val)
  278. end
  279. end
  280.  
  281. addon:prune()
  282. end
  283.  
  284. function addon:remove(key, val)
  285. if val then
  286. table.remove(UnitItemLevelDB, addon:search(key, val))
  287. else
  288. table.remove(UnitItemLevelDB, key)
  289. end
  290. end
  291.  
  292. function addon:search(key, val)
  293. local retVal, retTbl
  294.  
  295. for k, v in pairs(UnitItemLevelDB) do
  296. if v[key] == val then
  297. retVal = k
  298. retTbl = v
  299. break
  300. end
  301. end
  302.  
  303. return retVal, retTbl
  304. end
  305.  
  306. function addon:prune()
  307. local i = 1
  308.  
  309. while #(UnitItemLevelDB) > 50 do
  310. if UnitItemLevelDB[i] then
  311. local found
  312.  
  313. for b=1,GetNumGroupMembers(),1 do
  314. local guid = UnitGUID("raid"..b) or UnitGUID("party"..b)
  315.  
  316. if guid and guid == UnitItemLevelDB[i].guid then
  317. found = true
  318. break
  319. end
  320. end
  321.  
  322. if not found then addon:remove(i) end
  323. end
  324.  
  325. i = i + 1
  326. end
  327. end
  328.  
  329. -----------------------------------------------
  330. -- LibDataBroker --
  331. -----------------------------------------------
  332.  
  333. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  334.  
  335. local function ldbOnEnter(self)
  336. local tooltip = LibQTip:Acquire(addonName.."Tooltip", 3, "LEFT", "CENTER", "RIGHT")
  337. self.tooltip = tooltip
  338.  
  339. local dataset = {}
  340. local gType, gMembers
  341.  
  342. for i=1,GetNumGroupMembers(),1 do
  343. if UnitExists("raid"..i) then
  344. gType = "raid"
  345. gMembers = GetNumGroupMembers()
  346. break
  347. elseif UnitExists("party"..i) then
  348. gType = "party"
  349. gMembers = GetNumGroupMembers()
  350. break
  351. end
  352. end
  353.  
  354. if not gType then return end
  355.  
  356. for i=1,gMembers,1 do
  357. local unitGUID = UnitGUID(gType..i)
  358.  
  359. if unitGUID and type(unitGUID) == "string" and unitGUID ~= UnitGUID("player") then
  360. local index, data = addon:search('guid', unitGUID)
  361.  
  362. if index then
  363. table.insert(dataset, {data.name or "Unknown", data.spec or "???", addon:Round(tonumber(data.equipped)) or 0})
  364. else
  365. local name = select(6, GetPlayerInfoByGUID(unitGUID)) or "Unknown"
  366.  
  367. table.insert(dataset, {name, "???", 0})
  368. end
  369. end
  370. end
  371.  
  372. table.insert(dataset, {UnitName("player"), addon:GetSpec(false), ("%.1f"):format(select(2, GetAverageItemLevel()))})
  373.  
  374. local sortTbl = {}
  375.  
  376. for k,v in pairs(dataset) do
  377. table.insert(sortTbl, k)
  378. end
  379.  
  380. table.sort(sortTbl, function(a, b)
  381. return tonumber(dataset[a][3]) > tonumber(dataset[b][3])
  382. end)
  383.  
  384. tooltip:AddHeader('Name', 'Specialization', 'Equipped iLvl')
  385.  
  386. for k,v in pairs(sortTbl) do
  387. local i, c = tooltip:AddLine(dataset[v][1], dataset[v][2], dataset[v][3])
  388.  
  389. if dataset[v][1] == UnitName("player") then
  390. tooltip:SetLineColor(i, 0, 1, 0, 1)
  391. elseif dataset[v][3] == 0 then
  392. tooltip:SetLineColor(i, 1, 0.5, 0, 1)
  393. else
  394. tooltip:SetLineColor(i, 1, 1, 0, 1)
  395. end
  396. end
  397.  
  398. tooltip:SmartAnchorTo(self)
  399. tooltip:Show()
  400. end
  401.  
  402. local function ldbOnLeave(self)
  403. LibQTip:Release(self.tooltip)
  404. self.tooltip = nil
  405. end
  406.  
  407.  
  408. function ldbOnClick(self, button)
  409. if button == "LeftButton" then
  410. if GetNumGroupMembers() < 1 then
  411. addon:print("You are not in a group.")
  412. return
  413. end
  414.  
  415. if addon:IsPvP() then
  416. addon:print("You are in PvP.")
  417. return
  418. end
  419.  
  420. local dataset = {}
  421. local gMembers, gType
  422.  
  423. for i=1,GetNumGroupMembers(),1 do
  424. if UnitExists("raid"..i) then
  425. gType = "raid"
  426. gMembers = GetNumGroupMembers()
  427. break
  428. elseif UnitExists("party"..i) then
  429. gType = "party"
  430. gMembers = GetNumGroupMembers()
  431. break
  432. end
  433. end
  434.  
  435. for i=1,gMembers,1 do
  436. local unitGUID = UnitGUID(gType..i)
  437.  
  438. if unitGUID and type(unitGUID) == "string" and unitGUID ~= UnitGUID("player") then
  439. local index, data = addon:search('guid', unitGUID)
  440.  
  441. if index then
  442. table.insert(dataset, {data.name or "Unknown", ("%.1f"):format(tonumber(data.equipped)), data.spec or "None"})
  443. else
  444. local name = select(6, GetPlayerInfoByGUID(unitGUID)) or "Unknown"
  445.  
  446. table.insert(dataset, {name, 0, "None"})
  447. end
  448. end
  449. end
  450.  
  451. table.insert(dataset, {UnitName("player"), addon:Round(select(2, GetAverageItemLevel())), select(2, GetSpecializationInfo(GetSpecialization()))})
  452.  
  453. local sortTbl = {}
  454.  
  455. for k,v in pairs(dataset) do
  456. table.insert(sortTbl, k)
  457. end
  458.  
  459. table.sort(sortTbl, function(a, b)
  460. return tonumber(dataset[a][2]) > tonumber(dataset[b][2])
  461. end)
  462.  
  463. SendChatMessage("Group Item Levels:", gType)
  464.  
  465. for k,v in pairs(sortTbl) do
  466. SendChatMessage(dataset[v][1].." ["..dataset[v][3].."] "..dataset[v][2], gType)
  467. end
  468. end
  469. end
  470.  
  471. local dataobj = ldb:NewDataObject(addonName, {
  472. type = "data source",
  473. text = "ilvl(s): Loading...",
  474. OnEnter = ldbOnEnter,
  475. OnLeave = ldbOnLeave,
  476. OnTooltipShow = ldbOnTooltipShow,
  477. OnClick = ldbOnClick,
  478. })
  479.  
  480. function addon:UpdateLDBText()
  481. local avg, equipped = GetAverageItemLevel()
  482.  
  483. dataobj.text = "ilvl(s): "..addon:Round(equipped).." / "..addon:Round(avg)
  484. end
  485.  
  486. -----------------------------------------------
  487. -- ENABLE/DISABLE ADDON FUNCTIONS --
  488. -----------------------------------------------
  489.  
  490. function addon:OnEnable()
  491. self:RegisterEvent("INSPECT_READY")
  492.  
  493. --self:RegisterEvent("ADDON_LOADED")
  494.  
  495. self:RegisterEvent("UNIT_INVENTORY_CHANGED")
  496. self:RegisterEvent("PLAYER_AVG_ITEM_LEVEL_READY")
  497. self:RegisterEvent("RAID_ROSTER_UPDATE")
  498. self:RegisterEvent("PARTY_MEMBERS_CHANGED")
  499. self:RegisterEvent("PLAYER_ENTERING_WORLD")
  500.  
  501. self:Hook("NotifyInspect", true)
  502.  
  503. self:SecureHookScript(GameTooltip, "OnTooltipSetUnit", addon['OnTooltipSetUnit'])
  504. --self:SecureHookScript(GameTooltip, "OnShow", addon['TooltipOnShow'])
  505. --self:SecureHookScript(GameTooltip, "OnHide", addon['TooltipOnHide'])
  506.  
  507. --self:SecureHook(GameTooltip, "AddDoubleLine", addon['AddDoubleLine'])
  508.  
  509. self:RegisterChatCommand("eailt", "SlashCommand", true)
  510.  
  511. addon:UpdateLDBText()
  512.  
  513. --addon:print(addonName.." version "..VERSION.." enabled.")
  514. end
  515.  
  516. function addon:OnDisable()
  517. self:UnregisterEvent("INSPECT_READY")
  518.  
  519. --self:UnregisterEvent("ADDON_LOADED")
  520.  
  521. self:UnregisterEvent("UNIT_INVENTORY_CHANGED")
  522. self:UnregisterEvent("PLAYER_AVG_ITEM_LEVEL_READY")
  523. self:UnregisterEvent("RAID_ROSTER_UPDATE")
  524. self:UnregisterEvent("PARTY_MEMBERS_CHANGED")
  525. self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  526.  
  527. self:UnHook("NotifyInspect")
  528.  
  529. self:UnHook(GameTooltip, "OnTooltipSetUnit")
  530. --self:UnHook(GameTooltip, "OnShow")
  531. --self:UnHook(GameTooltip, "OnHide")
  532.  
  533. self:UnregisterChatCommand("eailt")
  534.  
  535. self:CancelAllTimers()
  536.  
  537. --addon:print(addonName.." version "..VERSION.." disabled.")
  538. end
  539.  
  540. -----------------------------------------------
  541. -- EVENTS/HOOKS --
  542. -----------------------------------------------
  543.  
  544. function addon:NotifyInspect(unitID)
  545. --[[
  546. --if not InspectFrame then
  547. -- LoadAddOn("Blizzard_InspectUI")
  548. --end
  549.  
  550. if ( InspectFrame and InspectFrame:IsVisible() ) or ( Examiner and Examiner:IsVisible() ) then
  551. InspectFrame.unit = "target"
  552. --else
  553. --InspectFrame.unit = "player"
  554. elseif InspectFrame then
  555. InspectFrame.unit = unitID
  556. end
  557. ]]
  558. addon.guid = UnitGUID(unitID)
  559. lastInspectRequest = GetTime()
  560. end
  561.  
  562. function addon:INSPECT_READY(_, unitGUID)
  563. local ilvl, items = addon:GetUnitItemLevelGUID(unitGUID)
  564. local index, tbl = addon:search('guid', unitGUID)
  565. local count = 0
  566. local spec = "..."
  567.  
  568. if unitGUID == addon.guid then spec = addon:GetSpec(true) end
  569.  
  570. if index then
  571. count = tbl.scanCount
  572. if (count or 1) < 2 then addon:Inspect(addon:GetUnitByGUID(unitGUID)) end
  573. end
  574.  
  575. if #(items or {}) <= 7 then
  576. addon:Inspect(addon:GetUnitByGUID(unitGUID))
  577. end
  578.  
  579. if ilvl then
  580. addon:insert({
  581. ['guid'] = unitGUID,
  582. ['name'] = select(6, GetPlayerInfoByGUID(unitGUID)),
  583. ['equipped'] = ilvl,
  584. ['items'] = items,
  585. ['spec'] = spec,
  586. ['scanCount'] = count,
  587. })
  588.  
  589. addon:UpdateTooltip()
  590. end
  591. end
  592.  
  593. --[[function addon:ADDON_LOADED(_, name)
  594. if name == "TipTacTalents" or IsAddOnLoaded("TipTacTalents") then
  595. if TipTac_Config then
  596. if TipTac_Config.showTalents == true then
  597. addon.settings.profile.show_spec = false
  598. end
  599. else
  600. addon.settings.profile.show_spec = false
  601. end
  602.  
  603. --addon:UnregisterEvent("ADDON_LOADED")
  604. elseif name == "bTooltip" or IsAddOnLoaded("bTooltip") then
  605. addon.settings.profile.show_spec = false
  606. end
  607. end]]
  608.  
  609. function addon:PLAYER_AVG_ITEM_LEVEL_READY(...)
  610. addon:UpdateLDBText()
  611. end
  612.  
  613. function addon:UNIT_INVENTORY_CHANGED(_, unitID)
  614. local gType
  615.  
  616. if UnitGUID(unitID) ~= UnitGUID("player") then
  617. addon:remove('guid', UnitGUID(unitID))
  618.  
  619. addon:Inspect(unitID)
  620. else
  621. for i=1,GetNumGroupMembers(),1 do
  622. if UnitExists("raid"..i) then
  623. gType = "raid"
  624. break
  625. elseif UnitExists("party"..i) then
  626. gType = "party"
  627. break
  628. end
  629. end
  630.  
  631. if gType and addon:IsPvP() == false then
  632. addon:SendItemInfo(gType:upper())
  633. end
  634.  
  635. addon:UpdateLDBText()
  636. end
  637. end
  638.  
  639. -----------------------------------------------
  640. -- ADDON COMMS --
  641. -----------------------------------------------
  642.  
  643. function addon:GroupType()
  644. if select(2, IsInInstance()) == "pvp" or select(2, IsInInstance()) == "arena" then
  645. return false, "none"
  646. end
  647.  
  648. for i=1,GetNumGroupMembers(),1 do
  649. if UnitExists("raid"..i) then
  650. return true, "raid"
  651. end
  652. end
  653.  
  654. for i=1,GetNumGroupMembers(),1 do
  655. if UnitExists("party"..i) then
  656. return true, "party"
  657. end
  658. end
  659. end
  660.  
  661. function addon:PLAYER_ENTERING_WORLD()
  662. local isGroup, groupType = addon:GroupType()
  663.  
  664. if isGroup then
  665. addon:SendCommMessage(PREFIX, addon:Serialize({type = "REQUEST_INFO"}), groupType:upper(), nil, "NORMAL")
  666. end
  667. end
  668.  
  669. function addon:RAID_ROSTER_UPDATE()
  670. local isGroup, groupType = addon:GroupType()
  671.  
  672. if isGroup and groupType == "raid" then
  673. addon:SendVersion("RAID")
  674. addon:SendItemInfo("RAID")
  675. end
  676. end
  677.  
  678. function addon:PARTY_MEMBERS_CHANGED()
  679. local isGroup, groupType = addon:GroupType()
  680.  
  681. if isGroup and groupType == "party" then
  682. addon:SendVersion("PARTY")
  683. addon:SendItemInfo("PARTY")
  684. end
  685. end
  686.  
  687. function addon:SendVersion(gType)
  688. addon:SendCommMessage(PREFIX, addon:Serialize({type = "VERSION", msg = VERSION}), gType, nil, "NORMAL")
  689. end
  690.  
  691. function addon:SendItemInfo(gType)
  692. local ilvl, items = addon:GetUnitItemLevel("player")
  693.  
  694. addon:SendCommMessage(PREFIX, addon:Serialize({type = "ITEM_INFO", msg = {
  695. ['guid'] = UnitGUID("player"),
  696. ['name'] = UnitName("player"),
  697. ['equipped'] = ilvl,
  698. ['items'] = items,
  699. }}), gType, nil, "NORMAL")
  700. end
  701.  
  702. function addon:OnCommReceived(pre, msg, chan, sender)
  703. if pre == PREFIX and sender ~= UnitName("player") then
  704. local _, data = addon:Deserialize(msg)
  705.  
  706. if data.type == "VERSION" and data.msg > VERSION and ( addon.versionWarning or 0 ) == 0 then
  707. addon:print("A newer version is available. Visit http://www.wowinterface.com to download the latest version.")
  708. addon.versionWarning = 1
  709. elseif data.type == "ITEM_INFO" then
  710. --addon:print("Received item info from "..sender)
  711. addon:insert(data.msg)
  712. elseif data.type == "REQUEST_INFO" then
  713. addon:SendItemInfo(chan)
  714. end
  715. end
  716. end
  717.  
  718. -----------------------------------------------
  719. -- TOOLTIP FUNCTIONS --
  720. -----------------------------------------------
  721.  
  722. function addon:searchTT(val)
  723. local retVal
  724.  
  725. for i=2, GameTooltip:NumLines()+1 do
  726. local txt = _G["GameTooltipTextLeft"..i]:GetText() or ""
  727.  
  728. if txt:find(val) then
  729. retVal = i
  730. break
  731. end
  732. end
  733.  
  734. return retVal
  735. end
  736.  
  737. function addon:OnTooltipSetUnit()
  738. local _, unit = self:GetUnit()
  739.  
  740. addon:Inspect(unit)
  741.  
  742. if unit and UnitGUID(unit) == UnitGUID("player") then
  743. local ilvl, items = addon:GetUnitItemLevel("player")
  744.  
  745. addon:insert({
  746. ['guid'] = UnitGUID("player"),
  747. ['name'] = UnitName("player"),
  748. ['equipped'] = ilvl,
  749. ['items'] = items,
  750. ['spec'] = addon:GetSpec(false),
  751. ['scanCount'] = 2,
  752. })
  753.  
  754. if addon.settings.profile.show_spec and not addon:showSpecFilter() and UnitLevel("player") >= 10 then
  755. self:AddLine("Spec: |cffffffff"..select(2, GetSpecializationInfo(GetSpecialization())))
  756. if not self.fadeOut then self:Show() end
  757. end
  758.  
  759. self:AddLine("iLvl: |cffff8000"..addon:Round(ilvl))
  760. if not self.fadeOut then self:Show() end
  761.  
  762. if addon.settings.profile.show_items then
  763. for i=1,16,1 do
  764. if i ~= 4 and items[i] then
  765. self:AddDoubleLine(addon.invSlots[i], "|c"..items[i].color..items[i].name.." |cffffffff("..(items[i].itemLevel or "???")..")")
  766. if not self.fadeOut then self:Show() end
  767. elseif i ~= 4 then
  768. self:AddDoubleLine(addon.invSlots[i], "|cffaaaaaaNone/Not Scanned |cffffffff(???)")
  769. if not self.fadeOut then self:Show() end
  770. end
  771. end
  772. end
  773. elseif unit and UnitIsPlayer(unit) then
  774. if addon.settings.profile.show_spec and not addon:showSpecFilter() and UnitLevel(unit) >= 10 then
  775. self:AddLine("Spec: |cffffffff...")
  776. self:Show()
  777. end
  778.  
  779. self:AddLine("iLvl: |cffff8000...", 1, 1, 1)
  780. if not self.fadeOut then self:Show() end
  781.  
  782. if addon.settings.profile.show_items then
  783. for i=1,16,1 do
  784. if i ~= 4 then
  785. self:AddDoubleLine(addon.invSlots[i], "|cffaaaaaaNone/Not Scanned |cffffffff(???)")
  786. if not self.fadeOut then self:Show() end
  787. end
  788. --GameTooltip:Show()
  789. end
  790. end
  791. end
  792.  
  793. addon:UpdateTooltip()
  794. end
  795.  
  796. function addon:TooltipOnShow()
  797. --if GameTooltip:GetUnit() then print("It's a unit!") end
  798. addon.tooltiptimer = addon:ScheduleRepeatingTimer("UpdateTooltip", 0.2)
  799. end
  800.  
  801. function addon:TooltipOnHide()
  802. --GameTooltip:SetMinResize(0, 0)
  803. addon:CancelTimer(addon.tooltiptimer)
  804. end
  805.  
  806. function addon:UpdateTooltip()
  807. if GameTooltip:GetUnit() then
  808. local name, unit = GameTooltip:GetUnit()
  809.  
  810. if not unit or not UnitIsPlayer(unit) then return end
  811.  
  812. local index, data = addon:search('guid', UnitGUID(unit))
  813.  
  814. if index then
  815. local found
  816.  
  817. if addon.settings.profile.show_spec and data.spec and not addon:showSpecFilter() then
  818. found = addon:searchTT("Spec:")
  819.  
  820. if found then
  821. _G["GameTooltipTextLeft"..found]:SetFormattedText("Spec: |cffffffff%s", data.spec)
  822. else
  823. GameTooltip:AddLine("Spec: |cffffffff"..data.spec)
  824. GameTooltip:Show()
  825. end
  826. end
  827.  
  828. found = addon:searchTT("iLvl:")
  829.  
  830. if found then
  831. _G["GameTooltipTextLeft"..found]:SetFormattedText("iLvl: |cffff8000%s", data.equipped)
  832. else
  833. GameTooltip:AddLine("iLvl: |cffff8800"..data.equipped)
  834. if not GameTooltip.fadeOut then GameTooltip:Show() end
  835. end
  836.  
  837. if addon.settings.profile.show_items then
  838.  
  839. for i=1, 16,1 do
  840. if i ~= 4 then
  841. found = addon:searchTT(addon.invSlots[i])
  842.  
  843. if found then
  844. if data.items[i] then
  845. _G["GameTooltipTextRight"..found]:SetFormattedText("|c%s%s |cffffffff(%s)", data.items[i].color, data.items[i].name, data.items[i].itemLevel)
  846. else
  847. _G["GameTooltipTextRight"..found]:SetFormattedText("|c%s%s |cffffffff(%s)", "ffaaaaaa", "None/Not Scanned", "???")
  848. end
  849. if not GameTooltip.fadeOut then GameTooltip:Show() end
  850. else
  851. if data.items[i] then
  852. GameTooltip:AddDoubleLine(addon.invSlots[i], "|c"..data.items[i].color..data.items[i].name.." |cffffffff("..(data.items[i].itemLevel or "???")..")")
  853. else
  854. GameTooltip:AddDoubleLine(addon.invSlots[i], "|cffaaaaaaNone/Not Scanned |cffffffff(???)")
  855. end
  856. if not GameTooltip.fadeOut then GameTooltip:Show() end
  857. end
  858. end
  859. end
  860. end
  861. end
  862. end
  863. end
  864.  
  865. --[[function addon:AddDoubleLine(...)
  866. if not GameTooltip.fadeOut then
  867. GameTooltip:Show()
  868. end
  869. end]]
  870.  
  871. --[[function addon:RefreshGameTooltip()
  872. local lwidth, rwidth, width, index
  873.  
  874. index = addon:searchTT(addon.invSlots[1])
  875.  
  876. for i=index,GameTooltip:NumLines(),1 do
  877. local l, r = _G["GameTooltipTextLeft"..i], _G["GameTooltipTextRight"..i]
  878.  
  879. if l:GetWidth() >= ( lwidth or 0 ) then
  880. lwidth = l:GetWidth()
  881. end
  882.  
  883. if r:GetWidth() >= ( rwidth or 0 ) then
  884. rwidth = r:GetWidth()
  885. end
  886.  
  887. width = lwidth + rwidth + 50
  888. end
  889.  
  890. for i=index,GameTooltip:NumLines(),1 do
  891. local l, r = _G["GameTooltipTextLeft"..i], _G["GameTooltipTextRight"..i]
  892.  
  893. r:SetPoint("RIGHT", l, "LEFT", width - 22, 0)
  894. end
  895.  
  896. GameTooltip:SetWidth(width)
  897. GameTooltip:Show()
  898. end]]
  899.  
  900. -----------------------------------------------
  901. -- INSPECT FUNCTION(S) --
  902. -----------------------------------------------
  903.  
  904. function addon:Inspect(unit)
  905. addon:CancelTimer(addon.inspectTimer, true)
  906.  
  907. if unit and UnitExists(unit) and not UnitIsUnit(unit, "player") then
  908. if CanInspect(unit, false) and CheckInteractDistance(unit, 1) and ( GetTime() - lastInspectRequest ) >= addon.settings.profile.inspectDelay and not ( ( InspectFrame and InspectFrame:IsVisible() ) or ( Examiner and Examiner:IsVisible() ) ) then
  909. NotifyInspect(unit)
  910. else
  911. addon.inspectTimer = addon:ScheduleTimer("Inspect", addon.settings.profile.inspectDelay, unit)
  912. end
  913. end
  914. end
  915.  
  916. -----------------------------------------------
  917. -- ITEMLEVEL FUNCTIONS --
  918. -----------------------------------------------
  919.  
  920. function addon:GetUnitByGUID(unitGUID)
  921. local unitID
  922.  
  923. for i = 1, 4, 1 do
  924. if UnitGUID("party"..i) == unitGUID then unitID = "party"..i end
  925. end
  926.  
  927. for i = 1, 40, 1 do
  928. if UnitGUID("raid"..i) == unitGUID then unitID = "raid"..i end
  929. end
  930.  
  931. if UnitGUID("player") == unitGUID then
  932. unitID = "player"
  933. elseif UnitGUID("mouseover") == unitGUID then
  934. unitID = "mouseover"
  935. elseif UnitGUID("target") == unitGUID then
  936. unitID = "target"
  937. elseif UnitGUID("focus") == unitGUID then
  938. unitID = "focus"
  939. end
  940.  
  941. return unitID
  942. end
  943.  
  944. function addon:GetUnitItemLevel(unit)
  945. local items = {}
  946. local sum, count
  947.  
  948. if unit and UnitIsPlayer(unit) and CheckInteractDistance(unit, 1) then
  949. for i=1, 16, 1 do
  950. local link = GetInventoryItemLink(unit, i)
  951. local name, _, quality, itemLevel = GetItemInfo(link or 0)
  952. local color = select(4, GetItemQualityColor(quality or 1))
  953.  
  954. if itemLevel and itemLevel > 0 and i ~= 4 then
  955. local upgrade = string.match(link, ":(%d+)\124h%[")
  956. if upgrade then
  957. itemLevel = itemLevel + (addon.itemUpgrade[upgrade] or 0)
  958. end
  959.  
  960. table.insert(items, i, {
  961. ['name'] = name,
  962. ['itemLevel'] = itemLevel,
  963. ['color'] = color,
  964. ['slotName'] = addon.invSlots[i],
  965. })
  966. sum = (sum or 0) + itemLevel
  967. count = (count or 0) + 1
  968. end
  969. end
  970.  
  971. if (sum or 0) >= (count or 0) and (count or 0) > 0 then
  972. return addon:Round(sum/count), items
  973. else
  974. return nil, nil
  975. end
  976. end
  977. end
  978.  
  979. function addon:GetUnitItemLevelGUID(unitGUID)
  980. return addon:GetUnitItemLevel(addon:GetUnitByGUID(unitGUID))
  981. end
  982.  
  983. function addon:GetGUIDByName(name)
  984. local index, data = addon:search('name', name)
  985.  
  986. return data.guid or nil
  987. end
  988.  
  989. -----------------------------------------------
  990. -- TALENT FUNCTIONS --
  991. -----------------------------------------------
  992.  
  993. function addon:GetSpec(useGlobal)
  994. local name
  995.  
  996. if useGlobal then
  997. local unit = addon:GetUnitByGUID(addon.guid)
  998.  
  999. if unit and UnitLevel(unit) >= 10 then
  1000. name = select(2, GetSpecializationInfoByID(GetInspectSpecialization(unit)))
  1001. end
  1002. else
  1003. if UnitLevel("player") >= 10 then
  1004. name = select(2, GetSpecializationInfo(GetSpecialization()))
  1005. end
  1006. end
  1007.  
  1008. return name or "None"
  1009. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement