⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countdoomspelltimer.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
end


function CDTimerSpell_CreateBySpellAbbreviation( spellAbbreviation, targetInfo, in_rank )
    CountDoom.DebugPrint( "CDTimerSpell_CreateBySpellAbbreviation( " .. CountDoom.ToString( spellAbbreviation ) .. ")" );
    
    local spellIndex = -1;
    local replacedASpell = false;
    
    if CountDoomSpell.IsEnabled( spellAbbreviation ) ~= true then
        return -1, replacedASpell;
    end

    --See if the spell is already on our target
    local targetName = targetInfo.targetName;
    local targetLevel = targetInfo.targetLevel;
    local targetID = targetInfo.id;
    
    --If we're replacing a spell such as a curse, delete the old one
    for spellIndex = 0, CDTimerSpell_numSpells - 1 do
        if (CDTimerSpells[ spellIndex ].type == CountDoomSpell[ spellAbbreviation ].type ) and
            CDTimerSpells[ spellIndex ].targetName == targetName and
            CDTimerSpells[ spellIndex ].targetLevel == targetLevel then
            if CountDoomSpell[ spellAbbreviation ].replacesSameType then
        		CDTimerSpell_DeleteIndex( spellIndex );
		        replacedASpell = true;
            end
            break;
        end
    end
    
    spellIndex = CDTimerSpell_numSpells;
    CDTimerSpell_numSpells = CDTimerSpell_numSpells + 1;
        
    if CDTimerSpells[ spellIndex ] == nil then
        CDTimerSpells[ spellIndex ] = {};
    end

    --if rank was passed in as nil, use max rank    
    local rank = in_rank;
    if rank == nil then
        rank = 10;
    end;
    
    --determine duration
    local duration = nil;

    if CountDoomSpell[ spellAbbreviation ] ~= nil then
        duration = CountDoomSpell[ spellAbbreviation ].rankDuration[ rank ];
    end;
    
    while duration == nil and rank > 0 do
        rank = rank - 1;
        duration = CountDoomSpell[ spellAbbreviation ].rankDuration[ rank ];
    end
    
    local warningTime = duration - CountDoomSpell[ spellAbbreviation ].warningTime;
    local icon = CountDoomSpell[ spellAbbreviation ].icon;
    local type = CountDoomSpell[ spellAbbreviation ].type;
    
    -- Give unique spellIDs to each spell.
    local spellID = CDTimerSpell_spellID;
    CDTimerSpell_spellID = CDTimerSpell_spellID + 1;
    if CDTimerSpell_spellID > 1000 then
        CDTimerSpell_spellID = 0;
    end
    
    local timerIndex = CDTimer_Create( CDTIMERPRIORITY_MEDIUM, duration );
    CDTimerSpells[ spellIndex ].timerIndex          = timerIndex;    
    CDTimerSpells[ spellIndex ].warningHit          = false;
    CDTimerSpells[ spellIndex ].spellAbbreviation   = spellAbbreviation;
    CDTimerSpells[ spellIndex ].announceWarning     = CountDoomSpell[ spellAbbreviation ].announceWarning;
    CDTimerSpells[ spellIndex ].announceEnd         = CountDoomSpell[ spellAbbreviation ].announceEnd;

    CDTimerSpells[ spellIndex ].warningSound        = CountDoom.config.warningSound[ spellAbbreviation ];
    CDTimerSpells[ spellIndex ].endSound            = CountDoom.config.endSound[ spellAbbreviation ];
    
    CDTimerSpells[ spellIndex ].targetName          = targetName;
    CDTimerSpells[ spellIndex ].targetLevel         = targetLevel;
    CDTimerSpells[ spellIndex ].targetID            = targetID;
    CDTimerSpells[ spellIndex ].spellID             = spellID;
    CDTimerSpells[ spellIndex ].type                = type;

    if CountDoom.config.layout == "textonly" then
        local timerString = CDTimerSpell_CreateTimerString(spellIndex);
        CDTimer_SetTimerSuffix( timerIndex, timerString );
    end
    
    CDTimer_SetUserHandle( timerIndex, spellIndex );
    CDTimer_SetWarningTime( timerIndex, warningTime );
    CDTimer_SetCountDown( timerIndex, CountDoomSpell[ spellAbbreviation ].countDown );
    CDTimer_SetFunctionHandler( timerIndex, CDTIMEREVENT_ONTIMERWARNING, CDTimerSpell_OnTimerWarning );
    CDTimer_SetFunctionHandler( timerIndex, CDTIMEREVENT_ONTIMEREND, CDTimerSpell_OnTimerEnd );
    CDTimer_SetFunctionHandler( timerIndex, CDTIMEREVENT_ONMOVETIMER, CDTimerSpell_OnTimerMove );
    CDTimer_SetFunctionHandler( timerIndex, CDTIMEREVENT_ONCLICK, CDTimerSpell_OnTimerClick );
    CDTimer_SetFunctionHandler( timerIndex, CDTIMEREVENT_ONENTER, CDTimerSpell_OnEnter );
    CDTimer_SetIcon( timerIndex, icon );
    
    CDTimerSpell_DumpAll();

    return spellID, replacedASpell;
