WoWInterface SVN Bigtank

[/] [trunk/] [Bigtank.lua] - Rev 2

Compare with Previous | Blame | View Log

-- 盾牌屏障
local shield_barrier = {}

shield_barrier.spell_name = "盾牌屏障"

shield_barrier.statusbar = CreateFrame("StatusBar", nil, PlayerFrame)
shield_barrier.statusbar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
shield_barrier.statusbar:GetStatusBarTexture():SetHorizTile(false)
shield_barrier.statusbar:SetMinMaxValues(0, 100)
shield_barrier.statusbar:SetValue(0)
shield_barrier.statusbar:SetWidth(118)
shield_barrier.statusbar:SetHeight(8)
shield_barrier.statusbar:SetPoint("RIGHT", PlayerFrameManaBar, "RIGHT", 1, 0)
shield_barrier.statusbar:SetStatusBarColor(30/255, 200/255, 230/255, 80/100)
shield_barrier.statusbar:SetFrameLevel(PlayerFrameManaBar:GetFrameLevel() - 1)

shield_barrier.current_text = UIParent:CreateFontString(nil, "OVERLAY")
shield_barrier.current_text:SetSize(100, 20)
shield_barrier.current_text:SetPoint("TOPRIGHT", PlayerFrame, "TOPRIGHT", -10, -22)
shield_barrier.current_text:SetFont("Fonts\\ARHei.ttf", 16)
shield_barrier.current_text:SetJustifyH("RIGHT")
shield_barrier.current_text:Hide()

shield_barrier.time_text = UIParent:CreateFontString(nil, "OVERLAY")
shield_barrier.time_text:SetSize(20, 20)
shield_barrier.time_text:SetPoint("TOPRIGHT", PlayerFrame, "TOPRIGHT", -50, -22)
shield_barrier.time_text:SetFont("Fonts\\ARHei.ttf", 16)
shield_barrier.time_text:SetJustifyH("Left")
shield_barrier.time_text:Hide()

shield_barrier.cooldown = CreateFrame("Cooldown", nil, PlayerFrame)
shield_barrier.cooldown:SetSize(0, 0)
shield_barrier.cooldown:Hide()
shield_barrier.last_time = 0

shield_barrier.expect_text = UIParent:CreateFontString(nil, "OVERLAY")
shield_barrier.expect_text:SetSize(100, 20)
shield_barrier.expect_text:SetPoint("TOPRIGHT", PlayerFrame, "TOPRIGHT", -20, -22)
shield_barrier.expect_text:SetFont("Fonts\\ARHei.ttf", 16)
shield_barrier.expect_text:SetJustifyH("Left")
shield_barrier.expect_text:Hide()

shield_barrier.SetCurrentText = function(value)
    shield_barrier.current_text:SetText(string.format("|c0000ff00%dW", value/10000))
end

shield_barrier.SetCurrentText(0)

local function IsTankWarrior()
    local localizedClass, englishClass, classIndex = UnitClass("player")
    local specl_index = GetSpecialization()
    if specl_index == nil then return false end
    local specl_id = GetSpecializationInfo(specl_index)
    if classIndex ~= 1 then return false end
    if specl_id ~= 73 then return false end
    return true
end

local function GetRage()
    local rage = UnitPower("player", SPELL_POWER_RAGE)
    if rage == nil then rage = 0 end
    if IsTankWarrior() == false then
        rage = 0
    end
    return rage
end

local function TogglePlayerName()
    if GetRage() <= 1 and UnitBuff("player", "盾牌屏障") == nil then
        PlayerName:Show()
    else
        PlayerName:Hide()
    end
end

shield_barrier.UpdateTimeText = function()
    if GetTime() - shield_barrier.last_time > 0.1 then
        local seconds = shield_barrier.expire - GetTime()
        shield_barrier.time_text:SetText(string.format("|c0000ff00%d", seconds))
        shield_barrier.last_time = GetTime()
    end
end

shield_barrier.cooldown:SetScript("OnUpdate", shield_barrier.UpdateTimeText)

shield_barrier.UpdateExpectText = function()
    local power = GetRage()
    local stamina = UnitStat("player", 3)
    local revenge = select(15, UnitBuff("player", "复仇之力"))
    local current = select(15, UnitBuff("player", "盾牌屏障"))
    if revenge == nil then revenge = 0 end
    if current == nil then current = 0 end
    if power > 60 then power = 60 end
    local value = max(stamina * 2.5, revenge * 2)
    value = value * (power / 60)
    shield_barrier.expect_text:SetText(string.format("|c0000ff00%dW", value/10000))
    if power >= 20 and value > current then
        shield_barrier.expect_text:Show()
    else
        shield_barrier.expect_text:Hide()
    end
    TogglePlayerName()
end

