--------------------------------------------- |
-- StunWatch v2.1 BETA2 |
-- Changes: |
----Removed Realm name from Cross Realm Players |
----Changed the way SpellDB works |
----Added option for Grow up/down |
----Implemented blizzard interface options |
|
-- TODO: |
----Add Diminishing returns |
--------------------------------------------- |
StunWatchDB = StunWatchDB or { Lock = 1, Invert = "1", Growth = 0, } |
|
local StunWatchFrame |
local StunWatchName = "StunWatchBars" |
local StunWatchActiveCP = 0 |
local candy = LibStub:GetLibrary("LibCandyBar") |
--------------------------------------------- |
-- Spell DB |
-- Only need Rank 1 as we take the Name of the SpellDB Id and compare it to the Name of the combat event ID |
-- Hack for sap atm, for different durations |
--------------------------------------------- |
local SpellDBName = { } |
local SpellDB = { |
-- Cheap Shot |
[1833] = { Duration = 4 }, |
-- Kidney Shot |
[408] = { Duration = 1, Combo = true }, |
-- Mace Stun |
[5530] = { Duration = 3 }, |
-- Blade Twisting |
[31124] = { Duration = 8}, |
-- Blind |
[2094] = { Duration = 10 }, |
-- Gouge |
[1776] = { Duration = 4 }, |
-- Sap |
[6770] = { Duration = 25, PVPDur = 8 }, |
[2070] = { Duration = 35, PVPDur = 8 }, |
[11297] = { Duration = 45, PVPDur = 8 }, |
-- Expose Armor |
[8647] = { Duration = 30 }, |
-- Rupture |
[1943] = { Duration = 6, Combo = true }, |
-- Garrote |
[703] = { Duration = 18 }, |
} |
for k, v in pairs(SpellDB) do |
SpellDBName[GetSpellInfo(k)] = v |
end |
--------------------------------------------- |
-- KillTimer |
--------------------------------------------- |
function KillTimer(self, id) |
if (candy:IsCandyBarRegistered(StunWatchName..id)) then |
candy:StopCandyBar(StunWatchName..id) |
candy:UnregisterCandyBar(StunWatchName..id) |
end |
end |
--------------------------------------------- |
-- StartTimer |
--------------------------------------------- |
function StartTimer(self, id, time, srcName, spellName, invert) |
if (candy:IsCandyBarRegistered(StunWatchName..id)) then |
candy:SetCandyBarTimeLeft(StunWatchName..id, time) |
else |
candy:RegisterCandyBar(StunWatchName..id, time, spellName..": "..srcName, nil, 1, 1, 0) |
candy:SetCandyBarReversed(StunWatchName..id, invert) |
candy:RegisterCandyBarWithGroup(StunWatchName..id, StunWatchName) |
candy:SetWidth(StunWatchName..id, 160) |
candy:SetHeight(StunWatchName..id, 10) |
candy:StartCandyBar(StunWatchName..id, true) |
end |
end |
--------------------------------------------- |
-- FindImpGouge |
--------------------------------------------- |
function FindImpGouge() |
local _, texture, _, _, rank, _, _, _ = GetTalentInfo(2, 1) |
if (texture) then |
SpellDB[1776].Duration = 4 + rank * 0.5 |
end |
end |
--------------------------------------------- |
-- Blizzard Interface Options |
--------------------------------------------- |
function StunWatch_CreateOptions(self, title) |
local panel = CreateFrame("Frame", "StunWatchOptions", self) |
panel.name = "StunWatch" |
--Create Lock checkbox |
local LockButton = CreateFrame("CheckButton", "LockCheck", panel, "OptionsCheckButtonTemplate") |
LockCheckText:SetText("Lock StunWatch Bars") |
LockCheckText:SetTextColor(1, 1, 1) |
LockButton:SetPoint("TOPLEFT", panel, "TOPLEFT", 10, -30) |
LockButton:SetScript("OnShow", function(self) self:SetChecked(StunWatchDB.Lock) end) |
LockButton:SetScript("OnClick", function(self) |
StunWatchDB.Lock = self:GetChecked() |
if (StunWatchDB.Lock) then |
StunWatchFrame:EnableMouse(false) |
StunWatchFrame:Hide() |
else |
StunWatchFrame:EnableMouse(true) |
StunWatchFrame:Show() |
end |
end) |
--Create Invert checkbox |
local InvertButton = CreateFrame("CheckButton", "InvertCheck", panel, "OptionsCheckButtonTemplate") |
InvertCheckText:SetText("Invert Bars") |
InvertCheckText:SetTextColor(1,1,1) |
InvertButton:SetPoint("TOPLEFT", LockButton, "TOPLEFT", 0, -25) |
InvertButton:SetScript("OnShow", function(self) self:SetChecked(StunWatchDB.Invert) end) |
InvertButton:SetScript("OnClick", function(self) |
StunWatchDB.Invert = tostring(self:GetChecked()) |
end) |
--Create Growth checkbox |
local GrowButton = CreateFrame("CheckButton", "GrowCheck", panel, "OptionsCheckButtonTemplate") |
GrowCheckText:SetText("Grow Up") |
GrowCheckText:SetTextColor(1,1,1) |
GrowButton:SetPoint("TOPLEFT", InvertButton, "TOPLEFT", 0, -25) |
GrowButton:SetScript("OnShow", function(self) self:SetChecked(StunWatchDB.Growth) end) |
GrowButton:SetScript("OnClick", function(self) --????????wtf at this part |
StunWatchDB.Growth = self:GetChecked() |
if (StunWatchDB.Growth) then -- /sigh |
candy:SetCandyBarGroupGrowth(StunWatchName, true) |
else |
candy:SetCandyBarGroupGrowth(StunWatchName, false) |
end |
end) |
--Create Header Text |
local HeaderText = panel:CreateFontString(nil, panel) |
HeaderText:SetFontObject("GameFontNormal") |
HeaderText:SetTextHeight(22) |
local ver = GetAddOnMetadata("StunWatch", "Version") |
HeaderText:SetText("StunWatch v"..ver) |
HeaderText:SetPoint("CENTER", panel, "TOPLEFT", 85, -15) |
--Create Info Text |
local InfoText = panel:CreateFontString(nil, panel) |
InfoText:SetFontObject("GameFontNormal") |
InfoText:SetTextHeight(14) |
InfoText:SetTextColor(1,1,1) |
InfoText:SetText("StunWatch displays progress bars for Rogue stuns.\n\nOptions:\nLock - Lock/Unlock position of bars\nInvert - Invert filling of bar\nGrow up - Grow new bars up or down") |
InfoText:SetPoint("TOPLEFT", "GrowCheck", "TOPLEFT", 0, -35) |
InterfaceOptions_AddCategory(panel) |
end |
--------------------------------------------- |
-- OnLoad |
--------------------------------------------- |
function StunWatch_OnLoad(self) |
if (not StunWatchDB.Lock) then StunWatchDB.Lock = 1 end |
if (not StunWatchDB.Invert) then StunWatchDB.Invert = "1" end |
if (not StunWatchDB.Growth) then StunWatchDB.Growth = 0 end |
--Register slash cmd |
StunWatch_CreateOptions(UIParent, "lols") |
SlashCmdList["StunWatch"] = function() |
InterfaceOptionsFrame_OpenToFrame(_G["StunWatchOptions"]) |
end |
SLASH_StunWatch1 = "/sw" |
SLASH_StunWatch2 = "/stunwatch" |
--Print Version |
local ver = GetAddOnMetadata("StunWatch", "Version") |
ChatFrame1:AddMessage("StunWatch Ver: "..ver.. " Loaded! /sw or /stunwatch for options!", 0, 1, 0) |
--Add Anchor to StunWatchFrame |
StunWatchFrame:SetWidth("170") |
StunWatchFrame:SetHeight("20") |
StunWatchFrame:SetBackdrop({ |
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", |
tile = true, |
tileSize = 16, |
edgeSize = 0, |
insets = { left = 0, right = 0, top = 0, bottom = 0 }, |
}) |
StunWatchFrame:SetClampedToScreen(true) |
StunWatchFrame:SetMovable(true) |
StunWatchFrame:EnableMouse(true) --hack until options are done.. |
StunWatchFrame:SetPoint("CENTER", UIParent, "CENTER", 0 ,0) |
StunWatchFrame.Text = StunWatchFrame:CreateFontString(nil, "OVERLAY") |
StunWatchFrame.Text:SetFontObject("GameFontNormal") |
StunWatchFrame.Text:SetWidth(170) |
StunWatchFrame.Text:SetHeight(15) |
StunWatchFrame.Text:SetPoint("CENTER") |
StunWatchFrame.Text:SetText(StunWatchName) |
--SetScripts |
StunWatchFrame:SetScript("OnMouseDown", function(self, button) if (button == "LeftButton") then self:StartMoving(); end end) |
StunWatchFrame:SetScript("OnMouseUp", function(self, button) if (button == "LeftButton") then self:StopMovingOrSizing(); end end) |
if (not StunWatchDB.Lock) then StunWatchFrame:Show() else StunWatchFrame:Hide() end |
--Register CandyBars |
candy:RegisterCandyBarGroup(StunWatchName) |
candy:SetCandyBarGroupPoint(StunWatchName, "BOTTOM", StunWatchFrame, "BOTTOM", 0, 0) |
if (StunWatchDB.Growth) then candy:SetCandyBarGroupGrowth(StunWatchName, true) else |
candy:SetCandyBarGroupGrowth(StunWatchName, false) end |
--Find Improved gouge |
FindImpGouge() |
end |
--------------------------------------------- |
-- OnEvent |
--------------------------------------------- |
function StunWatch_OnEvent(self, event, ...) |
if (event == "VARIABLES_LOADED") then |
StunWatch_OnLoad(self) |
elseif (event == "COMBAT_LOG_EVENT_UNFILTERED") then |
local _, cmbEvent, srcGUID, srcName, _, dstGUID, dstName, _ = select(1, ...) |
if (cmbEvent == "SPELL_AURA_APPLIED") then |
local spellID = arg9 |
local name = GetSpellInfo(spellID) |
local tname = string.match(dstName, "[^-]*") |
--Combo Point check |
if (GetComboPoints() > 0) then StunWatchActiveCP = GetComboPoints() end |
if (UnitGUID("target") == dstGUID) then |
if (SpellDBName[name]) then |
if (UnitIsPlayer("target") and SpellDBName[name].PVPDur) then |
StartTimer(StunWatchName, spellID, SpellDBName[name].PVPDur, tname, name, StunWatchDB.Invert) --Update to StunWatchDB.Invert |
elseif (StunWatchActiveCP and SpellDBName[name].Combo) then --ghetto hack for combo points.. |
if (GetSpellInfo(spellID) == "Kidney Shot") then |
StartTimer(StunWatchName, spellID, SpellDBName[name].Duration + StunWatchActiveCP, tname, name, StunWatchDB.Invert) |
elseif (GetSpellInfo(spellID) == "Rupture") then |
StartTimer(StunWatchName, spellID, SpellDBName[name].Duration + StunWatchActiveCP + StunWatchActiveCP, tname, name, StunWatchDB.Invert) |
end |
else |
StartTimer(StunWatchName, spellID, SpellDBName[name].Duration, tname, name, StunWatchDB.Invert) --Update to StunWatchDB.Invert |
end |
end |
end |
elseif (cmbEvent == "SPELL_AURA_REMOVED" or cmbEvent == "SPELL_AURA_DISPELLED") then |
local spellID = arg9 |
if (SpellDB[spellID]) then |
KillTimer(StunWatchName, spellID) |
end |
end |
else |
return |
end |
end |
--------------------------------------------- |
-- CreateFrame |
--------------------------------------------- |
StunWatchFrame = CreateFrame("Frame", "StunWatchMainFrame", UIParent) |
StunWatchFrame:RegisterEvent("VARIABLES_LOADED") |
StunWatchFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") |
StunWatchFrame:SetScript("OnEvent", StunWatch_OnEvent) |