📄 countdoom.lua
字号:
-- CountDoom
-- Author: Scrum
-- based on work by Justin Milligan
-- USEFUL STUFF
-- isDemon = UnitCreatureType("target") == "Demon"
-- isElemental = UnitCreatureType("target") == "Elemental"
-- local targetName = UnitName("target");
-- TargetByName( targetName )
CD_DefaultConfig = {};
-- 0.3 config items
CD_DefaultConfig.isLocked = true;
CD_DefaultConfig.announceSpells = "never";
CD_DefaultConfig.playSounds = true;
CD_DefaultConfig.flashSpells = true;
CD_DefaultConfig.enable = true;
CD_DefaultConfig.layout = "vertical";
CD_DefaultConfig.scale = "small";
CD_DefaultConfig.hseconds = false;
CD_DefaultConfig.postExpireDelay = 0;
CD_DefaultConfig.outofcombatDelay = 0;
CD_DefaultConfig.announceChannel = nil;
CountDoom = {};
CountDoom.debugVerbose = false;
CountDoom.debugEvents = false;
CountDoom.initialized = false;
CountDoom.playerName = nil;
CountDoom.realmName = nil;
CountDoom.activeSpell = nil;
CountDoom.soundPath = "Interface\\AddOns\\CountDoom\\";
CountDoom.targetID = 0;
CountDoom.targetName = nil;
CountDoom.activeSpell = nil;
CountDoom.totalTime = 0;
CountDoom.activeSpellWaitingForTarget = nil;
CountDoom.petTargetName = nil;
CountDoom.petTargeLevel = 0;
CountDoom.petActiveSpell = nil;
CountDoom.lastSpellID = -1;
CountDoom.spellRank = nil;
CountDoom.timeRemoveAllTimers = nil;
CountDoom.event = {};
CountDoom.event.castSpellName = nil;
CountDoom.event.castMode = nil;
CountDoom.event.castTarget = nil;
CountDoom.event.removedSpellName = nil;
CountDoom.event.removedLastReason = nil;
CountDoom.event.removedTarget = nil;
CountDoom.ChatPrint = function( msg, r, g, b )
local msgOutput = DEFAULT_CHAT_FRAME;
if( msgOutput ) then
msgOutput:AddMessage( msg, r, g, b );
end
end;
CountDoom.CombatPrint = function( msg, r, g, b )
local msgOutput = ChatFrame2;
if( msgOutput ) then
msgOutput:AddMessage( msg, r, g, b );
end
end;
CountDoom.DebugPrint = function(arg1)
if (CountDoom.debugVerbose) then
CountDoom.ChatPrint("CountDoom<DEBUG>: " .. arg1);
debuginfo( arg1 );
end
end;
CountDoom.ToString = function(arg1)
local argType = type( arg1 );
if argType == "nil" then
return "nil";
elseif argType == "boolean" then
if arg1 then
return COUNTDOOM_TRUE;
else
return COUNTDOOM_FALSE;
end
else
return "" .. arg1;
end
end;
CountDoom.DisplaySettings = function()
CountDoom.ChatPrint( "Locked: " .. CountDoom.ToString( CountDoom.config.isLocked ) );
CountDoom.ChatPrint( "Announce Spells: " .. CountDoom.ToString( CountDoom.config.announceSpells ) );
CountDoom.ChatPrint( "Announce channel: " .. CountDoom.ToString( CountDoom.config.announceChannel ) );
CountDoom.ChatPrint( "Flash Spells: " .. CountDoom.ToString( CountDoom.config.flashSpells ) );
CountDoom.ChatPrint( "Play sounds: " .. CountDoom.ToString( CountDoom.config.playSounds ) );
CountDoom.ChatPrint( "Layout: " .. CountDoom.ToString( CountDoom.config.layout ) );
CountDoom.ChatPrint( "Scale: " .. CountDoom.ToString( CountDoom.config.scale ) );
CountDoom.ChatPrint( "Out of combat delay: " .. CountDoom.ToString( CountDoom.config.outofcombatDelay ) );
CountDoom.ChatPrint( "Delay after expiration: " .. CountDoom.ToString( CountDoom.config.postExpireDelay ) );
CountDoom.ChatPrint( "Display Hundredths: " .. CountDoom.ToString( CountDoom.config.hseconds ) );
end;
CountDoom.DisplayCommands = function()
CountDoom.ChatPrint("CountDoom Usage:");
CountDoom.ChatPrint("/cd <enable|disable> -- enable/disable CountDoom" );
CountDoom.ChatPrint("/cd <lock|unlock> -- lock/unlock timers" );
CountDoom.ChatPrint("/cd announce -- toggle per spell announce" );
CountDoom.ChatPrint("/cd play -- toggle per spell sounds" );
CountDoom.ChatPrint("/cd flash -- toggle warning flashes" );
CountDoom.ChatPrint("/cd layout -- cycle layout styles horiz/vert/text" );
CountDoom.ChatPrint("/cd scale -- cycle icon scale" );
CountDoom.ChatPrint("/cd <spell> -- dump spell information" );
CountDoom.ChatPrint("/cd <spell> start -- debug: start a spell" );
CountDoom.ChatPrint("/cd <spell> end -- debug: end a spell" );
CountDoom.ChatPrint("/cd <spell> toggle -- enable disable tracking a spell" );
CountDoom.ChatPrint("/cd ooc <seconds> -- delay before removing all timers" );
CountDoom.ChatPrint("/cd expire <seconds> -- delay before removing expired timers" );
CountDoom.ChatPrint("/cd hseconds -- display Hundredths of a second" );
CountDoom.ChatPrint("/cd debug verbose -- verbose debug msgs" );
end;
CountDoom.RegisterEvents = function()
-- Need to detect changes to enslaved demon state
this:RegisterEvent("LOCALPLAYER_PET_CHANGED");
this:RegisterEvent("UNIT_PET");
this:RegisterEvent("SPELLCAST_STOP");
this:RegisterEvent("SPELLCAST_FAILED");
this:RegisterEvent("SPELLCAST_INTERRUPTED");
-- Used to know when a player zones in.
this:RegisterEvent("PLAYER_ENTERING_WORLD");
-- Used for clearing timers after combat
this:RegisterEvent("PLAYER_REGEN_ENABLED");
this:RegisterEvent("PLAYER_REGEN_DISABLED");
-- Used to determine the target ID of a timer. It counts how many times
-- a player changes target (including back and forth)
this:RegisterEvent("PLAYER_TARGET_CHANGED");
-- Used to detect when a spell was resisted or immune
this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE");
-- Used to detect when Succubus casts Seduction
this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE");
this:RegisterEvent("CHAT_MSG_SPELL_PET_DAMAGE");
-- Used to detect when the succubus Seduction fades
this:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER");
-- Used to detect when someone dies.
this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILE_DEATH");
end;
CountDoom.RegisterCommands = function()
SLASH_COUNTDOOM1 = "/countdoom";
SLASH_COUNTDOOM2 = "/cd";
SlashCmdList["COUNTDOOM"] = function(msg)
CountDoomSlash(msg);
end
end;
-- Credit to Morbain for the logic
CountDoom.UpdateDurations = function()
local tab, talent;
local numTalentTabs = GetNumTalentTabs();
CountDoom.DebugPrint( "Talent Tabs: " .. CountDoom.ToString( numTalentTabs ) );
for tab = 1, numTalentTabs do
local numTalents = GetNumTalents(tab);
CountDoom.DebugPrint( "Talents: " .. CountDoom.ToString( numTalents ) );
for talent=1, numTalents do
local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq =
GetTalentInfo(tab, talent);
if name then
CountDoom.DebugPrint( "("..tab..","..talent .. "): " .. name .. "= " .. rank .. "(" .. maxRank ..
")" );
end
end
end
local duration = CountDoomSpell[ "诱惑" ].rankDuration[1];
-- Determine if the player has improved succubus which increases timer duration.
local _, texture, _, _, rank, _, _, _ = GetTalentInfo(2, 7);
if (texture) then
duration = duration + (duration * 0.1 * rank)
end
CountDoomSpell[ "诱惑" ].rankDuration[1] = duration;
end;
CountDoom.UpdateLayout = function()
if CountDoom.config.layout == "horizontal" then
CDTimers_LayoutHorizontal();
elseif CountDoom.config.layout == "textonly" then
CDTimers_LayoutTextOnly();
else
CDTimers_LayoutVertical();
end
CDTimerSpell_UpdateSpellPrefixes();
end;
CountDoom.CycleScale = function()
if CountDoom.config.scale == "small" then
CountDoom.config.scale = "medium";
elseif CountDoom.config.scale == "medium" then
CountDoom.config.scale = "large";
else
CountDoom.config.scale = "small";
end
CountDoom.UpdateLayout();
CountDoom.ChatPrint( "Scale set to: " .. CountDoom.config.scale );
end;
CountDoom.UpdateDragButtons = function()
if CountDoom.config.isLocked ~= true then
CountDoomFrame:SetBackdropColor( 1.0, 1.0, 1.0, 1.0 );
CountDoomFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 1.0 );
CountDoomFrameBackground:SetAlpha(1.0);
CountDoomFrame:Show();
getglobal("CountDoomFrameDragButton"):Show();
CountDoom.DebugPrint("Showing drag buttons.");
else
CountDoomFrame:SetBackdropColor( 1.0, 1.0, 1.0, 0.0 );
CountDoomFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 0.0 );
CountDoomFrameBackground:SetAlpha(0.0);
getglobal("CountDoomFrameDragButton"):Hide();
CountDoom.DebugPrint("Hiding drag buttons.");
if CDTimer_numTimers == 0 then
CountDoomFrame:Hide();
end
end
end;
CountDoom.RotateLayout = function( frameName )
if frameName == "CountDoomFrame" then
if CountDoom.config.layout == "vertical" then
CountDoom.config.layout = "horizontal";
elseif CountDoom.config.layout == "horizontal" then
CountDoom.config.layout = "textonly";
else
CountDoom.config.layout = "vertical";
end
CountDoom.UpdateLayout();
end
CountDoom.ChatPrint( "Layout set to: " .. CountDoom.config.layout );
end;
CountDoom.CreateConfig = function( playerName, realmName )
CountDoom.DebugPrint("Initializing CountDoom.config");
if not CountDoomConfig then
CountDoom.DebugPrint("Allocating CountDoomConfig");
CountDoomConfig = {};
end
if not CountDoomConfig[realmName] then
CountDoomConfig[realmName] = {};
end
if not CountDoomConfig[realmName][playerName] then
CountDoomConfig[realmName][playerName] = {};
end
if (not CountDoomConfig[realmName][playerName].enableSpell) then
CountDoomConfig[realmName][playerName].enableSpell = {};
end
-- set the defaults if the values weren't loaded by the SavedVariables.lua
if( CountDoomConfig[realmName][playerName].isLocked == nil ) then
CountDoomConfig[realmName][playerName].isLocked = CD_DefaultConfig.isLocked;
end
if( CountDoomConfig[realmName][playerName].warningSound == nil ) then
CountDoomConfig[realmName][playerName].warningSound = {};
CountDoomConfig[realmName][playerName].warningSound[ "enslave" ] = "enslavewarning";
end
if( CountDoomConfig[realmName][playerName].endSound == nil ) then
CountDoomConfig[realmName][playerName].endSound = {};
CountDoomConfig[realmName][playerName].endSound[ "enslave" ] = "enslaveend";
end
if( CountDoomConfig[realmName][playerName].announceSpells == nil ) then
CountDoomConfig[realmName][playerName].announceSpells = CD_DefaultConfig.announceSpells;
end
if( CountDoomConfig[realmName][playerName].playSounds == nil ) then
CountDoomConfig[realmName][playerName].playSounds = CD_DefaultConfig.playSounds;
end
if( CountDoomConfig[realmName][playerName].flashSpells == nil ) then
CountDoomConfig[realmName][playerName].flashSpells = CD_DefaultConfig.flashSpells;
end
if( CountDoomConfig[realmName][playerName].enable == nil ) then
CountDoomConfig[realmName][playerName].enable = CD_DefaultConfig.enable;
end
if( CountDoomConfig[realmName][playerName].layout == nil ) then
CountDoomConfig[realmName][playerName].layout = CD_DefaultConfig.layout;
end
if( CountDoomConfig[realmName][playerName].scale == nil ) then
CountDoomConfig[realmName][playerName].scale = CD_DefaultConfig.scale;
end
if( CountDoomConfig[realmName][playerName].hseconds == nil ) then
CountDoomConfig[realmName][playerName].hseconds = CD_DefaultConfig.hseconds;
end
if( CountDoomConfig[realmName][playerName].outofcombatDelay == nil ) then
CountDoomConfig[realmName][playerName].outofcombatDelay = CD_DefaultConfig.outofcombatDelay;
end
if( CountDoomConfig[realmName][playerName].postExpireDelay == nil ) then
CountDoomConfig[realmName][playerName].postExpireDelay = CD_DefaultConfig.postExpireDelay;
end
if( CountDoomConfig[realmName][playerName].announceChannel == nil ) then
CountDoomConfig[realmName][playerName].announceChannel = CD_DefaultConfig.announceChannel;
end
end;
CountDoom.Initialize = function ()
if (CountDoom.initialized == true) then
CountDoom.DebugPrint("Initialize: already loaded. returning.");
return
end
local playerName = UnitName("player");
local realmName = GetRealmName();
-- if CountDoom.playerName is "Unknown Entity" get out, need a real name
if (playerName == nil or playerName == UNKNOWNOBJECT) then
CountDoom.DebugPrint("Initialize: invalid name. returning");
return
end
CountDoom.playerName = playerName;
CountDoom.realmName = realmName;
-- Initialize our configuration
CountDoom.CreateConfig(playerName, realmName);
-- Alias the config to shorten the name. Hopefully, this save settings otherwise we're toast.
CountDoom.config = CountDoomConfig[realmName][playerName];
CountDoom.RegisterEvents();
CountDoom.RegisterCommands();
CountDoom.UpdateDurations();
CountDoom.UpdateLayout();
CountDoom.UpdateDragButtons();
CountDoom.GetSpellBookInfo();
-- print out a nice message letting the user know the addon loaded
-- CountDoom.ChatPrint( COUNTDOOM_LOADED );
-- All variables are loaded now
CountDoom.initialized = true;
end;
-- Sets the warning sound. (FUTURE USE)
CountDoom.SetWarningSound = function(spellAbbreviation, msg)
CountDoom.config.warningSound[ spellAbbreviation ] = msg;
CountDoom.ChatPrint( string.format( COUNTDOOM_SETWARNINGSOUNDMSG, warningSound[ spellAbbreviation ] ) );
end;
-- Sets the end sound. (FUTURE USE)
CountDoom.SetEndSound = function(spellAbbreviation, msg)
CountDoom.config.endSound[ spellAbbreviation ] = msg;
CountDoom.ChatPrint( string.format( COUNTDOOM_SETENDSOUNDMSG, CountDoom.config.endSound[ spellAbbreviation ] ) );
end;
CountDoom.ToggleAnnouncingSpells = function()
if CountDoom.config.announceSpells == nil or CountDoom.config.announceSpells == "never" then
CountDoom.config.announceSpells = "local";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -