Skip to content

Instantly share code, notes, and snippets.

@Resike
Created December 21, 2014 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Resike/a686a332998618c755ec to your computer and use it in GitHub Desktop.
Save Resike/a686a332998618c755ec to your computer and use it in GitHub Desktop.
Index: RecountMitigation.lua
===================================================================
--- RecountMitigation.lua (revision 26)
+++ RecountMitigation.lua (working copy)
@@ -12,15 +12,16 @@
local pairs = pairs
local math = math
-local UnitBuff = UnitBuff
-local UnitArmor = UnitArmor
+local GetCombatRatingBonus = GetCombatRatingBonus
local GetMastery = GetMastery
local GetSpellInfo = GetSpellInfo
-local UnitLevel = UnitLevel
local GetTime = GetTime
+local IsTalentSpell = IsTalentSpell
+local UnitArmor = UnitArmor
+local UnitBuff = UnitBuff
local UnitIsUnit = UnitIsUnit
+local UnitLevel = UnitLevel
local UnitName = UnitName
-local GetCombatRatingBonus = GetCombatRatingBonus
local GameTooltip = GameTooltip
@@ -40,7 +41,7 @@
local MAGICAL = 2
local ALL = 3
-local mAbsorbs = {
+--[[local mAbsorbs = {
[116631] = function() local _,_,_,_,_,_,_,_,_,_,_,_,_,_,v,_ = UnitBuff("player", "Colossus") return (v), nil end,
[77535] = function() local _,_,_,_,_,_,_,_,_,_,_,_,_,_,v,_ = UnitBuff("player", "Blood Shield") return (v), true end, --Physical Only (true)
[65148] = function() local _,_,_,_,_,_,_,_,_,_,_,_,_,_,v,_ = UnitBuff("player", "Sacred Shield") return (v), nil end,
@@ -56,7 +57,7 @@
[115295] = function() local _,_,_,_,_,_,_,_,_,_,_,_,_,_,v,_ = UnitBuff("player", "Guard") return (v), nil end,
[135286] = function() local _,_,_,_,_,_,_,_,_,_,_,_,_,_,v,_ = UnitBuff("player", "Tooth and Claw") return (v), true end, --Physical Only (true)
}
-local mLeft = {}
+local mLeft = {}]]
-- look at combining HTD events as they will be the only ones with times instead of nil. must add check when nessessary below
-- (value, school, type, customDuration)
@@ -74,7 +75,7 @@
--gem1, gem2, gem3 = GetInventoryItemGems(slot)
local gtK = {
-[0] = 5234,-- Default Level 103 as boss fights are most important
+[0] = 5234, -- Default Level 103 as boss fights are most important
[1] = 157,
[2] = 167,
[3] = 177,
@@ -183,11 +184,37 @@
[106] = 7587,
[107] = 8587,
[108] = 9718
-};
+}
+
+-- Also need to handle talent learned/removed events, and to check player buffs after logging in.
local mBuffs = {
- [71] = function() return (0.25), ALL, nil end, -- Defensive Stance (Unconfirmed)
- [871] = function() return (0.40), ALL, nil end, -- Shield Wall (Unconfirmed)
+ [71] = function()
+ local spellName = GetSpellInfo(152276)
+ local talent = IsTalentSpell(spellName)
+ local reduceDamage
+ if talent then
+ reduceDamage = 0.25
+ else
+ reduceDamage = 0.20
+ end
+ return (reduceDamage), ALL, nil
+ end, -- Defensive Stance
+ [871] = function()
+ local glyphed
+ for i = 1, GetNumGlyphSockets() do
+ local enabled, glyphType, glyphTooltipIndex, glyphSpellID, icon = GetGlyphSocketInfo(i)
+ if glyphSpellID == 63329 then
+ glyphed = true
+ break
+ end
+ end
+ if glyphed then
+ return 0.60, ALL, nil
+ else
+ return 0.40, ALL, nil
+ end
+ end, -- Shield Wall
[14771] = function() return (0.06), ALL, nil end, -- Glyph of Inner Sanctum (Unconfirmed)
[15473] = function() return (0.15), ALL, nil end, -- Shadowform (Unconfirmed)
[22812] = function() return (0.20), ALL, nil end, -- Barkskin (Unconfirmed)
@@ -213,13 +240,21 @@
[86659] = function() return (0.50), ALL, 8 end, -- Guardian of Ancient Kings -- maybe monitor buff instead
[30482] = function() return (0.06), PHYSICAL, nil end, -- Molten Armor (Unconfirmed)
[63269] = function() return (0.40), PHYSICAL, nil end, -- Glyph of Cloak of Shadows (Unconfirmed)
- [132403] = function() return (0.25 + (GetMastery()/200)), PHYSICAL, nil end, -- Shield of the Righteous
+ [132403] = function() return (0.25 + (GetMastery() / 200)), PHYSICAL, nil end, -- Shield of the Righteous
[137593] = function() return (0.20), ALL, nil end, -- Indomitable Primal Diamond (Meta Gem, Unconfirmed)
- [999998] = function() return (GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_TAKEN)/100), ALL, nil end, -- Versatility
+ [999998] = function()
+ return (GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_TAKEN) / 100), ALL, nil
+ end, -- Versatility
[999999] = function(l)
- local lvl
- if type(l) ~= "number" then lvl = 0 else lvl = l end
- return (UnitArmor("player")/(UnitArmor("player") + gtK[lvl] )), PHYSICAL, false end, -- Armor
+ local lvl
+ if type(l) ~= "number" or l == -1 then
+ lvl = 0
+ else
+ lvl = l
+ end
+ local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player")
+ return effectiveArmor / (effectiveArmor + gtK[lvl]), PHYSICAL, false
+ end, -- Armor
[498] = function() return (0.40), MAGICAL, nil end, -- Divine Protection
[31821] = function() return (0.20), MAGICAL, nil end, -- Devotion Aura
[48707] = function() return (0.75), MAGICAL, nil end, -- Anti-Magic Shell (Unconfirmed)
@@ -227,10 +262,10 @@
}
-local mBuffRemoveHTD = {}
+local mBuffRemoveHTD = { }
-local DetailTitles={}
-DetailTitles.DamageMitigation={
+local DetailTitles = { }
+DetailTitles.DamageMitigation = {
TopNames = RL["Ability Name"],
TopCount = RL["Count"],
TopAmount = RL["Damage"],
@@ -240,11 +275,11 @@
BotMax = RL["Max"],
BotAmount = RL["Count"]
}
-DetailTitles.DamageReducedBy={
+DetailTitles.DamageReducedBy = {
TopNames = RL["Ability Name"],
TopCount = RL["Count"],
TopAmount = RL["Damage"],
- BotNames = RL["Player/Mob Name"],
+ BotNames = L["Protected"],
BotMin = RL["Min"],
BotAvg = RL["Avg"],
BotMax = RL["Max"],
@@ -251,22 +286,27 @@
BotAmount = RL["Count"]
}
-local mActive={}
-local Epsilon=0.000000000000000001
-local math_floor = math.floor
+local mActive = { }
+local Epsilon = 0.000000000000000001
+
function RecountMitigation:Round100(num)
- return math_floor((num * 100) + 0.5) / 100
+ return math.floor((num * 100) + 0.5) / 100
end
+
function RecountMitigation:OnInitialize()
+
end
+
function RecountMitigation:OnEnable()
- if not Recount then return end
+ if not Recount then
+ return
+ end
RecountMitigation:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED", "CombatLogEvent")
RecountMitigation:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED", "mEventHTD")
local _
- RecountMitigation:mBuffApplied(GetTime(), _, _, "player", _, _, "player", _, 999998, "Versatility")--apply armor to player as a buff
- RecountMitigation:mBuffApplied(GetTime(), _, _, "player", _, _, "player", _, 999999, "Armor")--apply armor to player as a buff
- --need to apply meta gem to player as a buff here and also add/remove when changing helmet
+ RecountMitigation:mBuffApplied(GetTime(), _, _, "player", _, _, "player", _, 999998, "Versatility") -- Apply Versatility to player as a buff
+ RecountMitigation:mBuffApplied(GetTime(), _, _, "player", _, _, "player", _, 999999, "Armor") -- Apply Armor to player as a buff
+ -- Need to apply meta gem to player as a buff here and also add/remove when changing helmet
end
function RecountMitigation:OnDisable()
RecountMitigation:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
@@ -319,9 +359,15 @@
-- --
----------------------------------------------------------------------
function RecountMitigation:mBuffApplied(timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, spellId, spellName, spellSchool, auraType, amount)
- if not mBuffs[spellId] and not mAbsorbs[spellId] then return end
- if UnitIsUnit(dstName, "player") then dstName = UnitName("player") end
- if UnitIsUnit(srcName, "player") then srcName = UnitName("player") end
+ if not mBuffs[spellId] --[=[and not mAbsorbs[spellId]]=] then
+ return
+ end
+ if UnitIsUnit(dstName, "player") then
+ dstName = UnitName("player")
+ end
+ if UnitIsUnit(srcName, "player") then
+ srcName = UnitName("player")
+ end
if mBuffs[spellId] then --FIX
if ({mBuffs[spellId]()}) [3] then --If custom duration (HTD)
@@ -342,9 +388,9 @@
end
--print("Mitigation Buff: ", spellName, "[", spellId, "] applied")
mActive[dstName][spellId] = timestamp
- if mAbsorbs[spellId] then
+ --[[if mAbsorbs[spellId] then
mLeft[spellId] = (mAbsorbs[spellId]())
- end
+ end]]
end
----------------------------------------------------------------------
-- --
@@ -352,7 +398,9 @@
-- --
----------------------------------------------------------------------
function RecountMitigation:mBuffRemoved(timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, spellId, spellName, spellSchool, auraType, amount)
- if not mBuffs[spellId] and not mBuffRemoveHTD[timestamp] and not mAbsorbs[spellId] then return end
+ if not mBuffs[spellId] and not mBuffRemoveHTD[timestamp] --[=[and not mAbsorbs[spellId]]=] then
+ return
+ end
if mBuffRemoveHTD[timestamp] then
dstName = mBuffRemoveHTD[timestamp]["dstName"]
spellId = timestamp
@@ -359,11 +407,38 @@
mBuffRemoveHTD[spellId] = nil
end
local dstDRBuffs = mActive[dstName]
- if not dstDRBuffs or not dstDRBuffs[spellId] then return end
+ if not dstDRBuffs or not dstDRBuffs[spellId] then
+ return
+ end
--print("Mitigation Buff: ", spellName, "[", spellId, "] removed")
mActive[dstName][spellId] = nil
end
+function RecountMitigation:mSpellAbsorbed(...)
+ local _, _, _, _, _, _, _, _, srcSpellId = ...
+ if type(srcSpellId) == "number" then
+ local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, srcSpellId, srcSpellName, srcSpellSchool, casterGUID, casterName, casterFlags, casterRaidFlags, spellId, spellName, spellSchool, absorbed = ...
+ if dstGUID ~= casterGUID then
+ return
+ end
+ -- Stance of the Sturdy Ox, Purgatory
+ if spellId == 115069 or spellId == 114556 then
+ return
+ end
+ RecountMitigation:AddDM("Absorbed", absorbed, spellName, dstName)
+ else
+ local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, casterGUID, casterName, casterFlags, casterRaidFlags, spellId, spellName, spellSchool, absorbed = ...
+ if dstGUID ~= casterGUID then
+ return
+ end
+ -- Stance of the Sturdy Ox, Purgatory
+ if spellId == 115069 or spellId == 114556 then
+ return
+ end
+ RecountMitigation:AddDM("Absorbed", absorbed, spellName, dstName)
+ end
+end
+
local mEvent =
{
["SWING_DAMAGE"] = RecountMitigation.MeleeDamage,
@@ -380,6 +455,7 @@
["SPELL_AURA_APPLIED"] = RecountMitigation.mBuffApplied,
["SPELL_AURA_REFRESH"] = RecountMitigation.mBuffApplied,
["SPELL_AURA_REMOVED"] = RecountMitigation.mBuffRemoved,
+ ["SPELL_ABSORBED"] = RecountMitigation.mSpellAbsorbed,
}
local mEventList
@@ -389,10 +465,22 @@
-- --
----------------------------------------------------------------------
function RecountMitigation:CombatLogEvent(_,timestamp, eventtype, hideCaster, srcGUID, srcName, srcFlags, srcRaidFlags, dstGUID, dstName, dstFlags, dstRaidFlags, ...)
- if dstName and UnitIsUnit(dstName, "player") then dstName = UnitName("player") else return end
- if not Recount.db.profile.GlobalDataCollect or not Recount.CurrentDataCollect then return end
- if not Recount:CheckRetentionFromFlags(srcFlags) and not Recount:CheckRetentionFromFlags(dstFlags) then return end
- if srcName then Recount:MatchGUID(srcName, srcGUID, srcFlags) else srcName = "No One" end
+ if dstName and UnitIsUnit(dstName, "player") then
+ dstName = UnitName("player")
+ else
+ return
+ end
+ if not Recount.db.profile.GlobalDataCollect or not Recount.CurrentDataCollect then
+ return
+ end
+ if not Recount:CheckRetentionFromFlags(srcFlags) and not Recount:CheckRetentionFromFlags(dstFlags) then
+ return
+ end
+ if srcName then
+ Recount:MatchGUID(srcName, srcGUID, srcFlags)
+ else
+ srcName = "No One"
+ end
--UnitGUID("unit")==destGUID then local hostilelevel=UnitLevel("unit") end
@@ -407,9 +495,17 @@
-- --
----------------------------------------------------------------------
function RecountMitigation:mEventHTD(eventtype, unitId, spellName, rank, lineId, spellId, timestamp)
- if unitId and UnitIsUnit(unitId, "player") then unitId = UnitName("player") else return end
- if not mBuffs[spellId] then return end
- if not ({mBuffs[spellId]()}) [3] then return end
+ if unitId and UnitIsUnit(unitId, "player") then
+ unitId = UnitName("player")
+ else
+ return
+ end
+ if not mBuffs[spellId] then
+ return
+ end
+ if not ({mBuffs[spellId]()}) [3] then
+ return
+ end
local _
RecountMitigation:mBuffApplied(GetTime(), eventtype, _, unitId, _, _, unitId, _, spellId, spellName)
end
@@ -418,9 +514,13 @@
-- FUNCTION : CALCULATE DAMAGE MITIGATION --
-- --
----------------------------------------------------------------------
-function RecountMitigation:CalDM(source, victim, spellName, spellSchool, damage, spellId, timestamp, absorbed, blocked, resisted, srcGUID)
- if UnitIsUnit(victim, "player") then victim = UnitName("player") end
- if UnitIsUnit(source, "player") then source = UnitName("player") end
+function RecountMitigation:CalDM(source, victim, spellName, spellSchool, damage, spellId, timestamp, absorbed, blocked, resisted, srcGUID, ...)
+ if UnitIsUnit(victim, "player") then
+ victim = UnitName("player")
+ end
+ if UnitIsUnit(source, "player") then
+ source = UnitName("player")
+ end
if spellName == nil then
print("spellName Unknown - spellId: ", spellId)
spellName = "Unknown"
@@ -428,13 +528,17 @@
--------------
-- BLOCKED --
--------------
- if blocked ~= nil then
- RecountMitigation:AddDM("Blocked", blocked, "Blocked", victim)
+ if blocked then
+ if blocked > damage * 0.55 then
+ RecountMitigation:AddDM("Blocked", blocked, "Blocked (Critical)", victim)
+ else
+ RecountMitigation:AddDM("Blocked", blocked, "Blocked", victim)
+ end
end
--------------
-- ABSORBED --
--------------
- if absorbed ~= nil then
+ --[[if absorbed ~= nil then
local mAbsorbed = absorbed
for mAbsorbId, mAbsorb in pairs(mAbsorbs) do
if mAbsorbs[mAbsorbId] then --Fix
@@ -469,7 +573,7 @@
RecountMitigation:AddDM("Absorbed", mAbsorbed, "Absorbed", victim)
mAbsorbed = 0
end
- end
+ end]]
--------------
-- RESISTED --
--------------
@@ -480,8 +584,12 @@
-- DAMAGE MITIGATION BUFF --
----------------------------
local dstDRBuffs = mActive[victim]
- if not dstDRBuffs then return end
- if damage <= 0 and ((absorbed or 0) + (blocked or 0) + (resisted or 0)) <= 0 then return end
+ if not dstDRBuffs then
+ return
+ end
+ if damage <= 0 and ((absorbed or 0) + (blocked or 0) + (resisted or 0)) <= 0 then
+ return
+ end
local mPhysical = 0
local mMagical = 0
local mPhysicalTotal = 0
@@ -490,11 +598,11 @@
if dmBuffed then
if mBuffs[mSpellId] then --Fix
if ({mBuffs[mSpellId]()}) [2] == PHYSICAL or ({mBuffs[mSpellId]()}) [2] == ALL then
- mPhysical = 1 - ((1-mPhysical)*(1-(mBuffs[mSpellId](UnitLevel("target")))))
+ mPhysical = 1 - ((1 - mPhysical) * (1 - (mBuffs[mSpellId](UnitLevel("target")))))
mPhysicalTotal = mPhysicalTotal + (mBuffs[mSpellId](UnitLevel("target")))
end
if ({mBuffs[mSpellId]()}) [2] == MAGICAL or ({mBuffs[mSpellId]()}) [2] == ALL then
- mMagical = 1 - ((1-mMagical)*(1-(mBuffs[mSpellId]())))
+ mMagical = 1 - ((1 - mMagical) * (1 - (mBuffs[mSpellId]())))
mMagicalTotal = mMagicalTotal + (mBuffs[mSpellId]())
end
end
@@ -510,7 +618,7 @@
damage = ((absorbed or 0) + (blocked or 0) + (resisted or 0))
end
if mBuffs[mSpellId] then
- mAmount = math_floor((((math.ceil(damage/(1-mPhysical))*mPhysical) / mPhysicalTotal)*((mBuffs[mSpellId](UnitLevel("target")))))+0.5+Epsilon)
+ mAmount = math.floor((((math.ceil(damage / (1 - mPhysical)) * mPhysical) / mPhysicalTotal) * ((mBuffs[mSpellId](UnitLevel("target"))))) + 0.5 + Epsilon)
end
end
if spellSchool ~= SPELLSCHOOL_PHYSICAL and (({mBuffs[mSpellId]()}) [2] == MAGICAL or ({mBuffs[mSpellId]()}) [2] == ALL) then
@@ -518,7 +626,7 @@
damage = ((absorbed or 0) + (blocked or 0) + (resisted or 0))
end
if mBuffs[mSpellId] then
- mAmount = math_floor((((math.ceil(damage/(1-mMagical))*mMagical) / mMagicalTotal)*((mBuffs[mSpellId]())))+0.5+Epsilon)
+ mAmount = math.floor((((math.ceil(damage / (1 - mMagical)) * mMagical) / mMagicalTotal) * ((mBuffs[mSpellId]()))) + 0.5 + Epsilon)
end
end
if mAmount > 0 then
@@ -529,10 +637,7 @@
if mSpellId == 999998 then
mSpellName = "Versatility"
end
- --if mAmount > 200000 then
- -- print("Error? mAmount: ", mAmount, " OrgHit: ")
- --end
- RecountMitigation:AddDM(spellName, mAmount, mSpellName, victim)
+ RecountMitigation:AddDM(mSpellName, mAmount, mSpellName, victim)
end
end --Fix
end --Fix
@@ -553,13 +658,16 @@
end
function RecountMitigation:DataModesDamageMitigation(data, num)
- if not data then return 0, 0 end
+ if not data then
+ return 0, 0
+ end
if num == 1 then
- return RecountMitigation:Round100((data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0), (data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0)/((data.Fights[Recount.db.profile.CurDataSet].ActiveTime or 0) + Epsilon))
+ return RecountMitigation:Round100((data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0), (data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0) / ((data.Fights[Recount.db.profile.CurDataSet].ActiveTime or 0) + Epsilon))
else
- return (data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0), {{data.Fights[Recount.db.profile.CurDataSet].DamageReducedBy, " "..L["'s Damage Mitigation Abilities"], DetailTitles.DamageReducedBy}, {data.Fights[Recount.db.profile.CurDataSet].DamageMitigation, L["'s Damage Mitigation"], DetailTitles.DamageMitigation}}
+ return (data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0), {{data.Fights[Recount.db.profile.CurDataSet].DamageMitigation, L["'s Damage Mitigation"], DetailTitles.DamageMitigation}, {data.Fights[Recount.db.profile.CurDataSet].DamageReducedBy, L["'s Damage Mitigation Abilities"], DetailTitles.DamageReducedBy}}
end
end
+
----------------------------------------------------------------------
-- --
-- FUNCTION : DAMAGE MITIGATION TOOLTIP --
@@ -578,7 +686,7 @@
tBreakdown[L["Damage Mitigated"]] = {}
tBreakdown[L["Damage Taken"]]["amount"] = (data.Fights[Recount.db.profile.CurDataSet].DamageTaken or 0)
tBreakdown[L["Damage Mitigated"]]["amount"] = (data.Fights[Recount.db.profile.CurDataSet].TotalDamageMitigation or 0)
- Recount:AddSortedTooltipData(L["of Incoming Damage"], tBreakdown,2)
+ Recount:AddSortedTooltipData(L["Incoming Damage"], tBreakdown,2)
GameTooltip:AddLine("")
local tSelfHeals = {}
tSelfHeals[L["Damage Self Healed"]] = {}
@@ -589,10 +697,10 @@
end
tSelfHeals[L["Damage Self Healed"]]["amount"] = (SelfHeals or 0) - (data.Fights[Recount.db.profile.CurDataSet].Absorbs or 0)
tSelfHeals[L["Damage Not Actioned"]]["amount"] = (data.Fights[Recount.db.profile.CurDataSet].DamageTaken or 0) - ((SelfHeals or 0) - (data.Fights[Recount.db.profile.CurDataSet].Absorbs or 0))
- Recount:AddSortedTooltipData(L["of Damage Taken"], tSelfHeals,2)
+ Recount:AddSortedTooltipData(L["Damage Taken"], tSelfHeals,2)
GameTooltip:AddLine("")
- Recount:AddSortedTooltipData(L["of Damage Mitigated (Top 3)"], data and data.Fights[Recount.db.profile.CurDataSet] and data.Fights[Recount.db.profile.CurDataSet].DamageReducedBy, 3)
- GameTooltip:AddLine("<"..RL["Click for more Details"]..">",0,0.9,0)
+ Recount:AddSortedTooltipData(L["Top 3 Mitigation"], data and data.Fights[Recount.db.profile.CurDataSet] and data.Fights[Recount.db.profile.CurDataSet].DamageMitigation, 3)
+ GameTooltip:AddLine("<"..RL["Click for more Details"]..">", 0, 0.9, 0)
end
-Recount:AddModeTooltip(L["Damage Mitigation"], RecountMitigation.DataModesDamageMitigation, RecountMitigation.TooltipFuncsDamageMitigation, nil,nil,nil,nil)
\ No newline at end of file
+Recount:AddModeTooltip(L["Damage Mitigation"], RecountMitigation.DataModesDamageMitigation, RecountMitigation.TooltipFuncsDamageMitigation, nil, nil, nil, nil)
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment