--COMBAT_LOG_EVENT_UNFILTERED
function(...)
    local se = select(3, ...)
    if se == "SWING_DAMAGE" then
        local dest = select(10, ...)
        if dest == UnitName("player") then
            local bloq = select(17, ...)
            if bloq then
                aura_env.dmgbloq = aura_env.dmgbloq + bloq
                aura_env.numbloq = aura_env.numbloq + 1
                aura_env.region.blocks:SetText(aura_env.numbloq)
                aura_env.region.damag:SetText(aura_env.color(aura_env.dmgbloq) .. aura_env.shorten(aura_env.dmgbloq))
            end
        end
    elseif se == "SPELL_DAMAGE" then
        local dest = select(10, ...)
        if dest == UnitName("player") then
            local bloq = select(20, ...)
            if bloq then
                aura_env.dmgbloq = aura_env.dmgbloq + bloq
                aura_env.numbloq = aura_env.numbloq + 1
                aura_env.region.blocks:SetText(aura_env.numbloq)
                aura_env.region.damag:SetText(aura_env.color(aura_env.dmgbloq) .. aura_env.shorten(aura_env.dmgbloq))
            end
        end
    elseif se == "SPELL_AURA_APPLIED" then
        local dest = select(6, ...)
        if dest == UnitName("player") then
            local name = select(14, ...)
            if name == "Shield Block" or name == "Last Stand" then
                aura_env.numbloq = 0
                aura_env.dmgbloq = 0
                aura_env.region.blocks:SetText(aura_env.numbloq)
                aura_env.region.damag:SetText(aura_env.color(aura_env.dmgbloq) .. aura_env.shorten(aura_env.dmgbloq))
            end
        end
    end
end

--INIT
aura_env.numbloq = 0
aura_env.dmgbloq = 0
aura_env.color = function(damag)
    local damagcolor = "|cFFFFFFFF"
    if damag <= 0.25 * UnitHealth("player") then damagcolor = "|cFFFF0000"
    elseif damag > 0.25 * UnitHealth("player") and damag <= 0.5 * UnitHealth("player") then damagcolor = "|cFFFF8000"
    elseif damag > 0.5 * UnitHealth("player") and damag <= 0.75 * UnitHealth("player") then damagcolor = "|cFF00FF00"
    elseif damag > 0.75 * UnitHealth("player") and damag <= UnitHealth("player") then damagcolor = "|cFF00FFFF"
    elseif damag > UnitHealth("player") and damag <= 1.33 * UnitHealth("player") then damagcolor = "|cFFFF00FF"
    elseif damag > 1.33 * UnitHealth("player") and damag <= 1.66 * UnitHealth("player") then damagcolor = "|cFFFFFF00"
    elseif damag > 1.66 * UnitHealth("player") then damagcolor = "|c" end
    return damagcolor
end
local fontsize = 32
if not aura_env.region.blocks then
    local text = aura_env.region:CreateFontString(nil, aura_env.region)
    aura_env.region.blocks = text
    print("ok!")
end
aura_env.region.blocks:SetFont("Interface\\AddOns\\SharedMedia_MyMedia\\font\\FiraCode-Bold.ttf", fontsize, "OUTLINE")
aura_env.region.blocks:SetTextColor(1,1,1,1)
aura_env.region.blocks:SetPoint("CENTER", aura_env.region, "CENTER")
aura_env.region.blocks:SetJustifyH("LEFT")
aura_env.region.blocks:SetText("0")
aura_env.region.blocks:Show()

if not aura_env.region.damag then
    local text = aura_env.region:CreateFontString(nil, aura_env.region)
    aura_env.region.damag = text
    print("ok!")
end
aura_env.region.damag:SetFont("Interface\\AddOns\\SharedMedia_MyMedia\\font\\FiraCode-Bold.ttf", 16, "OUTLINE")
aura_env.region.damag:SetTextColor(1,1,1,1)
aura_env.region.damag:SetPoint("CENTER", aura_env.region, "CENTER", 0, -32)
aura_env.region.damag:SetJustifyH("LEFT")
aura_env.region.damag:SetText("0")
aura_env.region.damag:Show()

aura_env.shorten = function(val)
    local function round(var, n)
        if (n) then
            var = math.floor((var * 10^n) + 0.5) / (10^n)
        else
            var = math.floor(var+0.5)
        end
        return var
    end
    local n = 2
    if val <= 1e3 then
        return round(val, n)
    elseif val > 1e3 and val < 1e6 then
        return round(val / 1e3, n) .. "k"
    elseif val > 1e6 and val < 1e9 then
        return round(val / 1e6, n) .. "M"
    elseif val > 1e9 then
        return round(val / 1e9, n) .. "G"
    end
end
aura_env.auraID = function(spell)
    for i = 1, 40 do
        local name = UnitBuff("player", i)
        if name then
            if name == spell then
                return i
            end
        else
            break
        end
    end
end