shield_barrier.on_begin = function(spell_name, duration, expire, value)
    shield_barrier.max = value
    shield_barrier.expire = expire
    shield_barrier.statusbar:SetValue(100)
    PlayerFrameManaBar:SetAlpha(50/100)
    shield_barrier.SetCurrentText(value)
    shield_barrier.current_text:Show()
    shield_barrier.time_text:Show()
    shield_barrier.cooldown:SetCooldown(expire - duration, duration)
    shield_barrier.cooldown:Show()
    TogglePlayerName()
end

shield_barrier.on_update = function(spell_name, duration, expire, value)
    shield_barrier.expire = expire
    if shield_barrier.max < value then
        shield_barrier.max = value
    end
    shield_barrier.statusbar:SetValue(value * 100 / shield_barrier.max)
    shield_barrier.SetCurrentText(value)
    shield_barrier.cooldown:SetCooldown(expire - duration, duration)
    shield_barrier.cooldown:Show()
end

shield_barrier.on_end = function(spell_name)
    shield_barrier.max = 0
    shield_barrier.statusbar:SetValue(0)
    PlayerFrameManaBar:SetAlpha(100/100)
    shield_barrier.SetCurrentText(0)
    shield_barrier.current_text:Hide()
    shield_barrier.time_text:Hide()
    shield_barrier.cooldown:Hide()
    shield_barrier.UpdateExpectText()
    TogglePlayerName()
end

BuffEvent(shield_barrier.spell_name, shield_barrier.on_begin, shield_barrier.on_update, shield_barrier.on_end)
PowerEvent(shield_barrier.UpdateExpectText)

-- 盾牌格挡
local shield_block = {}

shield_block.spell_name = "盾牌格挡"

shield_block.frame = CreateFrame("Frame", nil, PlayerFrame)
shield_block.frame:SetSize(38, 38)
shield_block.frame:SetPoint("TOP", PlayerFrame, "BOTTOM", 100, 39)
shield_block.frame:SetFrameLevel(TotemFrame:GetFrameLevel() - 1)

shield_block.frame.icon = CreateFrame("Frame", nil, shield_block.frame)
shield_block.frame.icon:SetSize(22, 22)
shield_block.frame.icon:SetPoint("CENTER", 0, 0)

shield_block.frame.icon.texture = shield_block.frame.icon:CreateTexture(nil, "ARTWORK", shield_block.frame.icon)
shield_block.frame.icon.texture:SetSize(22, 22)
shield_block.frame.icon.texture:SetPoint("CENTER", 0, 0)
shield_block.frame.icon.texture:SetTexture("Interface\\Icons\\Ability_Defend")

shield_block.frame.cooldown = CreateFrame("Cooldown", nil, shield_block.frame.icon)
shield_block.frame.cooldown:SetSize(22, 22)
shield_block.frame.cooldown:SetPoint("CENTER", 0, 0)
shield_block.frame.cooldown:SetReverse(true)
shield_block.last_time = 0

shield_block.frame.border = CreateFrame("Frame", nil, shield_block.frame.icon)
shield_block.frame.border:SetSize(38, 38)
shield_block.frame.border:SetPoint("CENTER", 0, 0)

shield_block.frame.border.texture = shield_block.frame.border:CreateTexture(nil, "OVERLAY", shield_block.frame.border)
shield_block.frame.border.texture:SetSize(38, 38)
shield_block.frame.border.texture:SetPoint("CENTER", 0, 0)
shield_block.frame.border.texture:SetTexture("Interface\\CharacterFrame\\TotemBorder")

shield_block.frame.time_text = shield_block.frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
shield_block.frame.time_text:SetPoint("TOP", shield_block.frame, "BOTTOM", 0, 5)
shield_block.frame.time_text:SetText(string.format("|cffffffff%d s", 0))

shield_block.frame:Hide()

shield_block.UpdateTimeText = function()
    if GetTime() - shield_block.last_time > 0.1 then
        local seconds = shield_block.expire - GetTime()
        shield_block.frame.time_text:SetText(string.format("|cffffffff%d s", seconds))
        shield_block.last_time = GetTime()
    end
end

shield_block.frame.cooldown:SetScript("OnUpdate", shield_block.UpdateTimeText)

shield_block.on_begin = function(spell_name, duration, expire, value)
    shield_block.expire = expire
    shield_block.frame:Show()
    shield_block.frame.cooldown:SetCooldown(expire - duration, duration)
end

shield_block.on_update = function(spell_name, duration, expire, value)
    shield_block.expire = expire
    shield_block.frame:Show()
    shield_block.frame.cooldown:SetCooldown(expire - duration, duration)
end

shield_block.on_end = function(spell_name)
    shield_block.frame:Hide()
end

BuffEvent(shield_block.spell_name, shield_block.on_begin, shield_block.on_update, shield_block.on_end)

Compare with Previous | Blame