--TODO: FIX THE FUCKING THING
--I had no idea what I was doing lol

TRIGGER FOR HP
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    local output = ""
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            --if UnitName("nameplate" .. i) == bossList[j] then
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    return true
                end
            end
        end
    end
end

TRIGGER FOR POWER
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            --if UnitName("nameplate" .. i) == bossList[j] then
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    if UnitPower("nameplate" .. i) > 0 then
                        return true
                    end
                end
            end
        end
    end
end

TRIGGER FOR CASTBAR
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    local output = ""
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    if UnitCastingInfo("nameplate" .. i) then
                        return true
                    end
                end
            end
        end
    end
end

DISPLAY FOR HP
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    local output = ""
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            --if UnitName("nameplate" .. i) == bossList[j] then
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    aura_env.bossHp = UnitHealth("nameplate" .. i)
                    aura_env.bossMaxHp = UnitHealthMax("nameplate" .. i)
                    aura_env.bossPer = math.floor((aura_env.bossHp / aura_env.bossMaxHp) * 100)
                    output = math.floor(aura_env.bossHp / 1e6) .. "M%/" .. math.floor(aura_env.bossMaxHp / 1e6) .. "M - " .. aura_env.bossPer .. "%%"
                    break
                end
            end
        end
    end
    return output
end

DISPLAY FOR POWER
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    local output = ""
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            --if UnitName("nameplate" .. i) == bossList[j] then
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    if UnitPower("nameplate" .. i) > 0 then
                        aura_env.bossPower = UnitPower("nameplate" .. i)
                        aura_env.bossPowerMax = UnitPowerMax("nameplate" .. i)
                        aura_env.bossPer = math.floor((aura_env.bossPower / aura_env.bossPowerMax) * 100)
                        output = aura_env.bossPower .. "%/" .. aura_env.bossPowerMax .. " " .. aura_env.bossPer .. "%%"
                        break
                    end
                end
            end
        end
    end
    return output
end

DISPLAY FOR CASTBAR
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    local output = ""
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    if UnitCastingInfo("nameplate" .. i) then
                        aura_env.bossCast = UnitCastingInfo("nameplate" .. i)
                        aura_env.castEnd = select(6, UnitCastingInfo("nameplate" .. i))
                        aura_env.castStart = select(5, UnitCastingInfo("nameplate" .. i))
                        output = aura_env.bossCast .. " - " .. math.floor(((aura_env.castEnd - GetTime() * 1000) / 1000) * 100) / 100
                        break
                    end
                end
            end
        end
    end
    return output
end

DURATION FOR HP
function()
    return aura_env.bossHp, aura_env.bossMaxHp, 1
end

DURATION FOR POWER
function()
    return aura_env.bossPower, aura_env.bossPowerMax, 1
end

DURATION FOR CASTBAR
function()
    return aura_env.castEnd - GetTime() * 1000, aura_env.castEnd - aura_env.castStart, 1
end

DISPLAY FOR NAME
function()
    local bossList =
    {
        "Skorpyron", "Anomaly", "Trilliax", "Tichon", "Krosus", "Aluriel", "Botanist", "Augur", "Elisande", "Gul'dan", --Nighthold
        "Amalgam of souls", "Illysanna", "Smashspite", "Kur'talos", --BRH
        "Gerdo", "Flamewreath", "Advisor Melandrus", --CoS
        "Glaidalis", "Oakheart", "Dresaron", "of Xavius", --DHT
        "Parjesh", "Lady Hatecoil", "Deepbeard", "Serpentrix", "Wrath of Azshara", --EoA
        "Hymdall", "Hyrja", "Fenryr", "Skovald", "Odyn", --HoV
        "Ymiron", "Harbaron", "Helya", --MoS
        "Rokmora", "Ularogg", "Naraxas", "Dargrul", --NL
        "Ivanyr", "Corstilax", "Xakal", "Nal'tira", "Vandros", --Arcway
        "Saltheril", "Inquisitor Tormen", "Ash'golm", "Glazer", "Cordana Fel" --VoTW
    }
    local output = ""
    
    for i = 1, 40 do
        for j = 1, table.getn(bossList) do
            --if UnitName("nameplate" .. i) == bossList[j] then
            if UnitExists("nameplate" .. i) then
                if string.match(string.lower(UnitName("nameplate" .. i)), string.lower(bossList[j])) then
                    output = UnitName("nameplate" .. i)
                    break
                end
            end
        end
    end
    return output
end

ANIMATION FOR HP
function()
    local function range (val, min, max, max2)
        val = 1 - (((max - val) / (max - min)) * max2)
        return val
    end
    local c = aura_env.bossHp / aura_env.bossMaxHp
    c = 1 - c
    --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

INIT FOR HP
aura_env.bossHp = 1
aura_env.bossMaxHp = 1
aura_env.bossPer = 1

INIT FOR POWER
aura_env.bossPower = 1
aura_env.bossPowerMax = 1
aura_env.bossPer = 1

INIT FOR CASTBAR
aura_env.castEnd = 0
aura_env.castStart = 0
aura_env.bossCast = ""
