local addonName, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local ZLCreateFrame = ZL.ZLCreateFrame
local CreateEditBox = ZL.CreateEditBox
local CreateButton = ZL.CreateButton
local GameTooltipShow = ZL.GameTooltipShow
local GetClassColorName = ZL.GetClassColorName
local ParseClassColorName = ZL.ParseClassColorName
local PlayerIsML = ZL.PlayerIsML
local MyAddon = ZL.MyAddon
local Serializer = LibStub('AceSerializer-3.0')

local width, height, wgap, hgap = 120, 24, 5, 5
local classList = {"PRIEST", "PALADIN", "MAGE", "DRUID"}
local classDic = {
    PRIEST = "|A:classicon-priest:12:12|a 牧师",
    PALADIN = "|A:classicon-paladin:12:12|a 骑士",
    MAGE = "|A:classicon-mage:12:12|a 法师",
    DRUID = "|A:classicon-druid:12:12|a 德鲁伊"
}
local BUFFLIST = {"耐力", "精神", "暗抗", "王者", "智慧", "力量", "庇护", "智力", "爪子"}
local DRLIST = {"神圣牺牲", "光环掌握", "痛苦压制", "血歌", "宁静", "战复"}
local TASKSPELLID = {
    ["耐力"] = 21562, ["精神"] = 27681, ["暗抗"] = 27683,
    ["王者"] = 25898, ["智慧"] = 48938, ["力量"] = 48934,
    ["庇护"] = 25899, ["智力"] = 23028, ["爪子"] = 21849,
    ["神圣牺牲"] = 64205, ["光环掌握"] = 31821, ["痛苦压制"] = 33206,
    ["血歌"] = 64843, ["宁静"] = 740, ["战复"] = 20484,
}
local CLASSBUFF = {
    WARRIOR = {"耐力", "暗抗", "王者", "力量", "庇护", "爪子"},
    ROGUE = {"耐力", "暗抗", "王者", "力量", "庇护", "爪子"},
    DEATHKNIGHT = {"耐力", "暗抗", "王者", "力量", "庇护", "爪子"},
    PALADIN = {"耐力", "精神", "暗抗", "王者", "智慧", "庇护", "智力", "爪子"},
    HUNTER = {"耐力", "精神", "暗抗", "王者", "智慧", "力量", "庇护", "智力", "爪子"},
    DRUID = {"耐力", "精神", "暗抗", "王者", "智慧", "庇护", "智力", "爪子"},
    SHAMAN = {"耐力", "精神", "暗抗", "王者", "智慧", "庇护", "智力", "爪子"},
    PRIEST = {"耐力", "精神", "暗抗", "王者", "智慧", "庇护", "智力", "爪子"},
    MAGE = {"耐力", "精神", "暗抗", "王者", "智慧", "庇护", "智力", "爪子"},
    WARLOCK = {"耐力", "精神", "暗抗", "王者", "智慧", "庇护", "智力", "爪子"},
}
local BUFFNAMEDIC = {
    ["强效王者祝福"] = "王者",
    ["王者祝福"] = "王者",
    ["强效智慧祝福"] = "智慧",
    ["智慧祝福"] = "智慧",
    ["强效力量祝福"] = "力量",
    ["力量祝福"] = "力量",
    ["强效庇护祝福"] = "庇护",
    ["庇护祝福"] = "庇护",
    ["坚韧祷言"] = "耐力",
    ["真言术：韧"] = "耐力",
    ["精神祷言"] = "精神",
    ["神圣之灵"] = "精神",
    ["暗影防护祷言"] = "暗抗",
    ["暗影防护"] = "暗抗",
    ["奥术光辉"] = "智力",
    ["达拉然光辉"] = "智力",
    ["奥术智慧"] = "智力",
    ["野性赐福"] = "爪子",
    ["野性印记"] = "爪子",
}
local MONITORBUFFKEYFILTER = {
    "|CFF71D5FF|HSPELL:", "BUFF和减伤", "打气精神", "BUFF安排"
}
local function playerIsInRaid(playerName)
    if not playerName then return false, false end
    playerName = ZL.ParseClassColorName(playerName)
    local index = UnitInRaid(playerName)
    if index then
        local online = select(8, GetRaidRosterInfo(index))
        return true, online
    else
        return false, false
    end
end
local function getDROrderDropdownList()
    return {
        {text="减伤技能多在前", value=1},
        {text="按团队顺序", value=2}
    }
end

local function buffKeyIsExist(msg)
    for _, buffKey in ipairs(BUFFLIST) do
        if strfind(msg, buffKey) then
            return true
        end
    end
    return false
end

local function filterBuffKeyIsExist(msg)
    for _, buffKey in ipairs(MONITORBUFFKEYFILTER) do
        if strfind(msg, buffKey) then
            return true
        end
    end
    return false
end

local function buffEditBox(point, relativeTo, relativePoint, offsetX, offsetY, text, _fileName, _buffTask)
    local TaskFrame = ZL.TaskFrame
    local btn = CreateFrame("Button", nil, TaskFrame)
    btn:SetNormalFontObject("GameFontNormal")
	btn:SetHighlightFontObject("GameFontHighlight")
	btn:SetDisabledFontObject("GameFontDisable")
    btn:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)
    btn:SetSize(width, height)
    btn:SetText(text)
    btn.fileName = _fileName
    btn.buffTask = _buffTask

    btn.editBox = CreateEditBox(btn, width, height, 14, "CENTER")
    local editBox = btn.editBox
    editBox:SetPoint("TOP", btn, "BOTTOM", 0, 0)
    editBox:Disable()
    editBox:SetScript("OnMouseDown", function (self, button)
        if IsInRaid(1) then
            local function tempfunc()
                local menuList = {}
                for i = 1, MAX_RAID_MEMBERS do
                    local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                    if name and fileName == _fileName then
                        local colorName = GetClassColorName(name, fileName)
                        if _buffTask == "庇护" then
                            if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name]["庇护祝福"] then
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = "|T" .. ZL_CURRENT.playerInfo[name].talentName[ZL_CURRENT.playerInfo[name].newTalentName] .. ":12|t " .. colorName .. "|T135911:12|t"
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = ZL_PLAYERLIST.TaskList and ZL_PLAYERLIST.TaskList.BuffTask[_buffTask] == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.BuffTask[_buffTask] = name
                                        self:SetText(colorName)
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        else
                            tinsert(menuList, {
                                text = function ()
                                    local tex = ""
                                    if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].newTalentName then
                                        tex = "|T" .. ZL_CURRENT.playerInfo[name].talentName[ZL_CURRENT.playerInfo[name].newTalentName] .. ":12|t " .. colorName
                                        if ZL_CURRENT.playerInfo[name]["强化智慧祝福"] then
                                            tex = tex .. "|T135912:12|t"
                                        end
                                        if ZL_CURRENT.playerInfo[name]["强化力量祝福"] then
                                            tex = tex .. "|T135908:12|t"
                                        end
                                        if ZL_CURRENT.playerInfo[name]["庇护祝福"] then
                                            tex = tex .. "|T135911:12|t"
                                        end
                                    else
                                        tex = colorName
                                    end
                                    if not online then
                                        tex = tex .. "|cffff0000(离线)|r"
                                    end
                                    return tex
                                end,
                                checkable = 1,
                                keepShownOnClick = 1,
                                checked = ZL_PLAYERLIST.TaskList and ZL_PLAYERLIST.TaskList.BuffTask[_buffTask] == name,
                                func = function ()
                                    ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                    ZL_PLAYERLIST.TaskList.BuffTask[_buffTask] = name
                                    self:SetText(colorName)
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end

                    end
                end
                if #self:GetText() > 0 then
                    if #menuList > 0 then
                        tinsert(menuList, {isSeparator=1})
                    end
                    tinsert(menuList, {
                        text = "|CFFFFDE00清除|r",
                        func = function ()
                            ZL_PLAYERLIST.TaskList.BuffTask[_buffTask] = nil
                            self:SetText("")
                            ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                        end
                    })
                end
                return menuList
            end
            local menuList = tempfunc()
            if #menuList > 0 then
                ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
            end
        end
    end)
    return btn
end

local function DRTaskNoticeOnly(taskIndex, spellID)
    if IsShiftKeyDown() then
        if not ZL.opt.raidChannel and not ZL.opt.whisperChannel then
            ZL.Print("未开启发送信息频道！")
            return
        end
        if not IsInRaid(1) then
            ZL.Print("不在团队中！")
            return
        end
        if ZL_PLAYERLIST.TaskList and #ZL_PLAYERLIST.TaskList.DRTask > 0 then
            local tempList = {}
            for _, data in ipairs(ZL_PLAYERLIST.TaskList.DRTask) do
                if data[taskIndex] then
                    tinsert(tempList, data[taskIndex])
                end
            end
            if #tempList > 0 then
                local spellLink = GetSpellLink(spellID)
                if ZL.opt.raidChannel then
                    SendChatMessage(format("{rt6}%s安排如下{rt6}", spellLink), "RAID")
                end
                C_Timer.After(0.3, function ()
                    local index = 1
                    local function tempfunc()
                        if index <= #tempList then
                            local name = tempList[index]
                            if ZL.opt.raidChannel then
                                SendChatMessage(format("%s：%d%s", name, index, spellLink), "RAID")
                            end
                            if ZL.opt.whisperChannel then
                                local inRaid, online = playerIsInRaid(name)
                                if inRaid and online then
                                    SendChatMessage(format("你负责：%d%s", index, spellLink), "WHISPER", nil, name)
                                end
                            end
                            index = index + 1
                            C_Timer.After(0.3, tempfunc)
                        end
                    end
                    tempfunc()
                end)
            end

        end
    end
