--GET MAX SHIELD ABSORB AND BAR FOR ABSORB
TRIGGER
function()
    local buff = UnitBuff("player", "Bulwark of Order") or ""
    if buff ~= "" then return true else return false end
end

DURATION
function()
    local shieldAmount = select(17, UnitBuff("player", "Bulwark of Order"))
    if shieldAmount > aura_env.maxShield then
        aura_env.maxShield = shieldAmount
    end
    return shieldAmount, aura_env.maxShield, 1
end

DISPLAY
function()
    local shield = select(17, UnitBuff("player", "Bulwark of Order")) or 0
    return math.floor(shield / 1000) .. "k"
end

ANIMATION
function()
    local function range(val, min, max, max2)
        local val = 1 - (((max - val) / (max - min)) * max2)
        return val
    end
    
    local endTime = select(7, UnitBuff("player", "Bulwark of Order")) * 1000
    local time = GetTime() * 1000
    local maxDur = select(6, UnitBuff("player", "Bulwark of Order")) * 1000
    local duration = endTime - time
    local c = range(duration, 0, maxDur, 1)
    --c expected as [0, 1]
    if c > 0.5 then
        c = 1 - (2 * (c - 0.5))
        return c, 1, 0, 1
    else
        c = c * 2
        return 1, c, 0, 1
    end
end

ON SHOW
aura_env.maxShield = 0

TRIGGER
function()
    local buff = UnitBuff("player", "Bulwark of Order") or ""
    if buff ~= "" then return true else return false end
end

DURATION
function()
    local shieldAmount = select(17, UnitBuff("player", "Bulwark of Order"))
    local maxShield = UnitHealth("player") / 5
    return shieldAmount, maxShield, 1
end

DISPLAY
function()
    local shield = select(17, UnitBuff("player", "Bulwark of Order")) or 0
    local maxShield = UnitHealth("player") / 5
    local pp = (shield / maxShield) * 20
    return string.format("%2.1f", pp)
end