end


function CDTimerSpell_CreateBySpellName( spellName, targetInfo, rank )
    CountDoom.DebugPrint( "CDTimerSpell_CreateBySpellName(" .. CountDoom.ToString( spellName ) .. ")" );

    -- Enslave Demon is detected differently than the rest of the Warlock spells.
    -- It relies on a change on event in pet status
    if spellName == COUNTDOOMSPELL_ENSLAVEDEMON then
        return -1;
    end

    local spellAbbreviation = CountDoomSpellMapping[ spellName ];
    if spellAbbreviation ~= nil then
        return CDTimerSpell_CreateBySpellAbbreviation( spellAbbreviation, targetInfo, rank );
    end

    return -1, false;
end


function CDTimerSpell_DeleteIndex( spellIndex )
    CountDoom.DebugPrint( "CDTimerSpell_DeleteIndex(" .. CountDoom.ToString( spellIndex ) .. ")" );
    
    if spellIndex >= CDTimerSpell_numSpells then
        CountDoom.DebugPrint( "Invalid param CDTimerSpell_DeleteIndex(" .. spellIndex .. ")" );
        return;
    end

    -- Destroy the timer associated with the spell
    CDTimer_Destroy( CDTimerSpells[ spellIndex ].timerIndex );
    
    -- Collapse the array table by removing the deleted spell
    local srcIndex;
    for srcIndex = spellIndex + 1, CDTimerSpell_numSpells - 1do
        local dstIndex = srcIndex - 1;
        CDTimerSpells[ dstIndex ].timerIndex        = CDTimerSpells[ srcIndex ].timerIndex;    
        CDTimerSpells[ dstIndex ].warningHit        = CDTimerSpells[ srcIndex ].warningHit;
        CDTimerSpells[ dstIndex ].spellAbbreviation = CDTimerSpells[ srcIndex ].spellAbbreviation;
        CDTimerSpells[ dstIndex ].announceWarning   = CDTimerSpells[ srcIndex ].announceWarning;
        CDTimerSpells[ dstIndex ].warningSound      = CDTimerSpells[ srcIndex ].warningSound;
        CDTimerSpells[ dstIndex ].announceEnd       = CDTimerSpells[ srcIndex ].announceEnd;
        CDTimerSpells[ dstIndex ].endSound          = CDTimerSpells[ srcIndex ].endSound;
        CDTimerSpells[ dstIndex ].targetName        = CDTimerSpells[ srcIndex ].targetName;
        CDTimerSpells[ dstIndex ].targetLevel       = CDTimerSpells[ srcIndex ].targetLevel;
        CDTimerSpells[ dstIndex ].targetID          = CDTimerSpells[ srcIndex ].targetID;
        CDTimerSpells[ dstIndex ].spellID           = CDTimerSpells[ srcIndex ].spellID;
        CDTimerSpells[ dstIndex ].type              = CDTimerSpells[ srcIndex ].type;
                
        CDTimer_SetUserHandle( CDTimerSpells[ dstIndex ].timerIndex, dstIndex );
    end
    
    -- Update spell count
    CDTimerSpell_numSpells = CDTimerSpell_numSpells - 1; 
    
    -- Erase the last spell
    CDTimerSpells[ CDTimerSpell_numSpells ] = nil;
    
    -- Dump all spells in debug mode
    CDTimerSpell_DumpAll();
end


function CDTimerSpell_DeleteID( spellID )
    CountDoom.DebugPrint( "CDTimerSpell_DeleteID(" .. CountDoom.ToString( spellID ) .. ")" );

    local matchingIndex = -1;
    local spellIndex;
    for spellIndex = 0, CDTimerSpell_numSpells - 1 do
        if CDTimerSpells[ spellIndex ].spellID == spellID then
            matchingIndex = spellIndex;
            break;
        end
    end
    
    if matchingIndex ~= -1 then
        CDTimerSpell_DeleteIndex( matchingIndex );
    end
end


function CDTimerSpell_DeleteTarget( targetID )
    CountDoom.DebugPrint( "CDTimerSpell_DeleteID(" .. CountDoom.ToString( targetID ) .. ")" );

    local matchingIndex = -1;
    local spellIndex;
    for spellIndex = 0, CDTimerSpell_numSpells - 1 do
        if CDTimerSpells[ spellIndex ].targetID == targetID then
            matchingIndex = spellIndex;
            break;
        end
    end
    
    if matchingIndex ~= -1 then
        CDTimerSpell_DeleteIndex( matchingIndex );
        return true;
    end
    return false;