end

local function BUFFTaskNoticeOnly(buffName)
    if IsShiftKeyDown() then
        if not ZL.opt.raidChannel and not ZL.opt.whisperChannel then
            ZL.Print("未开启发送信息频道！")
            return
        end
        if not IsInRaid(1) then
            ZL.Print("不在团队中！")
            return
        end
        if ZL_PLAYERLIST.TaskList and ZL_PLAYERLIST.TaskList.BuffTask[buffName] then
            local spellLink = GetSpellLink(TASKSPELLID[buffName])
            if ZL.opt.raidChannel then
                SendChatMessage(spellLink .. "：" .. ZL_PLAYERLIST.TaskList.BuffTask[buffName], "RAID")
            end
            if ZL.opt.whisperChannel then
                local inRaid, online = playerIsInRaid(ZL_PLAYERLIST.TaskList.BuffTask[buffName])
                if inRaid and online then
                    SendChatMessage(spellLink .. "：是你负责的，注意及时补BUFF", "WHISPER", nil, ZL_PLAYERLIST.TaskList.BuffTask[buffName])
                end
            end
        end
    end
end

local function noticeByClass(_className, _buffList)
    local TaskContent = {}
    local BuffTask = ZL_PLAYERLIST.TaskList.BuffTask
    for _, buffName in ipairs(_buffList) do
        if BuffTask[buffName] then
            TaskContent[BuffTask[buffName]] = TaskContent[BuffTask[buffName]] or {}
            local spellLink = GetSpellLink(TASKSPELLID[buffName])
            spellLink = #spellLink > 0 and spellLink or buffName
            tinsert(TaskContent[BuffTask[buffName]], spellLink)
        end
    end
    if next(TaskContent) then
        if ZL.opt.raidChannel then
            SendChatMessage("{rt6}" .. _className .. "BUFF安排如下{rt6}", "RAID")
            C_Timer.After(0.3, function ()
                for playerName, taskContentData in pairs(TaskContent) do
                    SendChatMessage(playerName .. "：" .. table.concat(taskContentData, " "), "RAID")
                end
            end)
        end
        if ZL.opt.whisperChannel then
            local playerNameList = {}
            for playerName in pairs(TaskContent) do
                tinsert(playerNameList, playerName)
            end
            table.sort(playerNameList)
            local index = 1
            local playerName, delay
            local function _tempfunc()
                if index <= #playerNameList then
                    playerName = playerNameList[index]
                    local isInRaid, online = playerIsInRaid(playerName)
                    if isInRaid and online then
                        SendChatMessage("你负责：" .. table.concat(TaskContent[playerName], " "), "WHISPER", nil, playerName)
                        delay = 1
                    else
                        delay = 0
                    end
                    index = index + 1
                    C_Timer.After(delay, _tempfunc)
                end
            end
            _tempfunc()
        end
    end
end
local btnTexture = [[Interface\ACHIEVEMENTFRAME\UI-Achievement-Parchment-Horizontal]]
local function titleBtn(text, point, relativeTo, relativePoint, offsetX, offsetY)
    local btn = CreateButton(nil, ZL.TaskFrame, text, point, relativeTo, relativePoint, offsetX, offsetY, width, height)
    btn:GetFontString():SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    btn:SetNormalTexture(btnTexture)
    btn:ClearHighlightTexture()
    btn.BorderRight:Hide()
    return btn
end


