StoneTracker = {
name = "StoneTracker",
version = "1.0",
uiLocked = true,
STSet = "|H0:item:174258:364:50:0:0:0:0:0:0:0:0:0:0:0:1:122:0:1:0:10000:0|h|h", -- Used to get ID and set bonuses.
downTime = 0, -- proc cooldown timer
debuffTime = 0, -- Globabl debuff timer
defaults = {
["panelCenterY"] = 500,
["panelCenterX"] = 500,
["procFontSize"] = 35,
["procCDType"] = true,
["passiveHide"] = false,
["gearCheck"] = true,
["updateInterval"] = 100,
["colors"] = {
["active"] = {
0.05, 1, 0.1, 1
},
["cooldown"] = {
1, 0, 0,
},
},
},
}
local STT = StoneTracker
local EM = EVENT_MANAGER
function STT.STTCheck() --Check if the player has 5 pieces of StoneTalker
if STT.savedVars.gearCheck then
local ST = 0
_,_,_, ST = GetItemLinkSetInfo (STT.STSet, true)
if ST < 3 then return false end
if ST >=3 then return true end
end
return true
end
--Check proc on any target by you
function STT.Proc(eventCode, result, isError, abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, log, sourceUnitId, targetUnitId, abilityId)
if STT.STTCheck() then
STT.active = false
STT.downTime = GetGameTimeMilliseconds ()/1000 + 10
EM:RegisterForUpdate(STT.name.."Update", STT.savedVars.updateInterval, STT.CountDown)
end
end
function STT.Move()
STT.savedVars.panelCenterX, MTT.savedVars.panelCenterY = STTrackerPanel:GetCenter()
STTrackerPanel:ClearAnchors()
STTrackerPanel:SetAnchor(CENTER, GuiRoot, TOPLEFT, STT.savedVars.panelCenterX, STT.savedVars.panelCenterY)
end
function STT.RestorePosition() --Load status panel position
-- local panelCenterX = STT.savedVars.panelCenterX
-- local panelCenterY = STT.savedVars.panelCenterY
if panelCenterX or panelCenterY then
STTrackerPanel:ClearAnchors()
STTrackerPanel:SetAnchor(CENTER, GuiRoot, TOPLEFT, STT.savedVars.OffsetX, STT.savedVars.OffsetY)
end
end
function STT.CombatState() --Check player combat status
STT.HideOutOfCombat()
end
function STT.HideOutOfCombat() --Allow panel to be hidden in combat.
if STT.STTCheck() then
if STT.savedVars.passiveHide then
STT.HidePanel (not IsUnitInCombat("player"))
end
end
end
function STT.HideFrame() --Hide panel if opening menus.
if STT.STTCheck() then
STT.HidePanel(IsReticleHidden())
else
STT.HidePanel(true)
end
if not IsReticleHidden() then STT.HideOutOfCombat() end
end
function STT.HidePanel(value)
STTrackerPanel:SetHidden(value)
end
--function STT.HideGlobalProcPanel(value) --Hide global ST debuff timer
-- STTrackerPanel_GlobalProc:SetHidden(value)
--end
function STT.CountDown() -- Update proc timers
local procThreshold = 0
if STT.savedVars.procCooldownType then procThreshold = 0 else procThreshold = 10 end
if (STT.downTime - GetGameTimeMilliseconds()/1000 > procThreshold) then
STTrackerPanel_Proc:SetColor (unpack(STT.savedVars.colors.cooldown))
else
STTrackerPanel_Proc:SetColor(unpack(STT.savedVars.colors.active))
end
STTrackerPanel_Proc:SetText(string.format("%.1f", STT.Time(STT.downTime, 10)))
if (STT.downTime - GetGameTimeMilliseconds()/1000 <= 0) then
STTrackerPanel_Proc:SetText("0")
EM:UnregisterForUpdate(STT.name.."Update")
end
end
function STT.Time (nd, multiplier) --Rounds the timer down
return math.floor((nd - GetGameTimeMilliseconds()/1000) * multiplier + 0.5)/multiplier
end
function STT.SetColors() --Set colors on update or loading
STTrackerPanel_Proc:SetColor(unpack(STT.savedVars.colors.active))
end
function STT.SetFontSize() --Set Fonts for panel
STTrackerPanel_Proc:SetFont(string.format("%s|%d|%s", "$(CHAT_FONT)", STT.savedVars.procFontSize, "soft-shadow-thick"))
end
function STT.RegisterProcEventType()
EM:UnregisterForUpdate(STT.name.."Proc")
local procEvent = STT.name.."Proc"
EM:RegisterForEvent (procEvent, EVENT_COMBAT_EVENT, STT.Proc)
EM:AddFilterForEvent(procEvent, EVENT_COMBAT_EVENT, REGISTER_FILTER_ABILITY_ID, 154783)
EM:AddFilterForEvent(procEvent, EVENT_COMBAT_EVENT, REGISTER_FILTER_COMBAT_RESULT, ACTION_RESULT_EFFECT_GAINED)
EM:AddFilterForEvent(procEvent, EVENT_COMBAT_EVENT, REGISTER_FILTER_SOURCE_COMBAT_UNIT_TYPE, COMBAT_UNIT_TYPE_PLAYER)
end
--function STTracker.move()
-- STT.savedVars.OffsetX = STTrackerPanel:GetLeft()
-- STT.savedVars.OffsetY = SSTrackerPanel:GetTop()
--end
function STT.AddNewVariables()
if STT.savedVars.colors.active == nil then STT.savedVars.colors.active = { } STT.savedVars.colors.active = {0.05, 1, 0.11, 1} end
if STT.savedVars.ProcFontSize == nil then STT.savedVars.ProcFontSize = 34 end
end
function STT.Init(event, addon)
if addon ~= STT.name then return end
EM:UnregisterForEvent (STT.name.."Load", EVENT_ADD_ON_LOADED)
STT.savedVars = ZO_SavedVars:NewAccountWide("StoneSettings", StoneTracker.varVersion, nil, StoneTracker.defaults, GetWorldName())
STT.AddNewVariables()
STT.RegisterProcEventType()
STT.RestorePosition()
STTrackerPanel:SetHidden(IsReticleHidden())
STT.SetColors()
STT.SetFontSize()
STT.SetupMenu()
STT.HideOutOfCombat()
EM:RegisterForEvent(STT.name.."Hide", EVENT_RETICLE_HIDDEN_UPDATE, STT.HideFrame)
EM:RegisterForEvent(STT.name.."CombatState", EVENTER_PLAYER_COMBAT_STATE, STT.CombatState)
EM:RegisterForEvent(STT.name.."GearCheck", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, STT.HideFrame)
end
function STT.SetupMenu()
local LAM2 = LibAddonMenu2
local panelData = {
type = "panel",
name = STT.name,
displayName = "|cFF0000StoneTracker|",
version = ""..STT.version,
}
LAM2:RegisterAddonPanel(STT.name.."Options", panelData)
local options ={
{
type = "header",
name = "General Settings"
},
{
type = "checkbox",
name = "Lock UI",
tooltip = "Unlock to reposition timer to preferred location",
getFunc = function() return true end,
setFunc = function(value)
if not value then
EVENT_MANAGER:UnregisterForEvent(STT.name.."Hide", EVENT_RETICLE_HIDDEN_UPDATE)
STTrackerPanel:SetHidden(false)
STTrackerPanel:SetMovable(true)
STTrackerPanel:SetMouseEnabled(true)
else
EVENT_MANAGER:RegisterForEvent(STT.name.."Hide", EVENT_RETICLE_HIDDEN_UPDATE, STT.HideFrame)
STTrackerPanel:SetHidden(IsReticleHidden())
STTrackerPanel:SetMovable(false)
STTrackerPanel:SetMouseEnabled(false)
end
end
},
{
type = "checkbox",
name = "Gear Check",
tooltip = "Display status panel only if 3 or more pieces of StoneTalker's Oath are equipped",
getFunc = function() return STT.savedVars.gearCheck end,
setFunc = function(value)
STT.savedVars.gearCheck = value
STT.HideFrame()
end
},
{
type = "checkbox",
name = "Display only when in Combat",
tooltip = "Rate that information about the cooldown is updated.",
getFunc = function() return STT.savedVars.passiveHide end,
setFunc = function(value)
STT.savedVars.gearCheck = value
STT.HideFrame()
end
},
{
type = "slider",
name = "Update Intervals",
tooltip = "Rate that information about the cooldown is updated.",
getFunc = function() return STT.savedVars.updateInterval end,
setFunc = function(value) STT.savedVars.updateInterval = value end,
min = 100,
max = 1000,
step = 5,
default = 200,
width = "full",
},
{
type = "header",
name = "StoneTracker Proc Options"
},
{
type = "checkbox",
name = "Change Stonetalker Color when available",
tooltip = "Change color of the proc cooldown for when StoneTalker can be proc again. If set to false, will set color when the debuff ends.",
getFunc = function() return (STT.savedVars.colors.active) end,
setFunc = function(value)
STT.savedVars.procCooldownType = value
end
},
{
type = "slider",
name = "StoneTracker Cooldown font size",
tooltip = "Size of Font for StoneTracker cooldown",
getFunc = function() return STT.savedVars.procFontSize end,
setFunc = function(value) STT.savedVars.procFontSize = value STT.SetFontSize() end,
min = 10,
max = 72,
step = 1,
default = 32,
width = "full",
},
}
LAM2:RegisterOptionControls(STT.name.."Options", options)
end
EM:RegisterForEvent(STT.name.."Load", EVENT_ADD_ON_LOADED, STT.Init)