Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.17 KB | None | 0 0
  1. --Author Manaleaf - Sargeras, leaf#1485 if you have any questions.
  2.  
  3. function(e,...)
  4. local timeStamp = GetTime()
  5.  
  6. --Returns the current number of Player casted hots on the unit
  7. local function hotCounter(name)
  8. local destUnit
  9. local grpCount = GetNumGroupMembers()
  10. if UnitInRaid("player") then
  11. for i = 1, grpCount do
  12. local name2,realm2 = UnitName("raid"..i)
  13. if realm2 then name2 = name2 .. "-" .. realm2 end
  14.  
  15. if name2 == name then
  16. destUnit = "raid" .. i
  17. break
  18. end
  19. end
  20. elseif UnitInParty("player") then
  21. for i = 1, grpCount do
  22. local name2,realm2 = UnitName("party"..i)
  23. if realm2 then name2 = name2 .. "-" .. realm2 end
  24.  
  25. if name2 == name then
  26. destUnit = "party" .. i
  27. break
  28. end
  29. end
  30. elseif UnitName("player") == name then
  31. destUnit = "player"
  32. end
  33. if not destUnit then
  34. return -1 --Failure Flag
  35. end
  36. local hCount = 0
  37. for k,v in ipairs(aura_env.hotList) do
  38. local spellName = GetSpellInfo(v)
  39. if UnitBuff(destUnit, spellName, nil, "PLAYER") then hCount = hCount + 1 end
  40. end
  41. return hCount
  42. end
  43.  
  44. --Debug function
  45. --local function printTables(t1, t2, t3)
  46. -- if not(t1[1]) then
  47. -- print("Empty List")
  48. -- else
  49. -- for i = 1, #t1, 1 do
  50. -- print(t1[i], t2[i], t3[i])
  51. -- end
  52. -- print("print has printed.")
  53. -- end
  54. --end
  55.  
  56. --Inserts a row into a chain of tables.
  57. local function insert(i, t1, t2, t3)
  58. tinsert(WA_RDSW_expire, i, t1)
  59. tinsert(WA_RDSW_guid, i, t2)
  60. tinsert(WA_RDSW_reduce, i, t3)
  61. end
  62.  
  63. --Removes a row into a chain of tables.
  64. local function removet(i, t1, t2, t3)
  65. table.remove(t1, i)
  66. table.remove(t2, i)
  67. table.remove(t3, i)
  68. end
  69.  
  70.  
  71.  
  72. --Function Registers Living Seeds that are the result of a Regrowth crit as to reduced their contribution to crit healing
  73. -- by the percentage of bonus crit that makes up Regrowth's chance to crit. (Crit% - baseCrit% / Crit% + regrowth's passive crit%)
  74. --Living Seeds that are the result of Regrowth crits are stored on 3 tables and timestamped.
  75. --If timeStamp < current time, entry is removed.
  76. --If timeStamp >= current time and target is the current target of the heal,
  77. -- entry is updated (reduction is added to existing total, time stamp is set to new time)
  78. --If table entry is nil, information is inserted.
  79. local function regrowth(guid, heal)
  80. local reduceHeal = heal * 0.5
  81. local i = 1
  82. while(i <= #WA_RDSW_expire + 1) do
  83.  
  84. --if No Record (insert)
  85. if not(WA_RDSW_expire[i])then
  86. insert(i, timeStamp + 15, guid, reduceHeal)
  87. break;
  88. --If Record has not expired
  89. elseif WA_RDSW_expire[i] >= timeStamp then
  90.  
  91. --If Record is of target (update)
  92. if WA_RDSW_guid[i] == guid then
  93. WA_RDSW_expire[i] = timeStamp + 15
  94. WA_RDSW_reduce[i] = WA_RDSW_reduce[i] + reduceHeal
  95. break;
  96. end
  97.  
  98. --If Record is expired (remove)
  99. elseif WA_RDSW_expire[i] < timeStamp then
  100.  
  101. removet(i, WA_RDSW_expire, WA_RDSW_guid, WA_RDSW_reduce)
  102. i = i - 1
  103. end
  104. i = i + 1
  105. end
  106. end
  107.  
  108. --Function is called when an ally is healed by a living seed whose source is the player.
  109. --Function accesses a register of tables. (and removes expired entries) if the target if Living seed is boththe Registers Living Seeds that are the result of a Regrowth crit as to reduced their contribution to crit healing
  110. --by the percentage of bonus crit that makes up Regrowth's chance to crit. (Crit% - baseCrit% / Crit% + regrowth's passive crit%)
  111. local function livingSeed(guid, heal, overHeal, mstPerc, hCount)
  112.  
  113. local statSum = mstPerc + aura_env.vrsPerc
  114. local baseHeal = heal / ((1 + mstPerc) * (1 + aura_env.vrsPerc))
  115. local statHeal = heal - baseHeal
  116. local crtHeal = (baseHeal + 0.5 * statHeal) * ( aura_env.bonusCrt / aura_env.crtPerc) --CONSTANT: 0.5 <- half the contribution of mst and vrs
  117. local mstHeal = aura_env.bonusMst / (mstPerc * 2) * heal * hCount
  118. local vrsHeal = aura_env.bonusVrs / ( aura_env.vrsPerc * 2) * heal
  119. local reduce = 0
  120.  
  121. --Table Management
  122. local i = 1
  123. while(i <= #WA_RDSW_expire + 1) do
  124. --If Record has not expired
  125. if WA_RDSW_expire[i] >= timeStamp then
  126.  
  127. --If Record is of target (read, remove and break loop)
  128. if WA_RDSW_guid[i] == guid then
  129. reduce = WA_RDSW_reduce[i]
  130. removet(i, WA_RDSW_expire, WA_RDSW_guid, WA_RDSW_reduce)
  131. break
  132. end
  133.  
  134. --If Record is expired (remove)
  135. elseif WA_RDSW_expire[i] < timeStamp then
  136. removet(i, WA_RDSW_expire, WA_RDSW_guid, WA_RDSW_reduce)
  137. i = i - 1
  138. end
  139. end
  140.  
  141. reduce = reduce * (1 - aura_env.bonusCrt / ( aura_env.crtPerc + aura_env.regrowthBaseCrt))
  142. local statHealSum = crtHeal + mstHeal + vrsHeal
  143. crtHeal = crtHeal - (crtHeal / statHealSum) * reduce - overHeal
  144. if crtHeal < 0 then crtHeal = 0 end
  145. mstHeal = mstHeal - (mstHeal / statHealSum) * reduce - overHeal
  146. if mstHeal < 0 then mstHeal = 0 end
  147. vrsHeal = vrsHeal - (vrsHeal / statHealSum) * reduce - overHeal
  148. if vrsHeal < 0 then vrsHeal = 0 end
  149. return crtHeal, mstHeal, vrsHeal, 0
  150.  
  151. end
  152.  
  153. --Function finds the lowest non-zero, non-negative value
  154. --Still returns 0 if all arguements are 0.
  155. local function maxButNotZero(n1, n2, n3, n4)
  156. local max = 1
  157. if n1 ~= nil and n1 > max then max = n1 end
  158. if n2 ~= nil and n2 > max then max = n2 end
  159. if n3 ~= nil and n3 > max then max = n3 end
  160. if n4 ~= nil and n4 > max then max = n4 end
  161. return max
  162. end
  163.  
  164.  
  165. --Allocates stat values
  166. local function allocate(mstHeal, hstHeal, crtHeal, vrsHeal)
  167.  
  168. --Total Raw Healing Score Allocation
  169. LEAFUI_TTL_MST_HEAL = LEAFUI_TTL_MST_HEAL + mstHeal
  170. LEAFUI_TTL_HST_HEAL = LEAFUI_TTL_HST_HEAL + hstHeal
  171. LEAFUI_TTL_CRT_HEAL = LEAFUI_TTL_CRT_HEAL + crtHeal
  172. LEAFUI_TTL_VRS_HEAL = LEAFUI_TTL_VRS_HEAL + vrsHeal
  173.  
  174. --Current Encounter Healing Score Allocation
  175. LEAFUI_CUR_MST_HEAL = LEAFUI_CUR_MST_HEAL + mstHeal
  176. LEAFUI_CUR_HST_HEAL = LEAFUI_CUR_HST_HEAL + hstHeal
  177. LEAFUI_CUR_CRT_HEAL = LEAFUI_CUR_CRT_HEAL + crtHeal
  178. LEAFUI_CUR_VRS_HEAL = LEAFUI_CUR_VRS_HEAL + vrsHeal
  179.  
  180. --Stat Value Score Allocation
  181. local mstCurVal
  182. local mstTtlVal
  183. local hstCurVal
  184. local hstTtlVal
  185. local crtCurVal
  186. local crtTtlVal
  187. local vrsCurVal
  188. local vrsTtlVal
  189. if aura_env.mstRating > 0 then
  190. mstCurVal = LEAFUI_CUR_MST_HEAL / aura_env.mstRating
  191. mstTtlVal = LEAFUI_TTL_MST_HEAL / aura_env.mstRating
  192. else
  193. mstCurVal = 0
  194. mstTtlVal = 0
  195. end
  196. if aura_env.hstRating > 0 then
  197. hstCurVal = LEAFUI_CUR_HST_HEAL / aura_env.hstRating
  198. hstTtlVal = LEAFUI_TTL_HST_HEAL / aura_env.hstRating
  199. else
  200. hstCurVal = 0
  201. hstTtlVal = 0
  202. end
  203. if aura_env.crtRating > 0 then
  204. crtCurVal = LEAFUI_CUR_CRT_HEAL / aura_env.crtRating
  205. crtTtlVal = LEAFUI_TTL_CRT_HEAL / aura_env.crtRating
  206. else
  207. crtCurVal = 0
  208. crtTtlVal = 0
  209. end
  210. if aura_env.vrsRating > 0 then
  211. vrsCurVal = LEAFUI_CUR_VRS_HEAL / aura_env.vrsRating
  212. vrsTtlVal = LEAFUI_TTL_VRS_HEAL / aura_env.vrsRating
  213. else
  214. vrsCurVal = 0
  215. vrsTtlVal = 0
  216. end
  217.  
  218. local maxCurHeal = maxButNotZero(mstCurVal, hstCurVal, crtCurVal, vrsCurVal)
  219. local maxTtlHeal = maxButNotZero(mstTtlVal, hstTtlVal, crtTtlVal, vrsTtlVal)
  220.  
  221. if mstCurVal > 0 then
  222. LEAFUI_CUR_MST = mstCurVal / maxCurHeal
  223. end
  224. if hstCurVal > 0 then
  225. LEAFUI_CUR_HST = hstCurVal / maxCurHeal
  226. end
  227. if crtCurVal > 0 then
  228. LEAFUI_CUR_CRT = crtCurVal / maxCurHeal
  229. end
  230. if vrsCurVal > 0 then
  231. LEAFUI_CUR_VRS = vrsCurVal / maxCurHeal
  232. end
  233.  
  234. if mstTtlVal > 0 then
  235. LEAFUI_TTL_MST = mstTtlVal / maxTtlHeal
  236. end
  237. if hstTtlVal > 0 then
  238. LEAFUI_TTL_HST = hstTtlVal / maxTtlHeal
  239. end
  240. if crtTtlVal > 0 then
  241. LEAFUI_TTL_CRT = crtTtlVal / maxTtlHeal
  242. end
  243. if vrsTtlVal > 0 then
  244. LEAFUI_TTL_VRS = vrsTtlVal / maxTtlHeal
  245. end
  246.  
  247. end
  248.  
  249.  
  250.  
  251. --Set and calculates healing and stat weight values
  252. local function decompHeal(heal, overHeal, name, crtFlag, hstFlag, sName, sklFlag, tGuid)
  253.  
  254. local hCount = hotCounter(name)
  255. local mstPerc = aura_env.mstPerc * hCount
  256.  
  257. local hstPerc --Local hstPerc is only applied on hots.
  258. if hstFlag then
  259. hstPerc = aura_env.hstPerc
  260. else hstPerc = 0
  261. end
  262.  
  263. local crtBonus --Local CrtBonus only applies on Crits.
  264. if crtFlag == true then
  265. crtBonus = 1 + aura_env.taurenRacial
  266. else crtBonus = 0
  267. end
  268.  
  269. --Heal Calculation
  270. local baseHeal
  271. local baseHeal = heal / ( (1 + mstPerc) * (1 + aura_env.hstPerc) * (1 + aura_env.crtPerc) * (1 + aura_env.vrsPerc) )
  272. local statHeal = heal - baseHeal - overHeal
  273. local statSum = mstPerc + aura_env.hstPerc + crtBonus + aura_env.vrsPerc
  274. local baseHeal = heal / ( (1 + mstPerc) * (1 + aura_env.hstPerc) * (1 + crtBonus) * (1 + aura_env.vrsPerc) )
  275. local statHeal = heal - baseHeal - overHeal
  276. local statSum = mstPerc + aura_env.hstPerc + crtBonus + aura_env.vrsPerc
  277. local mstHeal
  278. local hstHeal
  279. local vrsHeal
  280. local crtHeal
  281. if statHeal > 0 and statSum > 0 and heal > baseHeal then --Cut out redundant computations if overheal exceeds healing from all secondary stats combined.
  282.  
  283. --If Heal is Living Seed
  284. if sklFlag == 2 then
  285. crtHeal, mstHeal, vrsHeal, hstHeal = livingSeed(tGuid, heal, overHeal, mstPerc, hCount)
  286. else
  287. mstHeal = aura_env.bonusMst * hCount / statSum * statHeal
  288. hstHeal = aura_env.bonusHst / statSum * statHeal
  289. vrsHeal = aura_env.bonusVrs / statSum * statHeal
  290. --if heal is not a crit
  291. if not(crtFlag) then
  292. crtHeal = 0
  293. elseif sklFlag == 1 then --if heal is a crit
  294. regrowth(tGuid, heal)
  295. --Unique calc for Regrowth Crit
  296. crtHeal = ( aura_env.bonusCrt / ( aura_env.crtPerc + aura_env.regrowthBaseCrt)) * ( crtBonus / statSum) * statHeal
  297. else
  298. --All non-conditional crit that is successfully applied.
  299.  
  300. crtHeal = ( aura_env.bonusCrt / aura_env.crtPerc) * ( crtBonus / statSum) * statHeal
  301. end
  302.  
  303. end
  304. else
  305. mstHeal = 0
  306. hstHeal = 0
  307. crtHeal = 0
  308. vrsHeal = 0
  309. end
  310.  
  311. allocate(mstHeal, hstHeal, crtHeal, vrsHeal)
  312. end
  313.  
  314. --Debug function
  315. --local function printSavedTable(t)
  316. -- print(t[1])
  317. -- if not(t[1]) then
  318. -- print("Empty List")
  319. -- else
  320. -- for i = 1, #t, 1 do
  321. -- print(t[i])
  322. -- end
  323. -- print("Saved print has printed.")
  324. -- end
  325. --end
  326.  
  327. --Sets Encounter data to be printed to file.
  328. --Para mode: sets print out to stat either "WIPE" if mode - 0 or "KILL" if mode = 1
  329. local function printToFile(eID, eName, difficulty, raidSize, mode)
  330. local outcome
  331. if mode == 0 or mode == 1 then
  332. if mode == 0 then outcome = "WIPE"
  333. elseif mode == 1 then outcome = "KILL"
  334. end
  335.  
  336. local outString = "ENCOUNTER: %s eID: %d "
  337. .. "Time: %s "
  338. .. "Player: %s"
  339. .. "Difficulty: %d raidSize: %d "
  340. .. "Outcome: %s "
  341. .. "+_"
  342. .. "MST: %.4f "
  343. .. "HST: %.4f "
  344. .. "CRT: %.4f "
  345. .. "VRS: %.4f "
  346. .. "_+"
  347. .. "MST_H: %.2f "
  348. .. "HST_H: %.2f "
  349. .. "CRT_H: %.2f "
  350. .. "VRS_H: %.2f "
  351.  
  352.  
  353. tinsert(Leaf_RDSW, format(outString,
  354. eName,
  355. eID,
  356. aura_env.time,
  357. UnitName("player"),
  358. difficulty,
  359. raidSize,
  360. outcome,
  361. LEAFUI_CUR_MST,
  362. LEAFUI_CUR_HST,
  363. LEAFUI_CUR_CRT,
  364. LEAFUI_CUR_VRS,
  365. LEAFUI_CUR_MST_HEAL,
  366. LEAFUI_CUR_HST_HEAL,
  367. LEAFUI_CUR_CRT_HEAL,
  368. LEAFUI_CUR_VRS_HEAL))
  369. end
  370. end
  371.  
  372. --Clears the current healing and stat values
  373. local function clearStats()
  374. LEAFUI_CUR_MST = 0
  375. LEAFUI_CUR_HST = 0
  376. LEAFUI_CUR_CRT = 0
  377. LEAFUI_CUR_VRS = 0
  378. LEAFUI_CUR_MST_HEAL = 0
  379. LEAFUI_CUR_HST_HEAL = 0
  380. LEAFUI_CUR_CRT_HEAL = 0
  381. LEAFUI_CUR_VRS_HEAL = 0
  382. end
  383.  
  384. --MAIN--
  385. if e == "UNIT_STATS" or e == "COMBAT_RATING_UPDATE" then
  386. aura_env.mstRating = GetCombatRating(CR_MASTERY)
  387. aura_env.hstRating = GetCombatRating(CR_HASTE_SPELL)
  388. aura_env.crtRating = GetCombatRating(CR_CRIT_SPELL)
  389. aura_env.vrsRating = GetCombatRating(CR_VERSATILITY_DAMAGE_DONE)
  390.  
  391. aura_env.bonusMst = aura_env.mstRating / aura_env.mstRatingConv / 100
  392. aura_env.bonusHst = aura_env.hstRating / aura_env.hstRatingConv / 100
  393. aura_env.bonusCrt = aura_env.crtRating / aura_env.crtRatingConv / 100
  394. aura_env.bonusVrs = aura_env.vrsRating / aura_env.vrsRatingConv / 100
  395.  
  396. aura_env.mstPerc = GetMasteryEffect() / 100--GetCombatRatingBonus(26) / 100 * hCount
  397. aura_env.hstPerc = UnitSpellHaste("player") / 100
  398. aura_env.crtPerc = GetCritChance() / 100
  399. aura_env.vrsPerc = (GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE)) / 100
  400. return true
  401. end
  402.  
  403. if e == "ENCOUNTER_START" then
  404. print("Boss Encounter has begun. Recording")
  405. aura_env.time = date("%m/%d/%y %H:%M:%S")
  406. aura_env.encounter = true
  407. clearStats()
  408.  
  409. elseif e == "ENCOUNTER_END" then
  410. print("Boss Encounter has Ended. Recording to file.")
  411. printToFile(...)
  412. aura_env.encounter = false
  413.  
  414. elseif e == "COMBAT_LOG_EVENT_UNFILTERED" then
  415.  
  416. local heal, overHeal, crtFlag, effHeal, sName, hstFlag, sklFlag, tGuid
  417. sklFlag = 0
  418. type = select(2, ...)
  419. if select(4, ...) == UnitGUID("player") then
  420. --Hot Spells (haste effected)
  421. sName = select(13,...)
  422. if type == "SPELL_PERIODIC_HEAL" then
  423. if sName == aura_env.spells.rejuvenation
  424. or sName == aura_env.spells.germination
  425. or sName == aura_env.spells.lifebloom
  426. or sName == aura_env.spells.regrowth
  427. or sName == aura_env.spells.wildgrowth
  428. or sName == aura_env.spells.springblossoms
  429. or sName == aura_env.spells.cultivation
  430. or sName == aura_env.spells.cenarionward
  431. then hstFlag = true end
  432. --Direct Healing Spells (Mostly not Haste Effected)
  433.  
  434. elseif type == "SPELL_HEAL" then
  435. sName,_= select(13,...)
  436. if sName == aura_env.spells.efflorescence then hstFlag = true
  437.  
  438. elseif sName == aura_env.spells.regrowth then
  439. sklFlag = 1
  440. hstFlag = false
  441.  
  442. elseif sName == aura_env.spells.livingseed then
  443. sklFlag = 2
  444. hstFlag = false
  445.  
  446. elseif sName == aura_env.spells.swiftmend
  447. or sName == aura_env.spells.healingtouch
  448. or sName == aura_env.spells.lifebloom
  449. or sName == aura_env.spells.tranquility
  450. or sName == aura_env.spells.renewal
  451. then hstFlag = false end
  452. end
  453.  
  454. if hstFlag ~= nil then --If hstFlag == nil, healing was not done by a spell in the above listing. ie: Ysera's gift is uneffected by secondaries
  455. tGuid, name,_= select(8,...)
  456. heal,overHeal,_,crtFlag,_ = select(15,...)
  457. decompHeal(heal, overHeal, name, crtFlag, hstFlag, sName, sklFlag, tGuid)
  458. end
  459. end
  460. WeakAuras.ScanEvents("LEAFUI_RDSW_UPDATE")
  461. end
  462. return true
  463. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement