📄 ankhcooldowntimer.lua
字号:
local elapsed = arg1
if (AnkhCT_AddonEnabled == 1) then
if (not AnkhCT_TimerUpdate) then
AnkhCT_TimerUpdate = 0
else
if (elapsed) then
AnkhCT_TimerUpdate = AnkhCT_TimerUpdate - elapsed;
end
end
if (AnkhCT_TimerUpdate <= 0) then
-- OnUpdate is only called if the the gui is showing. The default for the GUI is
-- to be visible on startup, so if the user has disabled the gui it will be hidden
-- on the first update.
if (AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Gui == 0) then
AnkhCT_Frame:Hide()
end
-- Update the Gui box if it's enabled
if (AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Gui == 1) then
local ankhs = AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Ankhs
-- Change text color depending on the nr of ankhs the player has. Normal is light yellow
local ankhColor = "|cffffff9a"
if (ankhs == 0) then
-- Red color
ankhColor = "|cffff2020"
elseif ( ankhs == 1) then
-- Green color
ankhColor = "|cff20ff20"
end
-- Update the GUI box with text
AnkhCT_Ankhs:SetText("十字章: " .. ankhColor .. ankhs .. "|r")
AnkhCT_Cooldown:SetText("Cooldown: |c00FFFFFF" .. date("%M:%S ", AnkhCT_GetAnkhCooldown()) .. "|r");
end
-- Restore the timer update timer
AnkhCT_TimerUpdate = AnkhCT_TIMERINTERVAL
end
end
end
--------------------------------------------------------------------------------------------------
-- Checks if the user really used an ankh to reincarnate and calls the reincarnate function
-- if so. Also updates the ankh inventory status
--------------------------------------------------------------------------------------------------
function AnkhCT_ReincTest(eventTime)
local nrOfAnks = AnkhCT_GetAnkhs()
-- tests for reincarnation go here
-- first see if ankhs decremented
if (nrOfAnks == AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Ankhs - 1 ) then
ConsoleMsg("Testing for reincarnation bc ankhs changed.")
-- this is for ankh decrement while dead
if (AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Alive == 0) then
AnkhCT_PlayerReincarnated()
ConsoleMsg("ReincTest in .Alive", 2)
elseif (AnkhCT_ReincarnationTime) and ((eventTime - AnkhCT_ReincarnationTime) < AnkhCT_TESTINTERVAL) then
AnkhCT_PlayerReincarnated()
ConsoleMsg("ReincTest in AnkhCT_ReincarnationTime", 2)
end
end
AnkhCT_UpdateAnkhs()
end
--------------------------------------------------------------------------------------------------
-- Returns ankh cooldown in seconds
--------------------------------------------------------------------------------------------------
function AnkhCT_GetAnkhCooldown()
local lastUsed = AnkhCT_GetLastUsed()
if (lastUsed == 0) then
return 0
end
AnkhCT_UpdateTalentCooldown()
local cooldown = AnkhCT_GetSystemSinceWOW() - lastUsed
if( cooldown > AnkhCT_TalentCooldown ) then
return 0
end
return AnkhCT_TalentCooldown - cooldown
end
--------------------------------------------------------------------------------------------------
-- Checks if the player is alive or not. If called with eventTime the function will
-- store the time of death.
--------------------------------------------------------------------------------------------------
function AnkhCT_IsAlive(eventTime)
if (AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Alive == 0) then
AnkhCT_ReincarnationTime = eventTime
AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Alive = 1
end
end
function AnkhCT_IsAlive()
if (UnitIsDeadOrGhost("player")) then
return 0
else
return 1
end
end
--------------------------------------------------------------------------------------------------
-- Called when the player reincarnated with an ankh. It turns on the cooldown
--------------------------------------------------------------------------------------------------
function AnkhCT_PlayerReincarnated()
ConsoleMsg("Ankh reincarnation used! Starting cooldown timer now.")
AnkhCT_UpdateTalentCooldown()
AnkhCT_SetLastUsed(AnkhCT_GetSystemSinceWOW())
end
--------------------------------------------------------------------------------------------------
-- Function used to pring messages to the console. Can also be used for debug output
--------------------------------------------------------------------------------------------------
function ConsoleMsg(msg, level)
if (level) and (AnkhCT_Config) and (AnkhCT_Config.Debug) then
if (level <= AnkhCT_Config.Debug) then
if (msg) then
Print("AnkhCT: " .. msg)
end
end
else
if (msg) then
Print("AnkhCT: " .. msg)
end
end
end
--------------------------------------------------------------------------------------------------
-- Listener function for chat messages from the player
--------------------------------------------------------------------------------------------------
function AnkhCT_ChatCommandHandler(msg)
msg = string.lower(msg)
local firsti, lasti, command, setStr = string.find (msg, "(%w+) ([%w%.]+)")
if ((not command) and msg) then
command = msg
end
if (command) then
command = string.lower(command);
if (command == "enable") then
AnkhCT_AddonEnabled = 1
AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Enabled = 1
elseif (command == "disable") then
AnkhCT_AddonEnabled = 0
AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Enabled = 0
elseif (command == "version") then
ConsoleMsg("Version ".. AnkhCT_version)
elseif (command == "cooldown") then
ConsoleMsg("Cooldown: " .. date("%M:%S ", AnkhCT_GetAnkhCooldown()))
elseif (command == "ankhs") then
ConsoleMsg("Nr of ankhs in bag: " .. AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Ankhs)
elseif (command == "debug") then
if (setStr) then
AnkhCT_DebugLevel = setStr + 0
AnkhCT_Config.Debug = setStr + 0
ConsoleMsg("Debug level changed to: " .. AnkhCT_Config.Debug)
end
elseif (command == "dead") then
if (setStr) then
local secs = tonumber(setStr)
if (secs >= 0) and (secs <= AnkhCT_TalentCooldown) then
AnkhCT_SetLastUsed(AnkhCT_GetSystemSinceWOW() - AnkhCT_TalentCooldown + secs)
end
else
AnkhCT_SetLastUsed(AnkhCT_GetSystemSinceWOW())
end
elseif (command == "toggle") then
AnkhCT_ToggleGui()
elseif (command == "date") then
ConsoleMsg("Time is: " .. AnkhCT_GetSystemSinceWOW() .. " and ankh was used: " .. AnkhCT_GetLastUsed())
-- date("today is %A, in %B")
elseif (command == "reset") then
if (AnkhCT_Userdata) and (AnkhCT_Userdata[AnkhCT_CurrentServer]) and (AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName]) then
AnkhCT_SetLastUsed(0)
Print("Ankh cooldown set to 0!")
end
elseif (command == "reincarnated") then
if (AnkhCT_GetLastUsed() ~= 0) then
ConsoleMsg("Reincarnated since: " .. date("%c", AnkhCT_GetLastUsed() + 1100304000))
else
ConsoleMsg("No reincarnation data available")
end
else
Print("Ankh Cooldown Timer: [act | AnkhCT ]")
Print(" /act [enable | disable] - enable/disable Ankh Cooldown Timer")
Print(" /act version - show addon info")
Print(" /act reset - set cooldown to 0")
Print(" /act dead (secs) - set timer cooldown to max (or to cooldown - secs)")
Print(" /act ankhs - Returns number of ankhs in your inventory")
Print(" /act toggle - Toggles the GUI box on/off")
Print(" /act reincarnated - Tells you the date and time of your last reincarnation")
Print(" /act cooldown - Returns the cooldown of your reincarnation ability")
end
end
end
--------------------------------------------------------------------------------------------------
-- Returns time since WOW was released. The need for this strange time is that
-- saving the unix time in a persistent variable truncates the 10 digit variable
-- for some reason, and that fucks things up after logout/login. By removing time
-- since wow was released we end up with a much smaller and working number. *NOTE*
-- That was not the case, the time still got truncated, that's why it's stored as
-- a string now instead.. but the WOW time remains..
--------------------------------------------------------------------------------------------------
function AnkhCT_GetSystemSinceWOW()
-- Return time since WOW was released on november 13th 2004
return time() - 1100304000
end
function AnkhCT_GetLastUsed()
return tonumber(AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].LastUsed)
end
function AnkhCT_SetLastUsed(time)
AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].LastUsed = tostring(time)
end
--------------------------------------------------------------------------------------------------
-- Toggles the GUI box
--------------------------------------------------------------------------------------------------
function AnkhCT_ToggleGui()
if (AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Gui == 0) then
AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Gui = 1
AnkhCT_Frame:Show()
elseif(AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Gui == 1) then
AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Gui = 0
AnkhCT_Frame:Hide()
end
end
--------------------------------------------------------------------------------------------------
-- Titan panel support
--------------------------------------------------------------------------------------------------
function TitanPanelAnkhCTButton_OnLoad()
AnkhCT_OnLoad()
AnkhCT_TitanFound = 1
this.registry = {
id = AnkhCT_TITANID,
builtIn_c = 1,
menuText = "萨满重生计时器",
buttonTextFunction = "TitanPanelAnkhCTButton_GetButtonText",
tooltipTitle = "萨满重生计时器",
tooltipTextFunction = "TitanPanelAnkhCTButton_GetTooltipText",
frequency = 1,
};
end
function TitanPanelAnkhCTButton_GetButtonText(id)
if (not AnkhCT_PlayerName) then
return "AnkhCT"
end
local ankhs = AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Ankhs
-- Change text color depending on the nr of ankhs the player has. Normal is light yellow
local ankhColor = "|cffffff9a"
if (ankhs == 0) then
-- Red color
ankhColor = "|cffff2020"
elseif ( ankhs == 1) then
-- Green color
ankhColor = "|cff20ff20"
end
local cooldownColor = "|cffff2020"
if (AnkhCT_GetAnkhCooldown() == 0) then
cooldownColor = "|cff20ff20"
end
local btnText = "复生计时: " .. cooldownColor .. date("%M:%S ", AnkhCT_GetAnkhCooldown()) .. "|r (" .. ankhColor .. ankhs .. "|r)"
return btnText
end
function TitanPanelAnkhCTButton_GetTooltipText()
if (not AnkhCT_PlayerName) then
return ""
end
local since = "N/A"
if (AnkhCT_GetLastUsed() ~= 0) then
since = date("%c", AnkhCT_GetLastUsed() + 1100304000)
end
local ankhs = AnkhCT_Userdata[AnkhCT_CurrentServer][AnkhCT_PlayerName].Ankhs
-- Change text color depending on the nr of ankhs the player has. Normal is light yellow
local ankhColor = "|cffffff9a"
if (ankhs == 0) then
-- Red color
ankhColor = "|cffff2020"
elseif ( ankhs == 1) then
-- Green color
ankhColor = "|cff20ff20"
end
local cooldownColor = "|cffff2020"
if (AnkhCT_GetAnkhCooldown() == 0) then
cooldownColor = "|cff20ff20"
end
return "上次复生于: \n" .. since .. "\n十字章数: " .. ankhColor .. ankhs .. "|r\n十字章冷却时间: ".. cooldownColor .. date("%M:%S ", AnkhCT_GetAnkhCooldown()) .. "|r\n技能冷却时间: |c00FFFFFF" .. AnkhCT_TalentCooldown/60 .. "min|r"
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -