Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.22 KB | None | 0 0
  1. --[[
  2. ****************************************************************
  3. EavesDrop
  4.  
  5. Author: Grayhoof. Original idea by Bant. Coding help/samples
  6. from Andalia`s SideCombatLog and CombatChat.
  7.  
  8. Notes: Code comments coming at a later time.
  9. ****************************************************************]]
  10.  
  11. EavesDrop = LibStub("AceAddon-3.0"):NewAddon("EavesDrop", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0")
  12. local EavesDrop = EavesDrop
  13. local db
  14.  
  15. local L = LibStub("AceLocale-3.0"):GetLocale("EavesDrop", true)
  16. local media = LibStub("LibSharedMedia-3.0")
  17.  
  18. local OUTGOING = 1
  19. local INCOMING = -1
  20. local MISC = 3
  21.  
  22. local critchar = "*"
  23. local deathchar = "†"
  24. local crushchar = "^"
  25. local glancechar = "~"
  26. local newhigh = "|cffffff00!|r"
  27.  
  28. local arrEventData = {}
  29. local arrEventFrames = {}
  30. local frameSize = 21
  31. local arrSize = 10
  32. local arrDisplaySize = 20
  33. local arrMaxSize = 128
  34. local scroll = 0
  35. local allShown = false
  36. local totDamageIn = 0
  37. local totDamageOut = 0
  38. local totHealingIn = 0
  39. local totHealingOut = 0
  40. local timeStart = 0
  41. local curTime = 0
  42. local lastTime = 0
  43.  
  44. --LUA calls
  45. local _G = _G
  46. local tonumber = tonumber
  47. local strsub = strsub
  48. local string_format = string.format
  49. local string_match = string.match
  50. local gsub = gsub
  51. local tremove = tremove
  52. local tinsert = tinsert
  53. local function string_nil(val)
  54. if val then
  55. return val
  56. else
  57. return UNKNOWN
  58. end
  59. end
  60.  
  61. --API calls
  62. local UnitName = UnitName
  63. local UnitXP = UnitXP
  64. local GetSpellInfo = GetSpellInfo
  65. local GetTime = GetTime
  66. local InCombatLockdown = InCombatLockdown
  67.  
  68. --Combat log locals
  69. local pxp = UnitXP("player")
  70. local skillmsg = gsub(gsub(gsub(SKILL_RANK_UP, '%d%$', ''), '%%s', '(.+)'), '%%d', '(%%d+)')
  71. local CombatLog_Object_IsA = CombatLog_Object_IsA
  72. local Blizzard_CombatLog_CurrentSettings
  73.  
  74. local COMBATLOG_OBJECT_NONE = COMBATLOG_OBJECT_NONE
  75. local COMBATLOG_FILTER_MINE = COMBATLOG_FILTER_MINE
  76. local COMBATLOG_FILTER_MY_PET = COMBATLOG_FILTER_MY_PET
  77. local COMBATLOG_FILTER_HOSTILE = bit.bor(
  78. COMBATLOG_FILTER_HOSTILE_PLAYERS,
  79. COMBATLOG_FILTER_HOSTILE_UNITS)
  80.  
  81. local COMBAT_EVENTS = {
  82. ["SWING_DAMAGE"] = "DAMAGE",
  83. ["RANGE_DAMAGE"] = "DAMAGE",
  84. ["SPELL_DAMAGE"] = "DAMAGE",
  85. ["SPELL_PERIODIC_DAMAGE"] = "DAMAGE",
  86. ["ENVIRONMENTAL_DAMAGE"] = "DAMAGE",
  87. ["DAMAGE_SHIELD"] = "DAMAGE",
  88. ["DAMAGE_SPLIT"] = "DAMAGE",
  89. ["SPELL_HEAL"] = "HEAL",
  90. ["SPELL_PERIODIC_HEAL"] = "HEAL",
  91. ["SWING_MISSED"] = "MISS",
  92. ["RANGE_MISSED"] = "MISS",
  93. ["SPELL_MISSED"] = "MISS",
  94. ["SPELL_PERIODIC_MISSED"] = "MISS",
  95. ["DAMAGE_SHIELD_MISSED"] = "MISS",
  96. ["SPELL_DRAIN"] = "DRAIN",
  97. ["SPELL_LEECH"] = "DRAIN",
  98. ["SPELL_PERIODIC_DRAIN"] = "DRAIN",
  99. ["SPELL_PERIODIC_LEECH"] = "DRAIN",
  100. ["SPELL_ENERGIZE"] = "POWER",
  101. ["SPELL_PERIODIC_ENERGIZE"] = "POWER",
  102. ["PARTY_KILL"] = "DEATH",
  103. ["UNIT_DIED"] = "DEATH",
  104. ["UNIT_DESTROYED"] = "DEATH",
  105. }
  106.  
  107. local SCHOOL_STRINGS = {
  108. [SCHOOL_MASK_PHYSICAL] = SPELL_SCHOOL0_CAP,
  109. [SCHOOL_MASK_HOLY] = SPELL_SCHOOL1_CAP,
  110. [SCHOOL_MASK_FIRE] = SPELL_SCHOOL2_CAP,
  111. [SCHOOL_MASK_NATURE] = SPELL_SCHOOL3_CAP,
  112. [SCHOOL_MASK_FROST] = SPELL_SCHOOL4_CAP,
  113. [SCHOOL_MASK_SHADOW] = SPELL_SCHOOL5_CAP,
  114. [SCHOOL_MASK_ARCANE] = SPELL_SCHOOL6_CAP,
  115. }
  116.  
  117. local POWER_STRINGS = {
  118. [SPELL_POWER_MANA] = MANA,
  119. [SPELL_POWER_RAGE] = RAGE,
  120. [SPELL_POWER_FOCUS] = FOCUS,
  121. [SPELL_POWER_ENERGY] = ENERGY,
  122. [SPELL_POWER_RUNES] = RUNES,
  123. [SPELL_POWER_RUNIC_POWER] = RUNIC_POWER,
  124. [SPELL_POWER_SOUL_SHARDS] = SHARDS,
  125. [SPELL_POWER_LUNAR_POWER] = LUNAR_POWER,
  126. [SPELL_POWER_HOLY_POWER] = HOLY_POWER,
  127. [SPELL_POWER_ALTERNATE_POWER] = ALTERNATE_RESOURCE_TEXT,
  128. [SPELL_POWER_MAELSTROM] = MAELSTROM_POWER,
  129. [SPELL_POWER_CHI] = CHI_POWER,
  130. [SPELL_POWER_INSANITY] = INSANITY_POWER,
  131. --[SPELL_POWER_OBSOLETE] = 14;
  132. --[SPELL_POWER_OBSOLETE2] = 15;
  133. [SPELL_POWER_ARCANE_CHARGES] = ARCANE_CHARGES_POWER,
  134. [SPELL_POWER_FURY] = FURY,
  135. [SPELL_POWER_PAIN] = PAIN,
  136. }
  137.  
  138. --set table default size sense table.insert no longer does
  139. for i=1, arrMaxSize do
  140. arrEventData[i] = {}
  141. end
  142.  
  143. local function convertRGBtoHEXString(color, text)
  144. return string_format("|cFF%02x%02x%02x%s|r", ceil(color.r * 255), ceil(color.g * 255), ceil(color.b * 255), text)
  145. end
  146.  
  147. local function shortenValue(value)
  148. if value >= 10000000 then
  149. value = string_format("%.1fm", value / 1000000)
  150. elseif value >= 1000000 then
  151. value = string_format("%.2fm",value / 1000000)
  152. elseif value >= 100000 then
  153. value = string_format("%.0fk",value / 1000)
  154. elseif value >= 10000 then
  155. value = string_format("%.1fk",value / 1000)
  156. end
  157. return value
  158. end
  159.  
  160. local function round(num, idp)
  161. return tonumber(string_format("%." .. (idp or 0) .. "f", num))
  162. end
  163.  
  164. local function cleanstring(s)
  165. s = gsub(s, "|r", "")
  166. s = gsub(s, "|c........", "")
  167. s = gsub(s, "|Hunit:..................:([%w%s*%-*]*)|h", "")
  168. s = gsub(s, "|Haction:([%w_*]*)|h", "")
  169. s = gsub(s, "|Hitem:(%d+)|h", "")
  170. s = gsub(s, "|Hicon:%d+:dest|h", "")
  171. s = gsub(s, "|Hicon:%d+:source|h", "")
  172. s = gsub(s, "|Hspell:%d+:([%w_*]*)|h", "")
  173. s = gsub(s, "|TInterface.TargetingFrame.UI.RaidTargetingIcon.%d.blp:0|t", "")
  174. s = gsub(s, "|h", "")
  175. s = gsub(s, "\n", ", ")
  176. s = gsub(s, "\124", "\124\124")
  177. return s
  178. end
  179.  
  180. local function clearSummary()
  181. totDamageIn = 0
  182. totDamageOut = 0
  183. totHealingIn = 0
  184. totHealingOut = 0
  185. end
  186.  
  187. --Main Functions
  188. function EavesDrop:OnInitialize()
  189.  
  190. --setup table for display frame objects
  191. for i=1, arrDisplaySize do
  192. arrEventFrames[i] = {}
  193. arrEventFrames[i].frame = _G[string_format("EavesDropEvent%d", i)]
  194. arrEventFrames[i].text = _G[string_format("EavesDropEvent%dEventText", i)]
  195. arrEventFrames[i].intexture = _G[string_format("EavesDropEvent%dIncomingTexture", i)]
  196. arrEventFrames[i].intextureframe = _G[string_format("EavesDropEvent%dIncoming", i)]
  197. arrEventFrames[i].outtexture = _G[string_format("EavesDropEvent%dOutgoingTexture", i)]
  198. arrEventFrames[i].outtextureframe = _G[string_format("EavesDropEvent%dOutgoing", i)]
  199. end
  200.  
  201. self.db = LibStub("AceDB-3.0"):New("EavesDropDB", self:GetDefaultConfig())
  202. self.chardb = LibStub("AceDB-3.0"):New("EavesDropStatsDB", {profile = {[OUTGOING] = {},[INCOMING] = {}}})
  203.  
  204. self:SetupOptions()
  205.  
  206. --callbacks for profile changes
  207. self.db.RegisterCallback(self, "OnProfileChanged", "UpdateFrame")
  208. self.db.RegisterCallback(self, "OnProfileCopied", "UpdateFrame")
  209. self.db.RegisterCallback(self, "OnProfileReset", "UpdateFrame")
  210.  
  211. --local the profile table
  212. db = self.db.profile
  213.  
  214. self:PerformDisplayOptions()
  215.  
  216.  
  217. self:RegisterEvent("ADDON_LOADED", self.SetFonts)
  218. end
  219.  
  220. function EavesDrop:OnEnable()
  221. self:RegisterEvent("PLAYER_DEAD")
  222. self:UpdateExpEvents()
  223. self:UpdateRepHonorEvents()
  224. self:UpdateCombatEvents()
  225. self:UpdateBuffEvents()
  226. self:UpdateBuffFadeEvents()
  227. self:UpdateSkillEvents()
  228.  
  229. self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED","CombatEvent")
  230.  
  231. --show frame
  232. EavesDropFrame:Show()
  233. if (db["FADEFRAME"]) then
  234. self:HideFrame()
  235. end
  236.  
  237. end
  238.  
  239. function EavesDrop:OnDisable()
  240. self:UnregisterAllEvents()
  241. EavesDropFrame:Hide()
  242. end
  243.  
  244. function EavesDrop:UpdateCombatEvents()
  245. if (db["COMBAT"] == true) then
  246. self:RegisterEvent("PLAYER_REGEN_DISABLED")
  247. self:RegisterEvent("PLAYER_REGEN_ENABLED")
  248. else
  249. self:UnregisterEvent("PLAYER_REGEN_DISABLED")
  250. self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  251. end
  252. end
  253.  
  254. function EavesDrop:UpdateExpEvents()
  255. if (db["EXP"] == true) then
  256. self:RegisterEvent("PLAYER_XP_UPDATE")
  257. else
  258. self:UnregisterEvent("PLAYER_XP_UPDATE")
  259. end
  260. end
  261.  
  262. function EavesDrop:UpdateRepHonorEvents()
  263. if (db["REP"] or db["HONOR"]) then
  264. self:RegisterEvent("COMBAT_TEXT_UPDATE")
  265. else
  266. self:UnregisterEvent("COMBAT_TEXT_UPDATE")
  267. end
  268. end
  269.  
  270. function EavesDrop:UpdateBuffEvents()
  271. if (db["DEBUFF"] == true or db["BUFF"] == true) then
  272. COMBAT_EVENTS["SPELL_AURA_APPLIED"] = "BUFF"
  273. COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED"] = "BUFF"
  274. COMBAT_EVENTS["SPELL_AURA_APPLIED_DOSE"] = "BUFF"
  275. COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED_DOSE"] = "BUFF"
  276. COMBAT_EVENTS["ENCHANT_APPLIED"] = "ENCHANT_APPLIED"
  277. else
  278. COMBAT_EVENTS["SPELL_AURA_APPLIED"] = nil
  279. COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED"] = nil
  280. COMBAT_EVENTS["SPELL_AURA_APPLIED_DOSE"] = nil
  281. COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED_DOSE"] = nil
  282. COMBAT_EVENTS["ENCHANT_APPLIED"] = nil
  283. end
  284. end
  285.  
  286. function EavesDrop:UpdateBuffFadeEvents()
  287. if (db["DEBUFFFADE"] == true or db["BUFFFADE"] == true) then
  288. COMBAT_EVENTS["SPELL_AURA_REMOVED"] = "FADE"
  289. COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED"] = "FADE"
  290. COMBAT_EVENTS["SPELL_AURA_REMOVED_DOSE"] = "FADE"
  291. COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED_DOSE"] = "FADE"
  292. COMBAT_EVENTS["ENCHANT_REMOVED"] = "ENCHANT_REMOVED"
  293. else
  294. COMBAT_EVENTS["SPELL_AURA_REMOVED"] = nil
  295. COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED"] = nil
  296. COMBAT_EVENTS["SPELL_AURA_REMOVED_DOSE"] = nil
  297. COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED_DOSE"] = nil
  298. COMBAT_EVENTS["ENCHANT_REMOVED"] = nil
  299. end
  300. end
  301.  
  302. function EavesDrop:UpdateSkillEvents()
  303. if (db["SKILL"] == true) then
  304. self:RegisterEvent("CHAT_MSG_SKILL")
  305. else
  306. self:UnregisterEvent("CHAT_MSG_SKILL")
  307. end
  308. end
  309.  
  310. ----------------------
  311. --Reset everything to default
  312. function EavesDrop:UpdateFrame()
  313. --local the profile table
  314. db = self.db.profile
  315. self:UpdateExpEvents()
  316. self:UpdateRepHonorEvents()
  317. self:UpdateCombatEvents()
  318. self:UpdateBuffEvents()
  319. self:UpdateBuffFadeEvents()
  320. self:UpdateSkillEvents()
  321. self:PerformDisplayOptions()
  322. self:UpdateEvents()
  323. end
  324.  
  325. function EavesDrop:PerformDisplayOptions()
  326. --set size
  327. arrSize = db["NUMLINES"]
  328. frameSize = db["LINEHEIGHT"] + 1
  329. local totalh = (frameSize * arrSize) + 50
  330. local totalw = (db["LINEHEIGHT"] * 2) + db["LINEWIDTH"]
  331. EavesDropFrame:SetHeight(totalh)
  332. EavesDropFrame:SetWidth(totalw)
  333. --update look of frame
  334. local r,g,b,a = db["FRAME"].r, db["FRAME"].g, db["FRAME"].b, db["FRAME"].a
  335. --main frame
  336. EavesDropFrame:SetBackdropColor(r, g, b, a)
  337. EavesDropTopBar:SetGradientAlpha("VERTICAL", r*.1, g*.1, b*.1, 0, r*.2, g*.2, b*.2, a)
  338. EavesDropBottomBar:SetGradientAlpha("VERTICAL", r*.2, g*.2, b*.2, a, r*.1, g*.1, b*.1, 0)
  339. EavesDropTopBar:SetWidth(totalw-10)
  340. EavesDropBottomBar:SetWidth(totalw-10)
  341. r,g,b,a = db["BORDER"].r, db["BORDER"].g, db["BORDER"].b, db["BORDER"].a
  342. EavesDropFrame:SetBackdropBorderColor(r, g, b, a)
  343. EavesDropFrame:EnableMouse(not db["LOCKED"])
  344. --tooltips
  345. EavesDropTab.tooltipText = L["TabTip"]
  346. if (db["SCROLLBUTTON"]) then
  347. EavesDropFrameDownButton:Hide()
  348. EavesDropFrameUpButton:Hide()
  349. else
  350. EavesDropFrameDownButton.tooltipText = L["DownTip"]
  351. EavesDropFrameUpButton.tooltipText = L["UpTip"]
  352. self:UpdateScrollButtons()
  353. end
  354. self.ToolTipAnchor = "ANCHOR_"..strupper(db["TOOLTIPSANCHOR"])
  355. --labels
  356. r,g,b,a = db["LABELC"].r, db["LABELC"].g, db["LABELC"].b, db["LABELC"].a
  357. if (db["FLIP"] == true) then
  358. EavesDropFramePlayerText:SetText(L["TargetLabel"])
  359. EavesDropFrameTargetText:SetText(L["PlayerLabel"])
  360. else
  361. EavesDropFramePlayerText:SetText(L["PlayerLabel"])
  362. EavesDropFrameTargetText:SetText(L["TargetLabel"])
  363. end
  364. EavesDropFramePlayerText:SetTextColor(r,g,b,a)
  365. EavesDropFrameTargetText:SetTextColor(r,g,b,a)
  366. --fonts
  367. self:SetFonts()
  368. --tab
  369. if (db["HIDETAB"] == true) then
  370. EavesDropTab:Hide()
  371. else
  372. EavesDropTab:Show()
  373. end
  374. --position frame (have to schedule cause UI scale is still 1 for some reason during init)
  375. self:ScheduleTimer("PlaceFrame", .1, self)
  376.  
  377. self:ResetEvents()
  378. self:SetupHistory()
  379.  
  380. if (db["FADEFRAME"]) then
  381. self:HideFrame()
  382. else
  383. self:ShowFrame()
  384. end
  385. end
  386.  
  387. function EavesDrop:SetFonts()
  388. EavesDropFontNormal:SetFont(media:Fetch("font", db["FONT"]), db["TEXTSIZE"])
  389. EavesDropFontNormalSmall:SetFont(media:Fetch("font", db["FONT"]), db["TEXTSIZE"])
  390. end
  391.  
  392. function EavesDrop:PlaceFrame()
  393. local frame, x, y = EavesDropFrame, db.x, db.y
  394. frame:ClearAllPoints()
  395. if x==0 and y==0 then
  396. frame:SetPoint("CENTER", UIParent, "CENTER")
  397. else
  398. local es = frame:GetEffectiveScale()
  399. frame:SetPoint("TOPLEFT", UIParent, "CENTER", x/es, y/es)
  400. end
  401. end
  402.  
  403. function EavesDrop:HideFrame()
  404. EavesDropFrame:SetAlpha(0)
  405. end
  406.  
  407. function EavesDrop:ShowFrame()
  408. EavesDropFrame:SetAlpha(1)
  409. EavesDropTab:SetAlpha(0)
  410. end
  411.  
  412. function EavesDrop:CombatEvent()
  413. local larg1, timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 = CombatLogGetCurrentEventInfo()
  414. local etype = COMBAT_EVENTS[event]
  415. if not etype then return end
  416.  
  417. if not Blizzard_CombatLog_CurrentSettings then
  418. Blizzard_CombatLog_CurrentSettings = Blizzard_CombatLog_Filters.filters[Blizzard_CombatLog_Filters.currentFilter]
  419. end
  420.  
  421. --check for reflect damage
  422. if event == "SPELL_DAMAGE" and sourceName == destName and CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_HOSTILE) then
  423. self:ParseReflect(timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
  424. return
  425. end
  426.  
  427. local toPlayer, fromPlayer, toPet, fromPet
  428. if (sourceName and not CombatLog_Object_IsA(sourceFlags, COMBATLOG_OBJECT_NONE) ) then
  429. fromPlayer = CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MINE)
  430. fromPet = CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MY_PET)
  431. end
  432. if (destName and not CombatLog_Object_IsA(destFlags, COMBATLOG_OBJECT_NONE) ) then
  433. toPlayer = CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_MINE)
  434. toPet = CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_MY_PET)
  435. end
  436.  
  437. if not fromPlayer and not toPlayer and not fromPet and not toPet then return end
  438. if (not fromPlayer and not toPlayer) and (toPet or fromPet) and not db["PET"] then return end
  439.  
  440. local amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing
  441. local spellId, spellName, spellSchool, missType, powerType, extraAmount, environmentalType, overHeal
  442. local text, texture, message, inout, color
  443.  
  444. --defaults
  445. if toPet or fromPet then texture = "pet" end
  446. if toPlayer or toPet then inout = INCOMING end
  447. if fromPlayer or fromPet then inout = OUTGOING end
  448. if toPet then color = db["PETI"] end
  449. if fromPet then color = db["PETO"] end
  450.  
  451. --get combat log message (for tooltip)
  452. message = CombatLog_OnEvent(Blizzard_CombatLog_CurrentSettings, timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
  453.  
  454.  
  455. ------------damage----------------
  456. if etype == "DAMAGE" then
  457. local intype, outtype
  458. if event == "SWING_DAMAGE" then
  459. amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing = a1, a2, a3, a4, a5, a6, a7, a8, a9
  460. if school == SCHOOL_MASK_PHYSICAL then
  461. outtype, intype = "TMELEE", "PHIT"
  462. else
  463. outtype, intype = "TSPELL", "PSPELL"
  464. end
  465. elseif event == "RANGE_DAMAGE" then
  466. spellId, spellName, spellSchool, amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing = a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
  467. if school == SCHOOL_MASK_PHYSICAL then
  468. outtype, intype = "TMELEE", "PHIT"
  469. else
  470. outtype, intype = "TSPELL", "PSPELL"
  471. end
  472. elseif event == "ENVIRONMENTAL_DAMAGE" then
  473. environmentalType, amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing = a1, a2, a3, a4, a5, a6, a7, a8, a9, a10
  474. outtype, intype = "TSPELL", "PSPELL"
  475. else
  476. spellId, spellName, spellSchool, amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing = a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
  477. texture = select(3, GetSpellInfo(spellId))
  478. outtype, intype = "TSPELL", "PSPELL"
  479. end
  480. text = tostring(shortenValue(amount))
  481.  
  482. if (critical) then text = critchar..text..critchar end
  483. if (crushing) then text = crushchar..text..crushchar end
  484. if (glancing) then text = glancechar..text..glancechar end
  485. if (resisted) then text = string_format("%s (%d)", text, shortenValue(resisted)) end
  486. if (blocked) then text = string_format("%s (%d)", text, shortenValue(blocked)) end
  487. if (absorbed) then text = string_format("%s (%d)", text, shortenValue(absorbed))end
  488.  
  489. if fromPlayer then
  490. if (self:TrackStat(inout, "hit", spellName, texture, SCHOOL_STRINGS[school], amount, critical, message)) then
  491. text = newhigh..text..newhigh
  492. end
  493. --fix colors for self physical
  494. if school == SCHOOL_MASK_PHYSICAL then school = 0 end
  495. color = self:SpellColor(db[outtype], SCHOOL_STRINGS[school])
  496. totDamageOut = totDamageOut + amount
  497. elseif toPlayer then
  498. if (self:TrackStat(inout, "hit", spellName, texture, SCHOOL_STRINGS[school], amount, critical, message)) then
  499. text = newhigh..text..newhigh
  500. end
  501. color = self:SpellColor(db[intype], SCHOOL_STRINGS[school])
  502. text = "-"..text
  503. totDamageIn = totDamageIn + amount
  504. elseif toPet then
  505. text = "-"..text
  506. end
  507. self:DisplayEvent(inout, text, texture, color, message)
  508. ------------buff/debuff gain----------------
  509. elseif etype == "BUFF" then
  510. spellId, spellName, spellSchool, auraType, amount = a1, a2, a3, a4, a5
  511. texture = select(3, GetSpellInfo(spellId))
  512. if toPlayer and db[auraType] then
  513. self:DisplayEvent(INCOMING, self:ShortenString(spellName), texture, db["P"..auraType], message)
  514. else return
  515. end
  516. ------------buff/debuff lose----------------
  517. elseif etype == "FADE" then
  518. spellId, spellName, spellSchool, auraType, amount = a1, a2, a3, a4, a5
  519. texture = select(3, GetSpellInfo(spellId))
  520. if toPlayer and db[auraType.."FADE"] then
  521. self:DisplayEvent(INCOMING, self:ShortenString(spellName).." "..L["Fades"], texture, db["P"..auraType], message)
  522. else return
  523. end
  524. ------------heals----------------
  525. elseif etype == "HEAL" then
  526. spellId, spellName, spellSchool, amount, overHeal, absorbed, critical = a1, a2, a3, a4, a5, a6, a7
  527. text = tostring(shortenValue(amount))
  528. texture = select(3, GetSpellInfo(spellId))
  529.  
  530. if toPlayer then
  531. totHealingIn = totHealingIn + amount
  532. if (amount < db["HFILTER"]) then return end
  533. if (db["OVERHEAL"]) and overHeal > 0 then text = string_format("%d {%d}", shortenValue(amount-overHeal), shortenValue(overHeal)) end
  534. if (critical) then text = critchar..text..critchar end
  535. if (db["HEALERID"] == true and not fromPlayer) then text = text.." ("..sourceName..")" end
  536. color = db["PHEAL"]
  537. if (self:TrackStat(inout, "heal", spellName, texture, SCHOOL_STRINGS[spellSchool], amount, critical, message)) then
  538. text = newhigh..text..newhigh
  539. end
  540. text = "+"..text
  541. elseif fromPlayer then
  542. totHealingOut = totHealingOut + amount
  543. if (amount < db["HFILTER"]) then return end
  544. if (db["OVERHEAL"]) and overHeal > 0 then text = string_format("%d {%d}", shortenValue(amount-overHeal), shortenValue(overHeal)) end
  545. if (critical) then text = critchar..text..critchar end
  546. color = db["THEAL"]
  547. if (self:TrackStat(inout, "heal", spellName, texture, SCHOOL_STRINGS[spellSchool], amount, critical, message)) then
  548. text = newhigh..text..newhigh
  549. end
  550. text = "+"..text
  551. if (db["HEALERID"] == true) then text = destName..": "..text end
  552. end
  553. self:DisplayEvent(inout, text, texture, color, message)
  554. ------------misses----------------
  555. elseif etype == "MISS" then
  556. local tcolor
  557. if event == "SWING_MISSED" or event == "RANGE_MISSED" then
  558. missType = a1
  559. tcolor = "TMELEE"
  560. else
  561. spellId, spellName, spellSchool, missType = a1, a2, a3, a4
  562. texture = select(3, GetSpellInfo(spellId))
  563. tcolor = "TSPELL"
  564. end
  565. text = _G[missType]
  566. if fromPlayer then
  567. color = db[tcolor]
  568. elseif toPlayer then
  569. if missType == "REFLECT" then
  570. self:SetReflect(sourceName, spellName)
  571. end
  572. color = db["PMISS"]
  573. end
  574. self:DisplayEvent(inout, text, texture, color, message)
  575. ------------leech and drains----------------
  576. elseif etype == "DRAIN" then
  577. if (db["GAINS"]) then
  578. spellId, spellName, spellSchool, amount, powerType, extraAmount = a1, a2, a3, a4, a5, a6
  579. texture = select(3, GetSpellInfo(spellId))
  580. if toPlayer then
  581. text = string_format("-%d %s", amount, string_nil(POWER_STRINGS[powerType]))
  582. color = db["PGAIN"]
  583. elseif fromPlayer and extraAmount then
  584. if (extraAmount < db["MFILTER"]) then return end
  585. text = string_format("+%d %s", extraAmount, string_nil(POWER_STRINGS[powerType]))
  586. color = db["PGAIN"]
  587. elseif fromPlayer then
  588. return
  589. --for showing your drain damage
  590. --text = string_format("%d %s", amount, string_nil(POWER_STRINGS[powerType]))
  591. --color = db["TSPELL"]
  592. end
  593. self:DisplayEvent(inout, text, texture, color, message)
  594. end
  595. ------------power gains----------------
  596. elseif etype == "POWER" then
  597. if (db["GAINS"]) then
  598. spellId, spellName, spellSchool, amount, powerType = a1, a2, a3, a4, a5
  599. texture = select(3, GetSpellInfo(spellId))
  600. if toPlayer then
  601. if (amount < db["MFILTER"]) then return end
  602. color = db["PGAIN"]
  603. elseif not toPet then
  604. return
  605. end
  606. text = string_format("+%d %s", amount, string_nil(POWER_STRINGS[powerType]))
  607. self:DisplayEvent(inout, text, texture, color, message)
  608. end
  609. ------------deaths----------------
  610. elseif etype == "DEATH" then
  611. if fromPlayer then
  612. text = deathchar..destName..deathchar
  613. self:DisplayEvent(MISC, text, texture, db["DEATH"], message)
  614. else return
  615. end
  616. ------------enchants----------------
  617. elseif etype == "ENCHANT_APPLIED" then
  618. spellName = a1
  619. self:DisplayEvent(INCOMING, self:ShortenString(spellName), texture, db["PBUFF"], message)
  620. elseif etype == "ENCHANT_REMOVED" then
  621. spellName = a1
  622. self:DisplayEvent(INCOMING, self:ShortenString(spellName).." "..L["Fades"], texture, db["PBUFF"], message)
  623. -------------anything else-------------
  624. --else
  625. --self:Print(event, sourceName, destName)
  626. end
  627. end
  628.  
  629. function EavesDrop:PLAYER_XP_UPDATE()
  630. local xp = UnitXP("player")
  631. local xpgained = xp - pxp
  632. self:DisplayEvent(MISC, string_format("+%d (%s)", shortenValue(xpgained), XP), nil, db["EXPC"], nil)
  633. pxp = xp
  634. end
  635.  
  636. function EavesDrop:COMBAT_TEXT_UPDATE(event, larg1, larg2, larg3)
  637. if larg1=="FACTION" then
  638. local sign = "+"
  639. if (tonumber(larg3) < 0) then sign = "" end
  640. self:DisplayEvent(MISC, string_format("%s%d (%s)", sign, larg3, larg2), nil, db["REPC"], nil)
  641. elseif larg1=="HONOR_GAINED" then
  642. self:DisplayEvent(MISC, string_format("+%d (%s)", larg2, HONOR) , nil, db["HONORC"], nil)
  643. end
  644. end
  645.  
  646. function EavesDrop:PLAYER_REGEN_DISABLED()
  647. pxp = UnitXP("player")
  648. timeStart = GetTime()
  649. clearSummary()
  650. self:DisplayEvent(MISC, L["StartCombat"], nil, db["MISC"])
  651. --stop on update, since in combat
  652. self:StopOnUpdate()
  653. --show frame, if its hidden
  654. self:ShowFrame()
  655. --flag all as being shown, so buttons appear
  656. allShown = true
  657. end
  658.  
  659. function EavesDrop:PLAYER_REGEN_ENABLED()
  660. self:DisplayEvent(MISC, L["EndCombat"], nil, db["MISC"])
  661. if (db["SUMMARY"] == true) then
  662. local duration = round(GetTime() - timeStart, 1)
  663. local DPS = round(totDamageOut/duration,1) or 0
  664. local HPS = round(totHealingOut/duration,1) or 0
  665. local IDPS = round(totDamageIn/duration,1) or 0
  666. local IHPS = round(totHealingIn/duration,1) or 0
  667. local strSummary = convertRGBtoHEXString(db["MISC"], duration.." "..L["IncombatSummary"]).."\n"..
  668. convertRGBtoHEXString(db["PHIT"], L["IncomingDamge"]..": "..totDamageIn.." ("..IDPS..")").."\n"..
  669. convertRGBtoHEXString(db["PHEAL"], L["IncomingHeals"]..": "..totHealingIn.." ("..IHPS..")").."\n"..
  670. convertRGBtoHEXString(db["THEAL"], L["OutgoingHeals"]..": "..totHealingOut.." ("..HPS..")").."\n"..
  671. convertRGBtoHEXString(db["TSPELL"], L["OutgoingDamage"]..": "..totDamageOut.." ("..DPS..")")
  672.  
  673. self:DisplayEvent(MISC,
  674. convertRGBtoHEXString(db["PHIT"], shortenValue(totDamageIn)).." | "..
  675. convertRGBtoHEXString(db["PHEAL"], shortenValue(totHealingIn)).." | "..
  676. convertRGBtoHEXString(db["THEAL"], shortenValue(totHealingOut)).." | "..
  677. convertRGBtoHEXString(db["TSPELL"], shortenValue(totDamageOut)),
  678. nil, db["MISC"], strSummary)
  679. end
  680. clearSummary()
  681. --since out of combat, try and start onupdate to count down frames
  682. self:StartOnUpdate()
  683. end
  684.  
  685. function EavesDrop:PLAYER_DEAD()
  686. self:DisplayEvent(MISC, deathchar..UnitName("player")..deathchar, nil, db["DEATH"])
  687. end
  688.  
  689. function EavesDrop:CHAT_MSG_SKILL(event, larg1)
  690. local skill, rank = string_match(larg1, skillmsg)
  691. if skill then
  692. self:DisplayEvent(MISC, string_format("%s: %d", skill, rank), nil, db["SKILLC"], larg1)
  693. end
  694. end
  695.  
  696. local tempcolor = {r = 1, g = 1, b = 1}
  697. function EavesDrop:DisplayEvent(type, text, texture, color, message, spellname)
  698. --remove oldest table and create new display event
  699. local pEvent = tremove(arrEventData, 1)
  700. local tooltiptext = message
  701. if (db["FLIP"] == true) then type = type * -1 end
  702. pEvent.type = type
  703. pEvent.text = text
  704. pEvent.texture = texture
  705. pEvent.color = color or tempcolor
  706. if spellname then
  707. tooltiptext = spellname
  708. end
  709. if (db["TIMESTAMP"] == true) then
  710. pEvent.tooltipText = string_format('|cffffffff%s|r\n%s', date('%I:%M:%S'), tooltiptext or '')
  711. else
  712. pEvent.tooltipText = tooltiptext
  713. end
  714. tinsert(arrEventData, arrMaxSize, pEvent)
  715. self:UpdateEvents()
  716. end
  717.  
  718. function EavesDrop:UpdateEvents()
  719. local key, value
  720. local frame, text, intexture, outexture
  721. local start, finish
  722. local delay = db["FADETIME"] + (4 * arrSize)
  723. start = arrMaxSize-scroll
  724. finish = arrMaxSize-arrSize+1-scroll
  725. for i=start,finish,-1 do
  726. value = arrEventData[i]
  727. key = i - (arrMaxSize-arrSize) + scroll
  728. frame = arrEventFrames[key].frame
  729. text = arrEventFrames[key].text
  730. intexture = arrEventFrames[key].intexture
  731. outtexture = arrEventFrames[key].outtexture
  732. if (not value.text) then
  733. text:SetText(nil)
  734. intexture:SetTexture(nil)
  735. outtexture:SetTexture(nil)
  736. frame.delay = 0
  737. frame.alpha = 0
  738. frame.tooltipText = nil
  739. frame:Hide()
  740. else
  741. if (value.type == INCOMING) then
  742. text:SetJustifyH("LEFT")
  743. text:SetWidth(db["LINEWIDTH"]-20)
  744. text:SetPoint("LEFT", intexture, "RIGHT", 5, 0)
  745. intexture:SetTexCoord(.1,.9,.1,.9)
  746. outtexture:SetTexture(nil)
  747. if value.texture == "pet" then
  748. SetPortraitTexture(intexture, value.texture)
  749. else
  750. intexture:SetTexture(value.texture)
  751. end
  752. elseif (value.type == OUTGOING) then
  753. text:SetJustifyH("RIGHT")
  754. text:SetWidth(db["LINEWIDTH"]-20)
  755. text:SetPoint("LEFT", intexture, "RIGHT", 5, 0)
  756. intexture:SetTexture(nil)
  757. outtexture:SetTexCoord(.1,.9,.1,.9)
  758. if value.texture == "pet" then
  759. SetPortraitTexture(outtexture, value.texture)
  760. else
  761. outtexture:SetTexture(value.texture)
  762. end
  763. else
  764. text:SetJustifyH("CENTER")
  765. text:SetWidth((db["LINEHEIGHT"] * 2) + (db["LINEWIDTH"]-10))
  766. text:SetPoint("LEFT", intexture, "LEFT", 0, 0)
  767. intexture:SetTexture(nil)
  768. outtexture:SetTexture(nil)
  769. end
  770. text:SetText(value.text)
  771. text:SetTextColor(value.color.r, value.color.g, value.color.b)
  772. frame.delay = delay
  773. frame.alpha = 1
  774. if (db["TOOLTIPS"] == true) then
  775. frame.tooltipText = value.tooltipText
  776. else
  777. frame.tooltipText = nil
  778. end
  779. frame:Show()
  780. frame:SetAlpha(frame.alpha)
  781. end
  782. delay = delay - 4
  783. --set clickthru
  784. if (frame.tooltipText) then
  785. frame:EnableMouse(true)
  786. else
  787. frame:EnableMouse(false)
  788. end
  789. end
  790. --Update scrolls
  791. self:UpdateScrollButtons()
  792. --try to start up onUpdate. if in combat it won't start.
  793. self:StartOnUpdate()
  794. end
  795.  
  796. function EavesDrop:StartOnUpdate()
  797. --only start on update if not in combat, and not already started.
  798. if not InCombatLockdown() and not self.OnUpdateStarted then
  799. lastTime = GetTime()
  800. self.OnUpdateStarted = self:ScheduleRepeatingTimer("OnUpdate", .2, self)
  801. end
  802. end
  803.  
  804. function EavesDrop:StopOnUpdate()
  805. self:CancelTimer(self.OnUpdateStarted, true)
  806. self.OnUpdateStarted = nil
  807. end
  808.  
  809. function EavesDrop:ResetEvents()
  810. local frame, text, intexture, outexture
  811. for i=1,arrDisplaySize do
  812. frame = arrEventFrames[i].frame
  813. text = arrEventFrames[i].text
  814. intexture = arrEventFrames[i].intextureframe
  815. outtexture = arrEventFrames[i].outtextureframe
  816. frame.delay = 0
  817. frame.alpha = 0
  818. frame.tooltipText = nil
  819. frame:SetHeight(db["LINEHEIGHT"] + 1)
  820. frame:SetWidth((db["LINEHEIGHT"] * 2) + db["LINEWIDTH"])
  821. frame:Hide()
  822. text:SetHeight(db["LINEHEIGHT"])
  823. intexture:SetHeight(db["LINEHEIGHT"])
  824. intexture:SetWidth(db["LINEHEIGHT"])
  825. intexture:SetPoint("LEFT", frame, "RIGHT", 5, 0)
  826. outtexture:SetHeight(db["LINEHEIGHT"])
  827. outtexture:SetWidth(db["LINEHEIGHT"])
  828. end
  829. end
  830.  
  831. function EavesDrop:OnUpdate()
  832. local frame
  833. local count = 0
  834. curTime = GetTime()
  835. elapsed = curTime - lastTime
  836. lastTime = curTime
  837. for i=1,arrSize do
  838. frame = arrEventFrames[i].frame
  839. if (frame:IsShown()) then
  840. count = count + 1
  841. frame.delay = frame.delay - elapsed
  842. if frame.delay <= 0 then
  843. frame.alpha = frame.alpha - .2
  844. frame:SetAlpha(frame.alpha)
  845. end
  846. if (frame.alpha <= 0) then
  847. frame:Hide()
  848. EavesDropFrameUpButton:Hide()
  849. count = count - 1
  850. end
  851. end
  852. end
  853. if (count == arrSize) then
  854. allShown = true
  855. else
  856. allShown = false
  857. end
  858. --if none are active, stop onUpdate
  859. if (count == 0) then
  860. self:StopOnUpdate()
  861. end
  862. --hide frame when none active
  863. if (db["FADEFRAME"]) then
  864. if ((count == 0) and (scroll==0)) then
  865. self:HideFrame()
  866. else
  867. self:ShowFrame()
  868. end
  869. end
  870. end
  871.  
  872. function EavesDrop:Scroll(this, dir)
  873. local self = EavesDrop
  874. if dir > 0 then
  875. if IsShiftKeyDown() then
  876. self:ScrollToTop()
  877. elseif IsControlKeyDown() then
  878. self:FindCombatUp()
  879. else
  880. self:ScrollUp()
  881. end
  882. elseif dir < 0 then
  883. if IsShiftKeyDown() then
  884. self:ScrollToBottom()
  885. elseif IsControlKeyDown() then
  886. self:FindCombatDown()
  887. else
  888. self:ScrollDown()
  889. end
  890. end
  891. end
  892.  
  893. function EavesDrop:FindCombatUp()
  894. for i=arrMaxSize-scroll-arrSize, 1, -1 do
  895. if arrEventData[i].text and arrEventData[i].text == L["StartCombat"] then
  896. scroll = arrMaxSize-i-arrSize+1
  897. self:UpdateScrollButtons()
  898. self:UpdateEvents()
  899. return
  900. end
  901. end
  902. end
  903.  
  904. function EavesDrop:FindCombatDown()
  905. for i=arrMaxSize-scroll+1,arrMaxSize do
  906. if arrEventData[i].text and arrEventData[i].text == L["EndCombat"] then
  907. scroll = arrMaxSize-i
  908. self:UpdateScrollButtons()
  909. self:UpdateEvents()
  910. return
  911. end
  912. end
  913. end
  914.  
  915. function EavesDrop:ScrollToTop()
  916. scroll = arrMaxSize-arrSize
  917. self:UpdateScrollButtons()
  918. self:UpdateEvents()
  919. end
  920.  
  921. function EavesDrop:ScrollToBottom()
  922. scroll = 0
  923. self:UpdateScrollButtons()
  924. self:UpdateEvents()
  925. end
  926.  
  927. function EavesDrop:ScrollUp()
  928. scroll = scroll + 1
  929. if (scroll > (arrMaxSize-arrSize)) then
  930. scroll = arrMaxSize-arrSize
  931. end
  932. self:UpdateScrollButtons()
  933. self:UpdateEvents()
  934. end
  935.  
  936. function EavesDrop:ScrollDown()
  937. scroll = scroll - 1
  938. if (scroll < 0) then
  939. scroll = 0
  940. end
  941. self:UpdateScrollButtons()
  942. self:UpdateEvents()
  943. end
  944.  
  945. function EavesDrop:UpdateScrollButtons()
  946. if ( not db["SCROLLBUTTON"]) then
  947.  
  948. if (scroll > 0) then
  949. EavesDropFrameDownButton:Show()
  950. if (scroll == arrMaxSize-arrSize) then
  951. EavesDropFrameUpButton:Hide()
  952. else
  953. EavesDropFrameUpButton:Show()
  954. end
  955. else
  956. EavesDropFrameDownButton:Hide()
  957. if (not allShown) then
  958. EavesDropFrameUpButton:Hide()
  959. else
  960. EavesDropFrameUpButton:Show()
  961. end
  962. end
  963. end
  964. end
  965.  
  966. function EavesDrop:SpellColor(option, type)
  967. if (db["SPELLCOLOR"] == true) then
  968. return db[type] or option
  969. else
  970. return option
  971. end
  972. end
  973.  
  974. -------------------------
  975. --Set last reflection
  976. function EavesDrop:ParseReflect(timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2, ...)
  977. local spellId, spellName, spellSchool, amount, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
  978. local texture = select(3, GetSpellInfo(spellId))
  979. local text = amount
  980. local messsage = CombatLog_OnEvent(Blizzard_CombatLog_CurrentSettings, timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2, ...)
  981.  
  982. --reflected events
  983. if (self.ReflectTarget == sourceName and sourceName == destName and self.ReflectSkill == spellName) then
  984. local text = string_format("%s: %d", REFLECT, shortenValue(amount))
  985. if (critical) then text = critchar..text..critchar end
  986. self:DisplayEvent(OUTGOING, text, texture, self:SpellColor(db["TSPELL"], SCHOOL_STRINGS[school]), messsage)
  987. self:ClearReflect()
  988. end
  989. end
  990.  
  991. -------------------------
  992. --Set last reflection
  993. function EavesDrop:SetReflect(target, skill)
  994. self.ReflectTarget = target
  995. self.ReflectSkill = skill
  996. --clear reflection after 3 seconds.
  997. self:ScheduleTimer(self.ClearReflect, 3, self)
  998. end
  999.  
  1000. -------------------------
  1001. --Clear last reflection
  1002. function EavesDrop:ClearReflect()
  1003. self.ReflectTarget = nil
  1004. self.ReflectSkill = nil
  1005. end
  1006.  
  1007. ------------------------------
  1008. ---Shorten a spell/buff
  1009. function EavesDrop:ShortenString(strString)
  1010. if (db["TRUNCATETYPE"] ~= "0") and strlen(strString) > db["TRUNCATESIZE"] then
  1011. if (db["TRUNCATETYPE"] == "1") then
  1012. return strsub(strString, 1, db["TRUNCATESIZE"]).."..."
  1013. elseif (db["TRUNCATETYPE"] == "2") then
  1014. return gsub(gsub(gsub(strString," of ","O"),"%s",""), "(%u)%l*", "%1")
  1015. end
  1016. else
  1017. return strString
  1018. end
  1019. end
  1020.  
  1021. ------------------------------
  1022. ---Send Text to the editbox
  1023. function EavesDrop:SendToChat(text)
  1024. local tmptext = cleanstring(text)
  1025. if tmptext == "" then return end
  1026. local edit_box = _G.ChatEdit_ChooseBoxForSend()
  1027. if edit_box:IsShown() then
  1028. edit_box:Insert(tmptext)
  1029. else
  1030. _G.ChatEdit_ActivateChat(edit_box)
  1031. edit_box:Insert(tmptext)
  1032. end
  1033. end
  1034.  
  1035. ------------------------------
  1036. ---Show/Hide history frame
  1037. function EavesDrop:ShowHistory()
  1038. if (not EavesDropHistoryFrame:IsShown()) then
  1039. EavesDropHistoryFrame:Show()
  1040. else
  1041. EavesDropHistoryFrame:Hide()
  1042. end
  1043. PlaySound("igMainMenuOptionCheckBoxOn")
  1044. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement