追踪多个敌人单位的魔兽世界弱点提示插件。

在《魔兽世界》中,我一直在制作一个 Weakaura,用于追踪玩家击杀的敌对单位数量。其中一个主要问题是,在小组中时,“COMBAT_LOG_EVENT_UNFILTERED”强制光环在小组中的任何人执行动作时都会触发,这可能会导致很多掉帧。我能够找到的另一种选择是“COMBAT_LOG_EVENT”,然而,它不会在敌人死亡时触发,因此不会从列表中移除。

我的问题是:有没有办法在除 UI 线程之外的线程上收集此数据,以防止掉帧?在另一个线程中收集此数据时,数据能否用于向用户显示信息?

以下是当前使用的触发器(这些都按预期工作):

触发器1:

类型-自定义

事件类型-事件

事件- COMBAT_LOG_EVENT_UNFILTERED

Custom Trigger:

function(...)
    ADDS = ADDS or {}; -- Where enemy units are stored

    local _, _, event, _, src, _, _, _, dest, _, _, _ = select(1, ...);
    local player = UnitGUID("player");

    -- Attempts to only read data coming from the player casting harmful abilities
    if ((event == "SPELL_DAMAGE") and (src == player)) then

        -- Checks if the enemy unit is already being tracked and that it is NOT
        -- a part of your group (prevents friendly fire events from adding a friendly
        -- unit to this list)
        if ((not tContains(ADDS, dest)) and (not tContains(GROUP, dest))) then
            table.insert(ADDS, dest);
        end
    elseif event=="UNIT_DIED" then -- Remove a unit if it has died
        for i = #ADDS, 1, -1 do
            if ADDS[i] == dest then
                table.remove(ADDS, i);
            end
        end
    end

    return true;
end

上述代码块是掉帧的原因。下一个触发器仅用于在战斗开始或结束时重置列表(相当确定此块中没有导致掉帧的东西,但还是想包括它以防万一):

触发器2:

类型-自定义

事件类型-事件

事件- PLAYER_REGEN_DISABLED,PLAYER_REGEN_ENABLED

function(...)
    GROUP = GROUP or {};

    local size = GetNumGroupMembers();

    if (size == 0) then
        GROUP = {};
    end

    if (size ~= #GROUP and size ~= 0) then
        for i = 1, size do
            local name = GetRaidRosterInfo(i);

            if (name ~= nil) then
                local guid = UnitGUID(name);

                if (not tContains(GROUP, guid)) then
                    table.insert(GROUP, guid);
                end
            end
        end
    end

    ADDS = {};
    return true;
end
点赞