function ZL:CreateTaskFrame()
    ZL.TaskFrame = ZLCreateFrame("ZLTASKFRAME", ZL, nil, nil, nil, true, true, "|T132062:15:15|t AI任务分配")
    local TaskFrame = ZL.TaskFrame
    -- 注册 ESC 键关闭窗口
    tinsert(UISpecialFrames, ZL.TaskFrame:GetName())
    local minWidth = (width+wgap)*7 + 10 - wgap
    TaskFrame.Background:SetColorTexture(0.1, 0.1, 0.1, 1)
    TaskFrame:SetResizeBounds(minWidth, 250, minWidth, GetScreenHeight()-110)
    TaskFrame:SetScript("OnMouseUp", function (self)
        self:StopMovingOrSizing()
        if not ZL.glb.ZLTaskFrame then ZL.glb.ZLTaskFrame = {} end
        ZL.glb.ZLTaskFrame.point, _, ZL.glb.ZLTaskFrame.relative, ZL.glb.ZLTaskFrame.x, ZL.glb.ZLTaskFrame.y = self:GetPoint()
    end)
    TaskFrame:SetScript("OnMouseDown", function (self)
        self:StartMoving()
    end)
    TaskFrame:SetScript("OnShow", function (self)
        self:Update()
    end)
    TaskFrame.resizeButton:Hide()
    local resizeButton = TaskFrame.resizeButton
    -- 设置鼠标按下时开始调整大小
    resizeButton:SetScript("OnMouseDown", function(self, button)
        if button == "LeftButton" then
            TaskFrame:StartSizing("BOTTOMRIGHT")
        end
    end)
    -- 鼠标松开时停止调整大小
    resizeButton:SetScript("OnMouseUp", function(self, button)
        TaskFrame:StopMovingOrSizing()
        if not ZL.glb.ZLTaskFrame then ZL.glb.ZLTaskFrame = {} end
        ZL.glb.ZLTaskFrame.Width,  ZL.glb.ZLTaskFrame.Height= TaskFrame:GetSize()
    end)
    TaskFrame:ClearAllPoints()
    if ZL.glb.ZLTaskFrame and ZL.glb.ZLTaskFrame.point then
        TaskFrame:SetPoint(ZL.glb.ZLTaskFrame.point, UIParent, ZL.glb.ZLTaskFrame.relative, ZL.glb.ZLTaskFrame.x, ZL.glb.ZLTaskFrame.y)
    else
        TaskFrame:SetPoint("CENTER")
    end
    if ZL.glb.ZLTaskFrame and ZL.glb.ZLTaskFrame.Width and ZL.glb.ZLTaskFrame.Height then
        TaskFrame:SetSize(minWidth, ZL.glb.ZLTaskFrame.Height)
    else
        TaskFrame:SetSize(minWidth, 350)
    end
    TaskFrame.naiLiEditBox = buffEditBox("TOPLEFT", TaskFrame.TitleBottom, "BOTTOMLEFT", 5, -8, "|T135941:14|t耐力", "PRIEST", "耐力")
    local naiLiEditBox = TaskFrame.naiLiEditBox
    naiLiEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("耐力")
    end)

    TaskFrame.jingShenEditBox = buffEditBox("LEFT", naiLiEditBox, "RIGHT", wgap, 0, "|T135946:14|t精神", "PRIEST", "精神")
    local jingShenEditBox = TaskFrame.jingShenEditBox
    jingShenEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("精神")
    end)

    TaskFrame.anKangEditBox = buffEditBox("LEFT", jingShenEditBox, "RIGHT", wgap, 0, "|T135945:14|t暗抗", "PRIEST", "暗抗")
    local anKangEditBox = TaskFrame.anKangEditBox
    anKangEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("暗抗")
    end)

    TaskFrame.wangZheEditBox = buffEditBox("LEFT", anKangEditBox, "RIGHT", wgap, 0, "|T135993:14|t王者", "PALADIN", "王者")
    local wangZheEditBox = TaskFrame.wangZheEditBox
    wangZheEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("王者")
    end)

    TaskFrame.zhiHuiEditBox = buffEditBox("TOP", naiLiEditBox.editBox, "BOTTOM", 0, -hgap, "|T135912:14|t智慧", "PALADIN", "智慧")
    local zhiHuiEditBox = TaskFrame.zhiHuiEditBox
    zhiHuiEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("智慧")
    end)

    TaskFrame.liLiangEditBox = buffEditBox("LEFT", zhiHuiEditBox, "RIGHT", wgap, 0, "|T135908:14|t力量", "PALADIN", "力量")
    local liLiangEditBox = TaskFrame.liLiangEditBox
    liLiangEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("力量")
    end)

    TaskFrame.biHuEditBox = buffEditBox("LEFT", liLiangEditBox, "RIGHT", wgap, 0, "|T135911:14|t庇护", "PALADIN", "庇护")
    local biHuEditBox = TaskFrame.biHuEditBox
    biHuEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("庇护")
    end)

    TaskFrame.zhiLiEditBox = buffEditBox("LEFT", biHuEditBox, "RIGHT", wgap, 0, "|T135869:14|t智力", "MAGE", "智力")
    local zhiLiEditBox = TaskFrame.zhiLiEditBox
    zhiLiEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("智力")
    end)

    TaskFrame.zhuaZiEditBox = buffEditBox("LEFT", zhiLiEditBox, "RIGHT", wgap, 0, "|T136038:14|t爪子", "DRUID", "爪子")
    local zhuaZiEditBox = TaskFrame.zhuaZiEditBox
    zhuaZiEditBox:SetScript("OnClick", function (self)
        BUFFTaskNoticeOnly("爪子")
    end)

    TaskFrame.raidCheckBtn = CreateFrame("CheckButton", nil, TaskFrame, "ChatConfigCheckButtonTemplate")
    local raidCheckBtn = TaskFrame.raidCheckBtn
    raidCheckBtn:SetPoint("LEFT", wangZheEditBox, "RIGHT", wgap+3, -3)
    raidCheckBtn.Text:SetText("团队")
    raidCheckBtn.Text:SetFont(GameFontNormal:GetFont(), 14, "")
    raidCheckBtn:SetHitRectInsets(0, -raidCheckBtn.Text:GetWidth(), 0, 0)
    raidCheckBtn:SetChecked(ZL.opt.raidChannel)
    raidCheckBtn:SetScript("OnClick", function (self)
        ZL.opt.raidChannel = self:GetChecked()
    end)

    TaskFrame.whisperCheckBtn = CreateFrame("CheckButton", nil, TaskFrame, "ChatConfigCheckButtonTemplate")
    local whisperCheckBtn = TaskFrame.whisperCheckBtn
    whisperCheckBtn:SetPoint("LEFT", raidCheckBtn, "RIGHT", 35, 0)
    whisperCheckBtn.Text:SetText("密语")
    whisperCheckBtn.Text:SetFont(GameFontNormal:GetFont(), 14, "")
    whisperCheckBtn:SetHitRectInsets(0, -whisperCheckBtn.Text:GetWidth(), 0, 0)
    whisperCheckBtn:SetChecked(ZL.opt.whisperChannel)
    whisperCheckBtn:SetScript("OnClick", function (self)
        ZL.opt.whisperChannel = self:GetChecked()
    end)

    local DROrderFontString = TaskFrame:CreateFontString(nil, "OVERLAY")
    DROrderFontString:SetPoint("LEFT", wangZheEditBox, "RIGHT", 2*wgap+5+width, 0)
    DROrderFontString:SetHeight(height)
    DROrderFontString:SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    DROrderFontString:SetWordWrap(false)
    DROrderFontString:SetJustifyH("LEFT")
    DROrderFontString:SetTextColor(1, 0.82, 0, 1)
    DROrderFontString:SetText("减伤顺序：")
    TaskFrame.DROrderDropdown = CreateFrame("Button", nil, TaskFrame)
    local DROrderDropdown = TaskFrame.DROrderDropdown
    DROrderDropdown:SetPoint("LEFT", DROrderFontString, "RIGHT", 5, 0)
    DROrderDropdown:SetSize(160, height)
    ZL.GUI:GetClass('Dropdown'):Bind(DROrderDropdown)
    DROrderDropdown:SetMenuTable(getDROrderDropdownList())
    DROrderDropdown:SetValue(ZL.opt.DROrderSelect)
    DROrderDropdown:SetCallback('OnSelectChanged', function (self)
        ZL.opt.DROrderSelect = self.value
        TaskFrame.autoArrangeBtn:Click()
    end)

    TaskFrame.clearAllBtn = CreateButton(nil, TaskFrame, "清空", "TOPLEFT", DROrderFontString, "BOTTOMLEFT", 0, -hgap-5, width-5, height)
    local clearAllBtn = TaskFrame.clearAllBtn
    clearAllBtn.Background:SetColorTexture(0.25,0.25,0.27)
    clearAllBtn:SetScript("OnClick", function ()
        ZL_PLAYERLIST.TaskList = {BuffTask={}, DRTask={}}
        TaskFrame:Update()
    end)

    TaskFrame.refreshBtn = CreateButton(nil, TaskFrame, "刷新天赋", "LEFT", clearAllBtn, "RIGHT", wgap, 0, width-5, height)
    local refreshBtn = TaskFrame.refreshBtn
    refreshBtn.Background:SetColorTexture(0.25,0.25,0.27)
    refreshBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
    refreshBtn:SetScript("OnClick", function (self, button)
        if button == "LeftButton" then
            if IsInRaid(1) then
                self:Disable()
                local i = 1
                local delay
                local function tempfunc()
                    if i <= MAX_RAID_MEMBERS then
                        local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                        if name and online and tIndexOf(classList, fileName) then
                            if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].talentName
                            and not ZL_CURRENT.playerInfo[name].tdInspectDB then
                                i = i + 1
                                delay = 0
                            else
                                if ZL.canInspect(name) then
                                    if ZL.inspectUnit == true then
                                        ZL.inspectUnit = nil
                                        i = i + 1
                                        delay = 0
                                    else
                                        ZL.inspectUnit = name
                                        NotifyInspect(name)
                                        delay = 0.3
                                    end
                                else
                                    local fullName = ZL.GetFullName(name)
                                    if TDDB_INSPECT2 then
                                        if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and 
                                        TDDB_INSPECT2.global.userCache[fullName] and TDDB_INSPECT2.global.userCache[fullName].talents then
                                            local talentsDB = TDDB_INSPECT2.global.userCache[fullName]
                                            if time() - talentsDB.timestamp > 1800 then
                                                MyAddon:SendCommMessage("tdInspect", Serializer:Serialize('Q', true, false, 2, false, false), 'WHISPER', name)
                                            end
                                        else
                                            MyAddon:SendCommMessage("tdInspect", Serializer:Serialize('Q', true, false, 2, false, false), 'WHISPER', name)
                                        end
                                        ZL.Print(GetClassColorName(name, fileName) .. "获取天赋信息|cffff0000失败|r，尝试获取tdInspect缓存数据。")
                                    else
                                        ZL.Print(GetClassColorName(name, fileName) .. "获取天赋信息|cffff0000失败|r。")
                                    end
                                    i = i + 1
                                    delay = 0.1
                                end
                            end
                        else
                            i = i + 1
                            delay = 0
                        end
                        C_Timer.After(delay, tempfunc)
                    else
                        self:Enable()
                        ZL.Print("天赋信息更新完成！", true)
                        C_Timer.After(1, function ()
                            if ZL.SubsidyFrame:IsShown() then
                                ZL.SubsidyFrame:Update()
                            end
                            if TaskFrame:IsShown() then
                                TaskFrame:Update()
                            end
                        end)
                    end
                end
                tempfunc()
            else
                ZL.Print("不在团队中！")
            end
        elseif button == "RightButton" then
            local function tempfunc()
                local function getPlayerTalent(colorName)
                    C_Timer.NewTicker(0.2, function (self)
                        local name = ParseClassColorName(colorName)
                        if CanInspect(name, false) then --ZL.canInspect(name)
                            if ZL.inspectUnit == true then
                                ZL.Print(colorName .. "天赋信息已更新。")
                                ZL.inspectUnit = nil
                                if ZL.SubsidyFrame:IsShown() then
                                    ZL.SubsidyFrame:Update()
                                end
                                self:Cancel()
                            else
                                ZL.inspectUnit = name
                                NotifyInspect(name)
                            end
                        else
                            local fullName = ZL.GetFullName(name)
                            if TDDB_INSPECT2 then
                                if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and 
                                TDDB_INSPECT2.global.userCache[fullName] and TDDB_INSPECT2.global.userCache[fullName].talents then
                                    local talentsDB = TDDB_INSPECT2.global.userCache[fullName]
                                    if time() - talentsDB.timestamp > 1800 then
                                        MyAddon:SendCommMessage("tdInspect", Serializer:Serialize('Q', true, false, 2, false, false), 'WHISPER', name)
                                    end
                                else
                                    MyAddon:SendCommMessage("tdInspect", Serializer:Serialize('Q', true, false, 2, false, false), 'WHISPER', name)
                                end
                                ZL.Print(colorName .. "获取天赋信息|cffff0000失败|r，尝试获取tdInspect缓存数据。")
                            else
                                ZL.Print(colorName .. "获取天赋信息|cffff0000失败|r。")
                            end
                            self:Cancel()
                        end
                    end)
                end
                local menuList = {
                    {text="当前团队当前天赋", isTitle=1},
                    {
                        disabled = not IsInRaid(1),
                        text = "刷新全团天赋",
                        func = function ()
                            local i = 1
                            local delay
                            local function _tempfunc()
                                if i <= MAX_RAID_MEMBERS then
                                    local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                                    if name and online and tIndexOf(classList, fileName) then
                                        if ZL.canInspect(name) then
                                            if ZL.inspectUnit == true then
                                                ZL.inspectUnit = nil
                                                i = i + 1
                                                delay = 0
                                            else
                                                ZL.inspectUnit = name
                                                NotifyInspect(name)
                                                delay = 0.3
                                            end
                                        else
                                            i = i + 1
                                            delay = 0
                                            ZL.Print(GetClassColorName(name, fileName) .. "获取天赋信息|cffff0000失败|r。", true)
                                        end
                                    else
                                        i = i + 1
                                        delay = 0
                                    end
                                    C_Timer.After(delay, tempfunc)
                                else
                                    ZL.Print("天赋信息更新完成！", true)
                                    C_Timer.After(1, function ()
                                        if ZL.SubsidyFrame:IsShown() then
                                            ZL.SubsidyFrame:Update()
                                        end
                                        if TaskFrame:IsShown() then
                                            TaskFrame:Update()
                                        end
                                    end)
                                end
                            end
                            _tempfunc()
                        end
                    },
                    {text="*：数据来源tdInspect", isTitle=1},
                }
                local notTalentCounts = 0
                if IsInRaid(1) then
                    local tempList = {
                        PRIEST = {},
                        PALADIN = {},
                        MAGE = {},
                        DRUID = {},
                    }
                    for i = 1, MAX_RAID_MEMBERS do
                        local name, _, _, _, _, fileName = GetRaidRosterInfo(i)
                        if name then
                            if tempList[fileName] then
                                tinsert(tempList[fileName], name)
                            end
                        end
                    end
                    local counts = 0
                    for _, data in pairs(tempList) do
                        counts = counts + #data
                    end
                    if counts > 0 then
                        for _, fileName in ipairs(classList) do
                            if #tempList[fileName] > 0 then
                                tinsert(menuList, {isSeparator = true})
                                -- tinsert(menuList, {text=classDic[fileName], isTitle=1})
                                for _, name in ipairs(tempList[fileName]) do
                                    local colorName = GetClassColorName(name, fileName)
                                    local text = colorName
                                    local isExist
                                    if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].newTalentName then
                                        text = text .. " - |T" .. ZL_CURRENT.playerInfo[name].talentName[ZL_CURRENT.playerInfo[name].newTalentName] .. ":12|t" .. ZL_CURRENT.playerInfo[name].newTalentName
                                        isExist = true
                                        if ZL_CURRENT.playerInfo[name].tdInspectDB then
                                            text = "|CFFFFDE00*|r" .. text
                                        end
                                    end
                                    if (not isExist) and IsInRaid(1) and UnitInRaid(name) then
                                        notTalentCounts = notTalentCounts + 1
                                    end
                                    tinsert(menuList, {
                                        text = text,
                                        hasArrow = 1,
                                        menuTable = {
                                            {
                                                text = "刷新天赋",
                                                func = function ()
                                                    getPlayerTalent(colorName)
                                                    ZL.GUI:CloseMenu()
                                                end,
                                            },
                                        },
                                    })
                                end
                            end
                        end
                    end
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT")
        end
    end)
    refreshBtn:SetScript("OnEnter", function (self)
        local notExistCounts = 0
        for i = 1, MAX_RAID_MEMBERS do
            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
            if online and tIndexOf(classList, fileName) and not (name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
            and ZL_CURRENT.playerInfo[name].newTalentName and not ZL_CURRENT.playerInfo[name].tdInspectDB) then
                notExistCounts = notExistCounts + 1
            end
        end
        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
        GameTooltip:AddLine("说明")
        GameTooltip:AddLine("1、28码内会自动获取团队天赋信息；", 1, 1, 1)
        GameTooltip:AddLine("2、超出28码，如双方都装了|CFFFFDE00tdInspect|r\n插件，会获取这个插件的缓存数据", 1, 1, 1)
        GameTooltip:AddLine(" ")
        GameTooltip:AddLine("左键：|cffffffff刷新未获取到天赋成员(" .. notExistCounts .. ")|r")
        GameTooltip:AddLine("右键：|cffffffff更多功能|r")
        GameTooltip:Show()
    end)
    refreshBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)

    TaskFrame.autoArrangeBtn = CreateButton(nil, TaskFrame, "一键分配", "TOPLEFT", clearAllBtn, "BOTTOMLEFT", 0, -hgap, width-5, height)
    local autoArrangeBtn = TaskFrame.autoArrangeBtn
    autoArrangeBtn.Background:SetColorTexture(0.25,0.25,0.27)
    autoArrangeBtn:SetScript("OnClick", function (self)
        if not IsInRaid(1) then
            ZL.Print("不在团队中！")
            return
        end
        if not ZL_CURRENT.playerInfo or not next(ZL_CURRENT.playerInfo) then
            ZL.Print("没有天赋信息，请先刷新天赋后再分配！")
            return
        end
        local notExistCounts = 0
        for i = 1, MAX_RAID_MEMBERS do
            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
            if online and tIndexOf(classList, fileName) and not (name and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].newTalentName) then
                notExistCounts = notExistCounts + 1
            end
        end
        if notExistCounts > 0 then
            ZL.Print("有|cffffffff" .. notExistCounts .. "|r个未获取到天赋，请先全部获取到天赋后再分配任务！")
            return
        end
        ZL_PLAYERLIST.TaskList = {
            BuffTask = {}, DRTask = {}
        }
        local BuffTask = ZL_PLAYERLIST.TaskList.BuffTask
        local DRTask = ZL_PLAYERLIST.TaskList.DRTask
        local playerInfo = ZL_CURRENT.playerInfo
        local classFileList = {
            PRIEST = {},
            PALADIN = {},
            MAGE = {},
            DRUID = {},
            PALADIN_SHENSHENG = {},
            PALADIN_FANGHU = {},
            PALADIN_CHENGJIE = {},
            PALADIN_TWO = {},
            PALADIN_DAXISHENG = {},
            PALADIN_DAXISHENG2 = {},
            PALADIN_GUANGZHANG = {},
            PALADIN_GUANGZHANG2 = {},
            PRIEST_YAZHI = {},
            PRIEST_XUEGE = {}, --没有压制技能
            PRIEST_XUEGE2 = {},
        }
        -- local WagesGroupMembers, msg = ZL.GetWagesGroupMembers()
        -- if not WagesGroupMembers then ZL.Print("没有成员") return end
        -- for _, data in ipairs(WagesGroupMembers) do
        --     for _, colorName in ipairs(data) do
        --         local name = ParseClassColorName(colorName)
        --         local fileName = playerInfo[name].classFile
        --         if tIndexOf(classList, fileName) then
        --             tinsert(classFileList[fileName], name)
        --             if fileName == "PALADIN" then
        --                 if playerInfo[name].newTalentName == "神圣" then
        --                     tinsert(classFileList.PALADIN_SHENSHENG, name)
        --                 elseif playerInfo[name].newTalentName == "防护" then
        --                     tinsert(classFileList.PALADIN_FANGHU, name)
        --                 elseif playerInfo[name].newTalentName == "惩戒" then
        --                     tinsert(classFileList.PALADIN_CHENGJIE, name)
        --                 end
        --                 if playerInfo[name]["神圣牺牲"] and playerInfo[name]["光环掌握"] then
        --                     tinsert(classFileList.PALADIN_TWO, name)
        --                     tinsert(classFileList.PALADIN_DAXISHENG2, name)
        --                     tinsert(classFileList.PALADIN_GUANGZHANG2, name)
        --                 elseif playerInfo[name]["神圣牺牲"] and not playerInfo[name]["光环掌握"] then
        --                     tinsert(classFileList.PALADIN_DAXISHENG, name)
        --                     tinsert(classFileList.PALADIN_DAXISHENG2, name)
        --                 elseif not playerInfo[name]["神圣牺牲"] and playerInfo[name]["光环掌握"] then
        --                     tinsert(classFileList.PALADIN_GUANGZHANG, name)
        --                     tinsert(classFileList.PALADIN_GUANGZHANG2, name)
        --                 end
        --             elseif fileName == "PRIEST" then
        --                 tinsert(classFileList.PRIEST_XUEGE2, name)
        --                 if playerInfo[name]["痛苦压制"] then
        --                     tinsert(classFileList.PRIEST_YAZHI, name)
        --                 else
        --                     tinsert(classFileList.PRIEST_XUEGE, name)
        --                 end
        --             end
        --         end
        --     end
        -- end

        for i = 1, MAX_RAID_MEMBERS do
            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
            if name and online and tIndexOf(classList, fileName) then
                tinsert(classFileList[fileName], name)
                if fileName == "PALADIN" then
                    if playerInfo[name].newTalentName == "神圣" then
                        tinsert(classFileList.PALADIN_SHENSHENG, name)
                    elseif playerInfo[name].newTalentName == "防护" then
                        tinsert(classFileList.PALADIN_FANGHU, name)
                    elseif playerInfo[name].newTalentName == "惩戒" then
                        tinsert(classFileList.PALADIN_CHENGJIE, name)
                    end
                    if playerInfo[name]["神圣牺牲"] and playerInfo[name]["光环掌握"] then
                        tinsert(classFileList.PALADIN_TWO, name)
                        tinsert(classFileList.PALADIN_DAXISHENG2, name)
                        tinsert(classFileList.PALADIN_GUANGZHANG2, name)
                    elseif playerInfo[name]["神圣牺牲"] and not playerInfo[name]["光环掌握"] then
                        tinsert(classFileList.PALADIN_DAXISHENG, name)
                        tinsert(classFileList.PALADIN_DAXISHENG2, name)
                    elseif not playerInfo[name]["神圣牺牲"] and playerInfo[name]["光环掌握"] then
                        tinsert(classFileList.PALADIN_GUANGZHANG, name)
                        tinsert(classFileList.PALADIN_GUANGZHANG2, name)
                    end
                elseif fileName == "PRIEST" then
                    tinsert(classFileList.PRIEST_XUEGE2, name)
                    if playerInfo[name]["痛苦压制"] then
                        tinsert(classFileList.PRIEST_YAZHI, name)
                    else
                        tinsert(classFileList.PRIEST_XUEGE, name)
                    end
                end
            end
        end


        local PRIEST_Counts = #classFileList.PRIEST
        local PALADIN_Counts = #classFileList.PALADIN
        --耐力、精神、暗抗
        if PRIEST_Counts == 1 then
            BuffTask["耐力"] = classFileList.PRIEST[1]
            BuffTask["精神"] = classFileList.PRIEST[1]
            BuffTask["暗抗"] = classFileList.PRIEST[1]
        elseif PRIEST_Counts > 1 then
            --按照 戒律>神圣>暗影 排序
            table.sort(classFileList.PRIEST, function (a, b)
                if playerInfo[a].newTalentName == "戒律" and (playerInfo[b].newTalentName == "神圣" or playerInfo[b].newTalentName == "暗影") then
                    return true
                elseif playerInfo[a].newTalentName == "神圣" and playerInfo[b].newTalentName == "暗影" then
                    return true
                elseif playerInfo[a].newTalentName == "神圣" and playerInfo[b].newTalentName == "戒律" then
                    return false
                elseif playerInfo[a].newTalentName == "暗影" and (playerInfo[b].newTalentName == "戒律" or playerInfo[b].newTalentName == "神圣") then
                    return false
                end
                return (UnitInRaid(a) or 0) < (UnitInRaid(b) or 0)
            end)
            if PRIEST_Counts == 2 then
                BuffTask["耐力"] = classFileList.PRIEST[1]
                BuffTask["精神"] = classFileList.PRIEST[1]
                BuffTask["暗抗"] = classFileList.PRIEST[2]
            elseif PRIEST_Counts > 2 then
                BuffTask["耐力"] = classFileList.PRIEST[1]
                BuffTask["精神"] = classFileList.PRIEST[2]
                BuffTask["暗抗"] = classFileList.PRIEST[3]
            end
        end
        local PALADIN_SHENSHENG = classFileList.PALADIN_SHENSHENG
        local PALADIN_FANGHU = classFileList.PALADIN_FANGHU
        local PALADIN_CHENGJIE = classFileList.PALADIN_CHENGJIE
        --王者、智慧、力量、庇护
        if PALADIN_Counts == 1 then
            BuffTask["王者"] = classFileList.PALADIN[1]
        elseif PALADIN_Counts == 2 then
            if #PALADIN_FANGHU > 0 then
                for index, name in ipairs(PALADIN_FANGHU) do
                    if playerInfo[name]["庇护祝福"] then
                        BuffTask["智慧"] = name
                        BuffTask["力量"] = name
                        BuffTask["庇护"] = name
                        tremove(PALADIN_FANGHU, index)
                        break
                    end
                end
            end
            if not BuffTask["智慧"] then
                if #PALADIN_SHENSHENG > 0 then
                    for index, name in ipairs(PALADIN_SHENSHENG) do
                        if playerInfo[name]["强化智慧祝福"] then
                            BuffTask["智慧"] = name
                            BuffTask["力量"] = name
                            tremove(PALADIN_SHENSHENG, index)
                            break
                        end
                    end
                elseif #PALADIN_CHENGJIE > 0 then
                    for index, name in ipairs(PALADIN_CHENGJIE) do
                        if playerInfo[name]["强化力量祝福"] then
                            BuffTask["智慧"] = name
                            BuffTask["力量"] = name
                            tremove(PALADIN_CHENGJIE, index)
                            break
                        end
                    end
                end
            end
            if not BuffTask["智慧"] then
                if #PALADIN_SHENSHENG > 0 then
                    BuffTask["智慧"] = PALADIN_SHENSHENG[1]
                    BuffTask["力量"] = PALADIN_SHENSHENG[1]
                    tremove(PALADIN_SHENSHENG, 1)
                elseif #PALADIN_CHENGJIE > 0 then
                    BuffTask["智慧"] = PALADIN_CHENGJIE[1]
                    BuffTask["力量"] = PALADIN_CHENGJIE[1]
                    tremove(PALADIN_CHENGJIE, 1)
                elseif #PALADIN_FANGHU > 0 then
                    BuffTask["智慧"] = PALADIN_FANGHU[1]
                    BuffTask["力量"] = PALADIN_FANGHU[1]
                    tremove(PALADIN_FANGHU, 1)
                end
            end
            if #PALADIN_SHENSHENG > 0 then
                BuffTask["王者"] = PALADIN_SHENSHENG[1]
                tremove(PALADIN_SHENSHENG, 1)
            elseif #PALADIN_CHENGJIE > 0 then
                BuffTask["王者"] = PALADIN_CHENGJIE[1]
                tremove(PALADIN_CHENGJIE, 1)
            elseif #PALADIN_FANGHU > 0 then
                BuffTask["王者"] = PALADIN_FANGHU[1]
                tremove(PALADIN_FANGHU, 1)
            end
        elseif PALADIN_Counts == 3 then
            if #PALADIN_FANGHU > 0 then
                for index, name in ipairs(PALADIN_FANGHU) do
                    if playerInfo[name]["庇护祝福"] then
                        BuffTask["庇护"] = name
                        tremove(PALADIN_FANGHU, index)
                        break
                    end
                end
            end
            if BuffTask["庇护"] then
                if #PALADIN_SHENSHENG > 0 then
                    for index, name in ipairs(PALADIN_SHENSHENG) do
                        if playerInfo[name]["强化智慧祝福"] then
                            BuffTask["智慧"] = name
                            BuffTask["力量"] = name
                            tremove(PALADIN_SHENSHENG, index)
                            break
                        end
                    end
                elseif #PALADIN_CHENGJIE > 0 then
                    for index, name in ipairs(PALADIN_CHENGJIE) do
                        if playerInfo[name]["强化力量祝福"] then
                            BuffTask["智慧"] = name
                            BuffTask["力量"] = name
                            tremove(PALADIN_CHENGJIE, index)
                            break
                        end
                    end
                end
                if not BuffTask["智慧"] then
                    if #PALADIN_SHENSHENG > 0 then
                        BuffTask["智慧"] = PALADIN_SHENSHENG[1]
                        BuffTask["力量"] = PALADIN_SHENSHENG[1]
                        tremove(PALADIN_SHENSHENG, 1)
                    elseif #PALADIN_CHENGJIE > 0 then
                        BuffTask["智慧"] = PALADIN_CHENGJIE[1]
                        BuffTask["力量"] = PALADIN_CHENGJIE[1]
                        tremove(PALADIN_CHENGJIE, 1)
                    elseif #PALADIN_FANGHU > 0 then
                        BuffTask["智慧"] = PALADIN_FANGHU[1]
                        BuffTask["力量"] = PALADIN_FANGHU[1]
                        tremove(PALADIN_FANGHU, 1)
                    end
                end
                if #PALADIN_SHENSHENG > 0 then
                    BuffTask["王者"] = PALADIN_SHENSHENG[1]
                    tremove(PALADIN_SHENSHENG, 1)
                elseif #PALADIN_CHENGJIE > 0 then
                    BuffTask["王者"] = PALADIN_CHENGJIE[1]
                    tremove(PALADIN_CHENGJIE, 1)
                elseif #PALADIN_FANGHU > 0 then
                    BuffTask["王者"] = PALADIN_FANGHU[1]
                    tremove(PALADIN_FANGHU, 1)
                end
            else
                if #PALADIN_SHENSHENG > 0 then
                    local zhiHuiIndex
                    for index, name in ipairs(PALADIN_SHENSHENG) do
                        if playerInfo[name]["强化智慧祝福"] then
                            zhiHuiIndex = index
                            break
                        end
                    end
                    zhiHuiIndex = zhiHuiIndex or 1
                    BuffTask["智慧"] = PALADIN_SHENSHENG[zhiHuiIndex]
                    tremove(PALADIN_SHENSHENG, zhiHuiIndex)
                end
                if #PALADIN_CHENGJIE > 0 then
                    local liLiangIndex
                    for index, name in ipairs(PALADIN_CHENGJIE) do
                        if playerInfo[name]["强化力量祝福"] then
                            liLiangIndex = index
                            break
                        end
                    end
                    liLiangIndex = liLiangIndex or 1
                    BuffTask["力量"] = PALADIN_CHENGJIE[liLiangIndex]
                    tremove(PALADIN_CHENGJIE, liLiangIndex)
                end
                if not BuffTask["智慧"] then
                    --说明没有NQ，从CJ和FQ里面找
                    if #PALADIN_CHENGJIE > 0 then
                        BuffTask["智慧"] = PALADIN_CHENGJIE[1]
                        tremove(PALADIN_CHENGJIE, 1)
                    else
                        if #PALADIN_FANGHU > 0 then
                            BuffTask["智慧"] = PALADIN_FANGHU[1]
                            tremove(PALADIN_FANGHU, 1)
                        end
                    end
                end
                if not BuffTask["力量"] then
                    if #PALADIN_SHENSHENG > 0 then
                        BuffTask["力量"] = PALADIN_SHENSHENG[1]
                        tremove(PALADIN_SHENSHENG, 1)
                    else
                        if #PALADIN_FANGHU > 0 then
                            BuffTask["力量"] = PALADIN_FANGHU[1]
                            tremove(PALADIN_FANGHU, 1)
                        end
                    end
                end
                if #PALADIN_SHENSHENG > 0 then
                    BuffTask["王者"] = PALADIN_SHENSHENG[1]
                    tremove(PALADIN_SHENSHENG, 1)
                elseif #PALADIN_CHENGJIE > 0 then
                    BuffTask["王者"] = PALADIN_CHENGJIE[1]
                    tremove(PALADIN_CHENGJIE, 1)
                elseif #PALADIN_FANGHU > 0 then
                    BuffTask["王者"] = PALADIN_FANGHU[1]
                    tremove(PALADIN_FANGHU, 1)
                end
            end
        elseif PALADIN_Counts >= 4 then
            if #PALADIN_FANGHU > 0 then
                for index, name in ipairs(PALADIN_FANGHU) do
                    if playerInfo[name]["庇护祝福"] then
                        BuffTask["庇护"] = name
                        tremove(PALADIN_FANGHU, index)
                        break
                    end
                end
            end
            if #PALADIN_SHENSHENG > 0 then
                local zhiHuiIndex
                for index, name in ipairs(PALADIN_SHENSHENG) do
                    if playerInfo[name]["强化智慧祝福"] then
                        zhiHuiIndex = index
                        break
                    end
                end
                zhiHuiIndex = zhiHuiIndex or 1
                BuffTask["智慧"] = PALADIN_SHENSHENG[zhiHuiIndex]
                tremove(PALADIN_SHENSHENG, zhiHuiIndex)
            end
            if #PALADIN_CHENGJIE > 0 then
                local liLiangIndex
                for index, name in ipairs(PALADIN_CHENGJIE) do
                    if playerInfo[name]["强化力量祝福"] then
                        liLiangIndex = index
                        break
                    end
                end
                liLiangIndex = liLiangIndex or 1
                BuffTask["力量"] = PALADIN_CHENGJIE[liLiangIndex]
                tremove(PALADIN_CHENGJIE, liLiangIndex)
            end
            if not BuffTask["智慧"] then
                --说明没有NQ，从CJ和FQ里面找
                if #PALADIN_CHENGJIE > 0 then
                    BuffTask["智慧"] = PALADIN_CHENGJIE[1]
                    tremove(PALADIN_CHENGJIE, 1)
                else
                    if #PALADIN_FANGHU > 0 then
                        BuffTask["智慧"] = PALADIN_FANGHU[1]
                        tremove(PALADIN_FANGHU, 1)
                    end
                end
            end
            if not BuffTask["力量"] then
                if #PALADIN_SHENSHENG > 0 then
                    BuffTask["力量"] = PALADIN_SHENSHENG[1]
                    tremove(PALADIN_SHENSHENG, 1)
                else
                    if #PALADIN_FANGHU > 0 then
                        BuffTask["力量"] = PALADIN_FANGHU[1]
                        tremove(PALADIN_FANGHU, 1)
                    end
                end
            end
            if #PALADIN_SHENSHENG > 0 then
                BuffTask["王者"] = PALADIN_SHENSHENG[1]
                tremove(PALADIN_SHENSHENG, 1)
            elseif #PALADIN_CHENGJIE > 0 then
                BuffTask["王者"] = PALADIN_CHENGJIE[1]
                tremove(PALADIN_CHENGJIE, 1)
            elseif #PALADIN_FANGHU > 0 then
                BuffTask["王者"] = PALADIN_FANGHU[1]
                tremove(PALADIN_FANGHU, 1)
            end
        end

        --智力
        if #classFileList.MAGE > 0 then
            table.sort(classFileList.MAGE, function (a, b)
                return (UnitInRaid(a) or 0) < (UnitInRaid(b) or 0)
            end)
            BuffTask["智力"] = classFileList.MAGE[1]
        end
        --爪子
        if #classFileList.DRUID > 0 then
            table.sort(classFileList.DRUID, function (a, b)
                return (UnitInRaid(a) or 0) < (UnitInRaid(b) or 0)
            end)
            BuffTask["爪子"] = classFileList.DRUID[1]
        end
        ------减伤
        local index = 0
        local PRIEST_YAZHI = classFileList.PRIEST_YAZHI
        if ZL.opt.DROrderSelect == 1 then
            local PALADIN_TWO = classFileList.PALADIN_TWO
            local PALADIN_DAXISHENG = classFileList.PALADIN_DAXISHENG
            local PALADIN_GUANGZHANG = classFileList.PALADIN_GUANGZHANG
            local PRIEST_XUEGE = classFileList.PRIEST_XUEGE
            --大牺
            for _, name in ipairs(PALADIN_TWO) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][2] = name
                DRTask[index][3] = name
            end
            for _, name in ipairs(PALADIN_DAXISHENG) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][2] = name
            end
            --光掌
            index = #PALADIN_TWO
            for _, name in ipairs(PALADIN_GUANGZHANG) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][3] = name
            end
            --压制
            index = 0
            for _, name in ipairs(PRIEST_YAZHI) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][4] = name
                DRTask[index][5] = name
            end
            --血歌
            index = #PRIEST_YAZHI
            for _, name in ipairs(PRIEST_XUEGE) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][5] = name
            end
        else
            local PALADIN_DAXISHENG2 = classFileList.PALADIN_DAXISHENG2
            local PALADIN_GUANGZHANG2 = classFileList.PALADIN_GUANGZHANG2
            local PRIEST_XUEGE2 = classFileList.PRIEST_XUEGE2
            for _, name in ipairs(PALADIN_DAXISHENG2) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][2] = name
            end
            index = 0
            for _, name in ipairs(PALADIN_GUANGZHANG2) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][3] = name
            end
            --压制
            index = 0
            for _, name in ipairs(PRIEST_YAZHI) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][4] = name
            end
            --血歌
            index = 0
            for _, name in ipairs(PRIEST_XUEGE2) do
                index = index + 1
                DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
                DRTask[index][5] = name
            end
        end
        --宁静、战复
        index = 0
        for _, name in ipairs(classFileList.DRUID) do
            index = index + 1
            DRTask[index] = DRTask[index] or {ZL.numToChinese[tostring(index)] .. "减"}
            DRTask[index][6] = name
            DRTask[index][7] = name
        end
        TaskFrame:Update()
    end)
    autoArrangeBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
        GameTooltip:AddLine("提示")
        GameTooltip:AddLine("1、需在团队模式", 1, 1, 1)
        GameTooltip:AddLine("2、离线人员无法安排任务", 1, 1, 1)
        GameTooltip:Show()
    end)
    autoArrangeBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)
    TaskFrame.sendAllBtn = CreateButton(nil, TaskFrame, "一键发送 |T130940:14|t", "LEFT", autoArrangeBtn, "RIGHT", wgap, 0, width-5, height)
    local sendAllBtn = TaskFrame.sendAllBtn
    sendAllBtn.Background:SetColorTexture(0.25,0.25,0.27)
    sendAllBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
    sendAllBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
        GameTooltip:AddLine("发送")
        GameTooltip:AddLine("左键：|cffffffff发送全部任务|r")
        GameTooltip:AddLine("右键：|cffffffff按职业发送BUFF任务|r")
        GameTooltip:Show()
    end)
    sendAllBtn:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)
    sendAllBtn:SetScript("OnClick", function (self, button)
        if not IsInRaid(1) then
            ZL.Print("不在团队中！")
            return
        end
        if not (UnitIsGroupLeader("player") or UnitIsRaidOfficer("player")) then
            ZL.Print("团长或团长助理才可以通报任务！")
            return
        end
        if not ZL_PLAYERLIST.TaskList or (not next(ZL_PLAYERLIST.TaskList.BuffTask) and  #ZL_PLAYERLIST.TaskList.DRTask == 0) then
            ZL.Print("请先分配任务！")
            return
        end
        if not ZL.opt.raidChannel and not ZL.opt.whisperChannel then
            ZL.Print("未选择发送信息频道！")
            return
        end
        local TaskContent = {}
        local BuffTask = ZL_PLAYERLIST.TaskList.BuffTask
        local DRTask = ZL_PLAYERLIST.TaskList.DRTask
        if button == "LeftButton" then
            for _, buffName in ipairs(BUFFLIST) do
                if BuffTask[buffName] then
                    TaskContent[BuffTask[buffName]] = TaskContent[BuffTask[buffName]] or {}
                    local spellLink = GetSpellLink(TASKSPELLID[buffName])
                    spellLink = #spellLink > 0 and spellLink or buffName
                    tinsert(TaskContent[BuffTask[buffName]], spellLink)
                end
            end
            for index, DRName in ipairs(DRLIST) do
                for i, data in ipairs(DRTask) do
                    if data[index+1] then
                        TaskContent[data[index+1]] =TaskContent[data[index+1]] or {}
                        local spellLink = GetSpellLink(TASKSPELLID[DRName])
                        spellLink = #spellLink > 0 and spellLink or DRName
                        tinsert(TaskContent[data[index+1]], tostring(i) .. spellLink)
                    end
                end
            end
            if ZL.opt.raidChannel then
                local msgStr
                if next(ZL_PLAYERLIST.TaskList.BuffTask) and next(ZL_PLAYERLIST.TaskList.DRTask) then
                    msgStr = "{rt6}BUFF和减伤安排如下{rt6}"
                elseif not next(ZL_PLAYERLIST.TaskList.BuffTask) and next(ZL_PLAYERLIST.TaskList.DRTask) then
                    msgStr = "{rt6}减伤安排如下{rt6}"
                elseif next(ZL_PLAYERLIST.TaskList.BuffTask) and not next(ZL_PLAYERLIST.TaskList.DRTask) then
                    msgStr = "{rt6}BUFF安排如下{rt6}"
                end
                SendChatMessage(msgStr, "RAID")
                C_Timer.After(0.3, function ()
                    for playerName, taskContentData in pairs(TaskContent) do
                        local str = playerName .. "："
                        for index, content in ipairs(taskContentData) do
                            if strlen(str) + 1 + strlen(content) > 255 then
                                SendChatMessage(str, "RAID")
                                str = playerName .. "：" .. content
                            else
                                str = str .. content
                            end
                            if index == #taskContentData then
                                SendChatMessage(str, "RAID")
                            end
                        end
                    end
                end)
            end
            if ZL.opt.whisperChannel then
                local playerNameList = {}
                for playerName in pairs(TaskContent) do
                    tinsert(playerNameList, playerName)
                end
                table.sort(playerNameList)
                local index = 1
                local playerName, delay
                local function tempfunc()
                    if index <= #playerNameList then
                        playerName = playerNameList[index]
                        local isInRaid, online = playerIsInRaid(playerName)
                        if isInRaid and online then
                            local str = "你负责："
                            for i, content in ipairs(TaskContent[playerName]) do
                                if strlen(str) + 1 + strlen(content) > 255 then
                                    SendChatMessage(str, "WHISPER", nil, playerName)
                                    str = "你负责：" .. content
                                else
                                    str = str .. content
                                end
                                if i == #TaskContent[playerName] then
                                    SendChatMessage(str, "WHISPER", nil, playerName)
                                end
                            end
                            delay = 1
                        else
                            delay = 0
                        end
                        index = index + 1
                        C_Timer.After(delay, tempfunc)
                    end
                end
                tempfunc()
            end
        else
            local function tempfunc()
                return {
                    {text="按职业发送", isTitle=1},
                    {
                        text = classDic.PRIEST,
                        keepShownOnClick = 1,
                        func = function ()
                            noticeByClass("牧师", {"耐力", "精神", "暗抗"})
                        end
                    },
                    {
                        text = classDic.PALADIN,
                        keepShownOnClick = 1,
                        func = function ()
                            noticeByClass("骑士", {"王者", "智慧", "力量", "庇护"})
                        end
                    },
                    {
                        text = classDic.MAGE,
                        keepShownOnClick = 1,
                        func = function ()
                            noticeByClass("法师", {"智力"})
                        end
                    },
                    {
                        text = classDic.DRUID,
                        keepShownOnClick = 1,
                        func = function ()
                            noticeByClass("德鲁伊", {"爪子"})
                        end
                    },
                }
            end
            ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
        end
    end)

    local fontString = TaskFrame:CreateFontString(nil, "OVERLAY")
    fontString:SetPoint("TOPLEFT", zhiHuiEditBox.editBox, "BOTTOMLEFT", 0, -7)
    fontString:SetFont(GameFontNormal:GetFont(), 12, "OUTLINE")
    fontString:SetWordWrap(false)
    fontString:SetJustifyH("LEFT")
    fontString:SetJustifyV("MIDDLE")
    fontString:SetTextColor(1, 0.82, 0, 1)
    fontString:SetText("|cff4080FFShift+左键|r点击各任务图标可单独发送相应任务")

    TaskFrame.orderBtn = titleBtn("减伤顺序", "TOPLEFT", zhiHuiEditBox.editBox, "BOTTOMLEFT", 0, -25)
    local orderBtn = TaskFrame.orderBtn

    TaskFrame.daXiShengBtn = titleBtn("|T253400:14|t神圣牺牲", "LEFT", orderBtn, "RIGHT", wgap, 0)
    local daXiShengBtn = TaskFrame.daXiShengBtn
    daXiShengBtn:SetScript("OnClick", function (self)
        DRTaskNoticeOnly(2, 64205)
    end)

    TaskFrame.zhangWoBtn = titleBtn("|T135872:14|t光环掌握", "LEFT", daXiShengBtn, "RIGHT", wgap, 0)
    local zhangWoBtn = TaskFrame.zhangWoBtn
    zhangWoBtn:SetScript("OnClick", function (self)
        DRTaskNoticeOnly(3, 31821)
    end)

    TaskFrame.yaZhiBtn = titleBtn("|T135936:14|t痛苦压制", "LEFT", zhangWoBtn, "RIGHT", wgap, 0)
    local yaZhiBtn = TaskFrame.yaZhiBtn
    yaZhiBtn:SetScript("OnClick", function (self)
        DRTaskNoticeOnly(4, 33206)
    end)

    TaskFrame.xueGeBtn = titleBtn("|T237540:14|t血歌", "LEFT", yaZhiBtn, "RIGHT", wgap, 0)
    local xueGeBtn = TaskFrame.xueGeBtn
    xueGeBtn:SetScript("OnClick", function (self)
        DRTaskNoticeOnly(5, 64843)
    end)

    TaskFrame.ningJingBtn = titleBtn("|T136107:14|t宁静", "LEFT", xueGeBtn, "RIGHT", wgap, 0)
    local ningJingBtn = TaskFrame.ningJingBtn
    ningJingBtn:SetScript("OnClick", function (self)
        DRTaskNoticeOnly(6, 740)
    end)

    TaskFrame.zhanFuBtn = titleBtn("|T136080:14|t战复", "LEFT", ningJingBtn, "RIGHT", wgap, 0)
    local zhanFuBtn = TaskFrame.zhanFuBtn
    zhanFuBtn:SetScript("OnClick", function (self)
        DRTaskNoticeOnly(7, 20484)
    end)

    TaskFrame.entries = setmetatable({}, {
        __index = function (t, v)
            local f = CreateFrame("Button", nil, TaskFrame)
            if v == 1 then
                f:SetPoint("TOPLEFT", orderBtn, "BOTTOMLEFT", 0, -hgap)
                f:SetPoint("TOPRIGHT", zhanFuBtn, "BOTTOMRIGHT", 0, -hgap)
            else
                f:SetPoint("TOPLEFT", t[v-1], "BOTTOMLEFT", 0, -hgap)
                f:SetPoint("TOPRIGHT", t[v-1], "BOTTOMRIGHT", 0, -hgap)
            end
            f:SetHeight(height)

            f.orderbox = CreateEditBox(f, width, height, 14, "CENTER")
            f.orderbox:SetPoint("LEFT", f, "LEFT")
            f.orderbox:Disable()

            f.daXiShengbox = CreateEditBox(f, width, height, 14, "CENTER")
            f.daXiShengbox:SetPoint("LEFT", f.orderbox, "RIGHT", wgap, 0)
            f.daXiShengbox:Disable()
            f.daXiShengbox:SetScript("OnMouseDown", function (self)
                if IsInRaid(1) and ZL_CURRENT.playerInfo then
                    local playerInfo = ZL_CURRENT.playerInfo
                    local function tempfunc()
                        local menuList = {}
                        for i = 1, MAX_RAID_MEMBERS do
                            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                            if name and playerInfo[name] and playerInfo[name][DRLIST[1]] then
                                local colorName = GetClassColorName(name, fileName)
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = colorName
                                        if playerInfo[name]["光环掌握"] then
                                            tex = tex .. "|T135872:12|t"
                                        end
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = self.playerName == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.DRTask[f.row][2] = name
                                        self:SetText(colorName)
                                        self.playerName = name
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        end
                        if #self:GetText() > 0 then
                            if #menuList > 0 then
                                tinsert(menuList, {isSeparator=1})
                            end
                            tinsert(menuList, {
                                text = "|CFFFFDE00清除|r",
                                func = function ()
                                    ZL_PLAYERLIST.TaskList.DRTask[f.row][2] = nil
                                    self:SetText("")
                                    self.playerName = nil
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            f.zhangWobox = CreateEditBox(f, width, height, 14, "CENTER")
            f.zhangWobox:SetPoint("LEFT", f.daXiShengbox, "RIGHT", wgap, 0)
            f.zhangWobox:Disable()
            f.zhangWobox:SetScript("OnMouseDown", function (self)
                if IsInRaid(1) and ZL_CURRENT.playerInfo then
                    local playerInfo = ZL_CURRENT.playerInfo
                    local function tempfunc()
                        local menuList = {}
                        for i = 1, MAX_RAID_MEMBERS do
                            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                            if name and playerInfo[name] and playerInfo[name][DRLIST[2]] then
                                local colorName = GetClassColorName(name, fileName)
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = colorName
                                        if playerInfo[name]["光环掌握"] then
                                            tex = tex .. "|T253400:12|t"
                                        end
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = self.playerName == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.DRTask[f.row][3] = name
                                        self:SetText(colorName)
                                        self.playerName = name
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        end
                        if #self:GetText() > 0 then
                            if #menuList > 0 then
                                tinsert(menuList, {isSeparator=1})
                            end
                            tinsert(menuList, {
                                text = "|CFFFFDE00清除|r",
                                func = function ()
                                    ZL_PLAYERLIST.TaskList.DRTask[f.row][3] = nil
                                    self:SetText("")
                                    self.playerName = nil
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            f.yaZhibox = CreateEditBox(f, width, height, 14, "CENTER")
            f.yaZhibox:SetPoint("LEFT", f.zhangWobox, "RIGHT", wgap, 0)
            f.yaZhibox:Disable()
            f.yaZhibox:SetScript("OnMouseDown", function (self)
                if IsInRaid(1) and ZL_CURRENT.playerInfo then
                    local playerInfo = ZL_CURRENT.playerInfo
                    local function tempfunc()
                        local menuList = {}
                        for i = 1, MAX_RAID_MEMBERS do
                            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                            if name and playerInfo[name] and playerInfo[name][DRLIST[3]] then
                                local colorName = GetClassColorName(name, fileName)
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = colorName
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = self.playerName == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.DRTask[f.row][4] = name
                                        self:SetText(colorName)
                                        self.playerName = name
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        end
                        if #self:GetText() > 0 then
                            if #menuList > 0 then
                                tinsert(menuList, {isSeparator=1})
                            end
                            tinsert(menuList, {
                                text = "|CFFFFDE00清除|r",
                                func = function ()
                                    ZL_PLAYERLIST.TaskList.DRTask[f.row][4] = nil
                                    self:SetText("")
                                    self.playerName = nil
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            f.xueGebox = CreateEditBox(f, width, height, 14, "CENTER")
            f.xueGebox:SetPoint("LEFT", f.yaZhibox, "RIGHT", wgap, 0)
            f.xueGebox:Disable()
            f.xueGebox:SetScript("OnMouseDown", function (self)
                if IsInRaid(1) then
                    local function tempfunc()
                        local menuList = {}
                        for i = 1, MAX_RAID_MEMBERS do
                            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                            if name and fileName == "PRIEST" then
                                local colorName = GetClassColorName(name, fileName)
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = colorName
                                        if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name]["痛苦压制"] then
                                            tex = tex .. "|T135936:12|t"
                                        end
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = self.playerName == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.DRTask[f.row][5] = name
                                        self:SetText(colorName)
                                        self.playerName = name
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        end
                        if #self:GetText() > 0 then
                            if #menuList > 0 then
                                tinsert(menuList, {isSeparator=1})
                            end
                            tinsert(menuList, {
                                text = "|CFFFFDE00清除|r",
                                func = function ()
                                    ZL_PLAYERLIST.TaskList.DRTask[f.row][5] = nil
                                    self:SetText("")
                                    self.playerName = nil
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            f.ningJingbox = CreateEditBox(f, width, height, 14, "CENTER")
            f.ningJingbox:SetPoint("LEFT", f.xueGebox, "RIGHT", wgap, 0)
            f.ningJingbox:Disable()
            f.ningJingbox:SetScript("OnMouseDown", function (self)
                if IsInRaid(1) then
                    local function tempfunc()
                        local menuList = {}
                        for i = 1, MAX_RAID_MEMBERS do
                            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                            if name and fileName == "DRUID" then
                                local colorName = GetClassColorName(name, fileName)
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = colorName
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = self.playerName == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.DRTask[f.row][6] = name
                                        self:SetText(colorName)
                                        self.playerName = name
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        end
                        if #self:GetText() > 0 then
                            if #menuList > 0 then
                                tinsert(menuList, {isSeparator=1})
                            end
                            tinsert(menuList, {
                                text = "|CFFFFDE00清除|r",
                                func = function ()
                                    ZL_PLAYERLIST.TaskList.DRTask[f.row][6] = nil
                                    self:SetText("")
                                    self.playerName = nil
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            f.zhanFubox = CreateEditBox(f, width, height, 14, "CENTER")
            f.zhanFubox:SetPoint("LEFT", f.ningJingbox, "RIGHT", wgap, 0)
            f.zhanFubox:Disable()
            f.zhanFubox:SetScript("OnMouseDown", function (self)
                if IsInRaid(1) then
                    local function tempfunc()
                        local menuList = {}
                        for i = 1, MAX_RAID_MEMBERS do
                            local name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                            if name and fileName == "DRUID" then
                                local colorName = GetClassColorName(name, fileName)
                                tinsert(menuList, {
                                    text = function ()
                                        local tex = colorName
                                        if not online then
                                            tex = tex .. "|cffff0000(离线)|r"
                                        end
                                        return tex
                                    end,
                                    checkable = 1,
                                    keepShownOnClick = 1,
                                    checked = self.playerName == name,
                                    func = function ()
                                        ZL_PLAYERLIST.TaskList = ZL_PLAYERLIST.TaskList or {DRTask={}, BuffTask={}}
                                        ZL_PLAYERLIST.TaskList.DRTask[f.row][7] = name
                                        self:SetText(colorName)
                                        self.playerName = name
                                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                    end
                                })
                            end
                        end
                        if #self:GetText() > 0 then
                            if #menuList > 0 then
                                tinsert(menuList, {isSeparator=1})
                            end
                            tinsert(menuList, {
                                text = "|CFFFFDE00清除|r",
                                func = function ()
                                    ZL_PLAYERLIST.TaskList.DRTask[f.row][7] = nil
                                    self:SetText("")
                                    self.playerName = nil
                                    ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                                end
                            })
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            t[v] = f
            return f
        end
    })

    function TaskFrame:Update()
        local totalHeight = 193
        for _, f in ipairs(TaskFrame.entries) do f:Hide() end
        if ZL_PLAYERLIST.TaskList then
            local BuffTask = ZL_PLAYERLIST.TaskList.BuffTask
            local DRTask = ZL_PLAYERLIST.TaskList.DRTask
            local playerInfo = ZL_CURRENT.playerInfo
            naiLiEditBox.editBox:SetText(BuffTask["耐力"] and playerInfo[BuffTask["耐力"]].colorName or "")
            jingShenEditBox.editBox:SetText(BuffTask["精神"] and playerInfo[BuffTask["精神"]].colorName or "")
            anKangEditBox.editBox:SetText(BuffTask["暗抗"] and playerInfo[BuffTask["暗抗"]].colorName or "")
            wangZheEditBox.editBox:SetText(BuffTask["王者"] and playerInfo[BuffTask["王者"]].colorName or "")
            zhiHuiEditBox.editBox:SetText(BuffTask["智慧"] and playerInfo[BuffTask["智慧"]].colorName or "")
            liLiangEditBox.editBox:SetText(BuffTask["力量"] and playerInfo[BuffTask["力量"]].colorName or "")
            biHuEditBox.editBox:SetText(BuffTask["庇护"] and playerInfo[BuffTask["庇护"]].colorName or "")
            zhiLiEditBox.editBox:SetText(BuffTask["智力"] and playerInfo[BuffTask["智力"]].colorName or "")
            zhuaZiEditBox.editBox:SetText(BuffTask["爪子"] and playerInfo[BuffTask["爪子"]].colorName or "")
            for row, rowData in ipairs(DRTask) do
                local f = TaskFrame.entries[row]
                f.row = row
                f.orderbox:SetText(rowData[1] or "")
                f.daXiShengbox:SetText(rowData[2] and playerInfo[rowData[2]].colorName or "")
                f.daXiShengbox.playerName = rowData[2]
                f.zhangWobox:SetText(rowData[3] and playerInfo[rowData[3]].colorName or "")
                f.zhangWobox.playerName = rowData[3]
                f.yaZhibox:SetText(rowData[4] and playerInfo[rowData[4]].colorName or "")
                f.yaZhibox.playerName = rowData[4]
                f.xueGebox:SetText(rowData[5] and playerInfo[rowData[5]].colorName or "")
                f.xueGebox.playerName = rowData[5]
                f.ningJingbox:SetText(rowData[6] and playerInfo[rowData[6]].colorName or "")
                f.ningJingbox.playerName = rowData[6]
                f.zhanFubox:SetText(rowData[7] and playerInfo[rowData[7]].colorName or "")
                f.zhanFubox.playerName = rowData[7]
                f:Show()
                totalHeight = totalHeight + height + hgap
            end
        else
            naiLiEditBox.editBox:SetText("")
            jingShenEditBox.editBox:SetText("")
            anKangEditBox.editBox:SetText("")
            wangZheEditBox.editBox:SetText("")
            zhiHuiEditBox.editBox:SetText("")
            liLiangEditBox.editBox:SetText("")
            biHuEditBox.editBox:SetText("")
            zhiLiEditBox.editBox:SetText("")
            zhuaZiEditBox.editBox:SetText("")
        end
        totalHeight = totalHeight > 328 and totalHeight or 328
        TaskFrame:SetHeight(totalHeight)
    end

    TaskFrame:RegisterEvent("CHAT_MSG_RAID")
    TaskFrame:RegisterEvent("CHAT_MSG_RAID_LEADER")
    TaskFrame:RegisterEvent("CHAT_MSG_RAID_WARNING")
    TaskFrame:SetScript("OnEvent", function (self, event, ...)
        local arg = ZL.emptytable(...)
        if event == "CHAT_MSG_RAID" or event == "CHAT_MSG_RAID_LEADER" or "CHAT_MSG_RAID_WARNING" then
            if not (ZL_PLAYERLIST.TaskList and next(ZL_PLAYERLIST.TaskList.BuffTask)) then return end
            if not (ZL_PLAYERLIST.autoNotice and next(ZL_PLAYERLIST.autoNotice)) then return end
            local msg, sender = string.upper(arg[1]), ZL.pruneCrossRealm(arg[2])
            local reporter, group, fileName
            local tempList = {}
            for i = 1, MAX_RAID_MEMBERS do
                local name, _, subgroup, _, _, _fileName, _, online = GetRaidRosterInfo(i)
                if name then
                    if name == sender then
                        group = subgroup
                        fileName = _fileName
                    end
                    if online and ZL_PLAYERLIST.autoNotice[name] then
                        tinsert(tempList, name)
                    end
                end
            end
            if #tempList > 1 then
                table.sort(tempList, function (a, b)
                    local aIsLeader = UnitIsGroupLeader(a)
                    local bIsLeader = UnitIsGroupLeader(b)
                    if aIsLeader and not bIsLeader then
                        return true
                    elseif not aIsLeader and bIsLeader then
                        return false
                    end
                    local aIsML = PlayerIsML(a)
                    local bIsML = PlayerIsML(b)
                    if aIsML and not bIsML then
                        return true
                    elseif not aIsML and bIsML then
                        return false
                    end
                    return a < b
                end)
            end
            reporter = tempList[1]
            reporter = "潇湘凌风"
            tempList = nil
            if reporter == UnitName("player") then
                local buffList = {}
                if not filterBuffKeyIsExist(msg) and (strfind(msg, "BUFF") or  buffKeyIsExist(msg)) then
                    buffList = CLASSBUFF[fileName]
                    if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[sender] then
                        local activeTalent = ZL_CURRENT.playerInfo[sender].newTalentName
                        if activeTalent == "防护" or activeTalent == "惩戒" or activeTalent == "野性坦克" or
                        activeTalent == "野性输出" or activeTalent == "增强" then
                            tinsert(buffList, "力量")
                        end
                    end
                end
                if #buffList > 0 then
                    for i = 1, 50 do
                        local playerBuffName, _, _, _, _, expirationTime = UnitBuff(sender, i)
                        local buffName = BUFFNAMEDIC[playerBuffName]
                        if buffName and (expirationTime - GetTime()) > 300 then  --大于5分钟的不重新加
                            tDeleteItem(buffList, buffName)
                        end
                    end
                end
                if #buffList > 0 then
                    local buffContent = {}
                    for _, buffName in ipairs(buffList) do
                        local taskPlayerName = ZL_PLAYERLIST.TaskList.BuffTask[buffName]
                        if taskPlayerName then
                            local raidIndex, online = playerIsInRaid(taskPlayerName)
                            if raidIndex and online then
                                buffContent[taskPlayerName] = buffContent[taskPlayerName] or {}
                                tinsert(buffContent[taskPlayerName], buffName)
                            end
                        end
                    end
                    if next(buffContent) then
                        local tempList2 = {}
                        for name in pairs(buffContent) do
                            tinsert(tempList2, name)
                        end
                        local nameIndex = 1
                        local function tempfunc()
                            if nameIndex <= #tempList2 then
                                local name = tempList2[nameIndex]
                                SendChatMessage(
                                    format("%d队>>>%s<<<缺少%s，请及时补BUFF", group, sender, table.concat(buffContent[name], "，")),
                                    "WHISPER", nil, name
                                )
                                nameIndex = nameIndex + 1
                                C_Timer.After(1, tempfunc)
                            end
                        end
                        tempfunc()
                    end
                end
            end
        end
        arg:Release()
    end)
end