end


function CDTimerSpell_DestroyBySpellAbbreviation( spellAbbreviation )
    local found = false;
    
    CountDoom.DebugPrint( "CDTimerSpell_DestroyBySpellAbbreviation(" .. CountDoom.ToString( spellAbbreviation ) .. " )" );
    
    -- Look for the spell in question
    local foundIndex = 0;
    local spellIndex;
    for spellIndex = 0, CDTimerSpell_numSpells - 1 do
        if CDTimerSpells[ spellIndex ].spellAbbreviation == spellAbbreviation then
            CountDoom.DebugPrint( "[spellIndex]: " .. CDTimerSpells[ spellIndex ].spellAbbreviation );
            CountDoom.DebugPrint( "spellAbbr: " .. spellAbbreviation );
            found = true;
            foundIndex = spellIndex;
            break;
        end
    end
    
    if not found then
        CountDoom.DebugPrint( "Attempting to delete a spell not found: " .. spellAbbreviation );
        return;
    end
    
    CountDoom.DebugPrint( CountDoom.ToString( found ) .. " " .. CountDoom.ToString( foundIndex ) .. ": " .. CountDoom.ToString( CDTimerSpells[ foundIndex ].spellAbbreviation ) );
    
    -- Collapsed the spell table into a contiguous array
    CDTimerSpell_DeleteIndex( foundIndex );
end


function CDTimerSpell_DestroyBySpellName( spellName )
    CountDoom.DebugPrint( "CDTimerSpell_DestroyBySpellName(" .. CountDoom.ToString( spellName ) .. " )" );
    
    local spellAbbreviation = CountDoomSpellMapping[ spellName ];
    if spellAbbreviation ~= nil then
        CDTimerSpell_DestroyBySpellAbbreviation( spellAbbreviation );
    end
end


function CDTimerSpell_GetSpellName( spellIndex )
    if CDTimerSpells[ spellIndex ] ~= nil then
        local spellAbbreviation = CDTimerSpells[ spellIndex ].spellAbbreviation;
        if spellAbbreviation ~= nil and CountDoomSpell[ spellAbbreviation ] ~= nil then
            return CountDoomSpell[ spellAbbreviation ].text;
        end
    end
    
    return nil;
end


function CDTimerSpell_RemoveCombatSpellTimers()
    local spellIndex;

    for spellIndex = CDTimerSpell_numSpells - 1, 0, -1 do
        local spellAbbreviation = CDTimerSpells[ spellIndex ].spellAbbreviation;
        CountDoom.DebugPrint( "Checking for combat removal: " .. spellAbbreviation );
        if CountDoomSpell[ spellAbbreviation ].combatOnly then
            CDTimerSpell_DeleteIndex( spellIndex );
        end
    end
end


function CDTimerSpell_UpdateSpellPrefixes()
    local spellIndex;

    for spellIndex = 0, CDTimerSpell_numSpells - 1 do
        local timerIndex = CDTimerSpells[ spellIndex ].timerIndex;
        if CountDoom.config.layout == "textonly" then
            local timerString = CDTimerSpell_CreateTimerString(spellIndex);
            CDTimer_SetTimerSuffix( timerIndex, timerString );
        else
            CDTimer_SetTimerSuffix( timerIndex, nil );
        end
    end
end


function TargetHasMyDebuff(spellAbbreviation)
    local spellIndex = 0;
    local TimerSpell_numSpells = CDTimerSpell_numSpells - 1;
    CountDoom.DebugPrint(CDTimerSpell_numSpells.." Spells." );
    for spellIndex = 0, TimerSpell_numSpells do
--    CountDoom.DebugPrint(CDTimerSpells[ spellIndex ].targetName.."--"..UnitName("target"));
--    CountDoom.DebugPrint(CDTimerSpells[ spellIndex ].spellAbbreviation.."--"..spellAbbreviation);
--    CountDoom.DebugPrint(CDTimerSpells[ spellIndex ].targetLevel.."--"..UnitLevel("target"));
        if CDTimerSpells[ spellIndex ].targetName == UnitName("target") and
           CDTimerSpells[ spellIndex ].spellAbbreviation == spellAbbreviation and
           CDTimerSpells[ spellIndex ].targetLevel == UnitLevel("target") then
           return true;
        end           
    end  
    return false;  
end  

function CDTimerSpell_isDebuffCast(spellAbbreviation)
    return TargetHasMyDebuff(spellAbbreviation);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -