Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
272 lines (240 sloc) 11.5 KB
local ADDON_NAME = "UndauntedDaily"
UndauntedDaily = {}
local nextEventHandleIndex = 1
local function RegisterForEvent(event, callback)
local eventHandleName = ADDON_NAME .. nextEventHandleIndex
EVENT_MANAGER:RegisterForEvent(eventHandleName, event, callback)
nextEventHandleIndex = nextEventHandleIndex + 1
return eventHandleName
end
local function UnregisterForEvent(event, name)
EVENT_MANAGER:UnregisterForEvent(name, event)
end
local function WrapFunction(object, functionName, wrapper)
if(type(object) == "string") then
wrapper = functionName
functionName = object
object = _G
end
local originalFunction = object[functionName]
object[functionName] = function(...) return wrapper(originalFunction, ...) end
end
local messages = {}
local function LogDebug(message, ...)
if CHAT_SYSTEM.primaryContainer then
df("[%s] " .. message, ADDON_NAME, ...)
else
messages[#messages + 1] = {message, ...}
end
end
local function FlushMessages()
for i = 1, #messages do
LogDebug(messages[i])
end
messages = {}
end
local function OnAddonLoaded(callback)
local eventHandle = ""
eventHandle = RegisterForEvent(EVENT_ADD_ON_LOADED, function(event, name)
if(name ~= ADDON_NAME) then return end
FlushMessages()
callback()
UnregisterForEvent(event, name)
end)
end
OnAddonLoaded(function()
-- dungeon list from GetLFGOption(LFG_ACTIVITY_DUNGEON, index):
-- 1: Fungal Grotto I
-- 2: Spindleclutch I
-- 3: The Banished Cells I
-- 4: Darkshade Caverns I
-- 5: Wayrest Sewers I
-- 6: Elden Hollow I
-- 7: Arx Corinium
-- 8: Crypt of Hearts I
-- 9: City of Ash I
-- 10: Direfrost Keep
-- 11: Volenfell
-- 12: Tempest Island
-- 13: Blessed Crucible
-- 14: Blackheart Haven
-- 15: Selene's Web
-- 16: Vaults of Madness
-- 17: Fungal Grotto II
-- 18: Wayrest Sewers II
-- 19: White-Gold Tower
-- 20: Imperial City Prison
-- 21: Ruins of Mazzatun
-- 22: Cradle of Shadows
-- 23: The Banished Cells II
-- 24: Elden Hollow II
-- 25: Darkshade Caverns II
-- 26: Spindleclutch II
-- 27: Crypt of Hearts II
-- 28: City of Ash II
-- 29: Bloodroot Forge
-- 30: Falkreath Hold
-- 31: Scalecaller Peak
-- 32: Fang Lair
-- 33: Moon Hunter Keep
-- 34: March of Sacrifices
-- 35: Frostvault
-- 36: Depths of Malatar
-- 2016-07-22: Spindleclutch II / Direfrost Keep / Ruins of Mazzatun
local startTime = 1473055200
local SECONDS_PER_DAY = 24 * 3600
-- dungeon set A: Maj al-Ragath
local pledgeCycleA = {26, 3, 17, 2, 25, 6, 18, 1, 23, 4, 24, 5}
-- dungeon set B: Gilirion the Redbeard
local pledgeCycleB = {10, 16, 27, 9, 12, 14, 7, 15, 28, 8, 11, 13}
-- dlc dungeons: Urgalarg Chief-bane
local pledgeCycleC = {34, 36, 35, 20, 21, 19, 22, 29, 30, 32, 31, 33}
local localization = {
en = {
DUNGEONS = "<<1>>, <<2>> and <<3>>",
PAST = "The undaunted pledges <<3>> days ago (<<X:1>>) were <<2>>.",
YESTERDAY = "Yesterday's undaunted pledges (<<X:1>>) were <<2>>.",
TODAY = "Today's undaunted pledges (<<X:1>>, <<5>> left) are <<2>>.",
TOMORROW = "Tomorrow's undaunted pledges (<<X:1>>, available in <<4>>) will be <<2>>.",
FUTURE = "The undaunted pledges <<3>> days from now (<<X:1>>) will be <<2>>.",
NOINFO = "No information about the undaunted pledges from <<3>> days ago available.",
PLEDGE_COMMAND_DESCRIPTION = "Shows the undaunted pledges",
SEND_COMMAND_DESCRIPTION = "Places the pledges for sending",
UDLIST_COMMAND_DESCRIPTION = "Internal UndauntedDaily command",
LF_GROUP_PLEDGES = "LF Tank/Healer/Dps for Veteran Pledges <<1>>",
LF_GROUP_PLEDGES_DESCRIPTION = "Post LFG for Pledges to chat. Use /lfg4pledges roles, normal/veteran",
},
de = {
DUNGEONS = "<<1>>, <<2>> und <<3>>",
PAST = "Die Unerschrockenen Gelöbnisse von vor <<3>> Tagen (<<X:1>>) waren <<2>>.",
YESTERDAY = "Die Unerschrockenen Gelöbnisse von gestern (<<X:1>>) waren <<2>>.",
TODAY = "Die Unerschrockenen Gelöbnisse von heute (<<X:1>>, <<5>> verbleibend) sind <<2>>.",
TOMORROW = "Die Unerschrockenen Gelöbnisse von morgen (<<X:1>>, verfügbar in <<4>>) werden <<2>> sein.",
FUTURE = "Die Unerschrockenen Gelöbnisse <<3>> Tage von heute (<<X:1>>) werden <<2>> sein.",
NOINFO = "Keine Informationen über die Unerschrockenen Gelöbnisse von vor <<3>> Tagen verfügbar.",
PLEDGE_COMMAND_DESCRIPTION = "Zeigt die Unerschrockenen Gelöbnisse",
SEND_COMMAND_DESCRIPTION = "Plaziert die Gelöbnisse zum Senden",
UDLIST_COMMAND_DESCRIPTION = "Interner UndauntedDaily Befehl",
LF_GROUP_PLEDGES = "LF Tank/Healer/Dps for Veteran Pledges <<1>>",
LF_GROUP_PLEDGES_DESCRIPTION = "Post LFG for Pledges to chat. Use /lfg4pledges roles, normal/veteran",
},
fr = { -- provided by Ayantir
DUNGEONS = "<<1>>, <<2>> et <<3>>",
PAST = "Les donjons indomptables d'il y a <<3>> jours (<<X:1>>) étaient <<2>>.",
YESTERDAY = "Les donjons indomptables d'hier (<<X:1>>) étaient <<2>>.",
TODAY = "Les donjons indomptables d'aujourd'hui (<<X:1>>, <<5>> restantes) sont <<2>>.",
TOMORROW = "Les donjons indomptables de demain (<<X:1>>, disponibles dans <<4>>) seront <<2>>.",
FUTURE = "Les donjons indomptables dans <<3>> jours (<<X:1>>) seront <<2>>.",
NOINFO = "Aucune information disponible sur les donjons indomptables d'il y a <<3>> jours",
PLEDGE_COMMAND_DESCRIPTION = "Afficher les donjons indomptables",
SEND_COMMAND_DESCRIPTION = "Afficher dans le Chat",
UDLIST_COMMAND_DESCRIPTION = "Commande UndauntedDaily interne",
LF_GROUP_PLEDGES = "LF Tank/Healer/Dps for Veteran Pledges <<1>>",
LF_GROUP_PLEDGES_DESCRIPTION = "Post LFG for Pledges to chat. Use /lfg4pledges roles, normal/veteran",
},
ru = { -- provided by Fellorion
DUNGEONS = "<<1>>, <<2>> и <<3>>",
PAST = "Обеты Неустрашимых <<3>> д. назад (<<X:1>>): <<2>>",
YESTERDAY = "Обеты Неустрашимых вчера (<<X:1>>): <<2>>.",
TODAY = "Обеты Неустрашимых сегодня (<<X:1>>, <<5>> осталось): <<2>>.",
TOMORROW = "Обеты Неустрашимых завтра (<<X:1>>, доступны через <<4>>): <<2>>.",
FUTURE = "Обеты Неустрашимых через <<3>> д. (<<X:1>>): <<2>>.",
NOINFO = "Обеты Неустрашимых за <<3>> д. до этого недоступны.",
PLEDGE_COMMAND_DESCRIPTION = "Показать обеты Неустрашимых",
SEND_COMMAND_DESCRIPTION = "Поместить обеты в чат для отправки",
UDLIST_COMMAND_DESCRIPTION = "Внутренняя комманда UndauntedDaily",
LF_GROUP_PLEDGES = "LF Tank/Healer/Dps for Veteran Pledges <<1>>",
LF_GROUP_PLEDGES_DESCRIPTION = "Post LFG for Pledges to chat. Use /lfg4pledges roles, normal/veteran",
},
}
local language = GetCVar("language.2")
local L = localization[language] or {}
if(language ~= "en") then
setmetatable(L, { __index = localization["en"] })
end
local function FormatTimeBetween(startTime, endTime) -- formats as 11h 11m, strips seconds when over 1 minute
local diff = math.abs(GetDiffBetweenTimeStamps(startTime, endTime))
return ZO_FormatTime(diff, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL, TIME_FORMAT_PRECISION_TWENTY_FOUR_HOUR):gsub("m.-$","m")
end
local function GetFormatString(dayOffset)
if(not dayOffset) then
return L["NOINFO"]
elseif(dayOffset < -1) then
return L["PAST"]
elseif(dayOffset == -1) then
return L["YESTERDAY"]
elseif(dayOffset == 0) then
return L["TODAY"]
elseif(dayOffset == 1) then
return L["TOMORROW"]
elseif(dayOffset > 1) then
return L["FUTURE"]
end
end
local function GetDungeonName(pledgeCycle, diff)
local cycleIndex = 1 + diff % #pledgeCycle
local dungeonIndex = pledgeCycle[cycleIndex]
return GetLFGOption(LFG_ACTIVITY_DUNGEON, dungeonIndex)
end
local function GetPledgesString(dayOffset)
local now = GetTimeStamp()
local diff = math.floor(GetDiffBetweenTimeStamps(now, startTime) / SECONDS_PER_DAY)
dayOffset = tonumber(dayOffset)
if(dayOffset) then
diff = diff + dayOffset
else
dayOffset = 0
end
local currentStartTime = startTime + diff * SECONDS_PER_DAY
local dateString = FormatAchievementLinkTimestamp(currentStartTime)
local dayOffsetAbs = math.abs(dayOffset)
local timeToStartString = FormatTimeBetween(now, currentStartTime)
local timeToEndString = FormatTimeBetween(now, currentStartTime + SECONDS_PER_DAY)
local dungeonA = GetDungeonName(pledgeCycleA, diff)
local dungeonB = GetDungeonName(pledgeCycleB, diff)
local dungeonC = GetDungeonName(pledgeCycleC, diff)
if(currentStartTime < startTime) then
dayOffset = nil
end
local format = GetFormatString(dayOffset)
local dungeons = zo_strformat(L["DUNGEONS"], dungeonA, dungeonB, dungeonC)
return zo_strformat(format, dateString, dungeons, dayOffsetAbs, timeToStartString, timeToEndString)
end
local function GetLFGPledgesString()
local now = GetTimeStamp()
local diff = math.floor(GetDiffBetweenTimeStamps(now, startTime) / SECONDS_PER_DAY)
dayOffset = 0
local currentStartTime = startTime + diff * SECONDS_PER_DAY
local dayOffsetAbs = math.abs(dayOffset)
local timeToStartString = FormatTimeBetween(now, currentStartTime)
local timeToEndString = FormatTimeBetween(now, currentStartTime + SECONDS_PER_DAY)
local dungeonA = GetDungeonName(pledgeCycleA, diff)
local dungeonB = GetDungeonName(pledgeCycleB, diff)
local dungeonC = GetDungeonName(pledgeCycleC, diff)
if(currentStartTime < startTime) then
dayOffset = nil
end
local format = L["LF_GROUP_PLEDGES"]
local dungeons = zo_strformat(L["DUNGEONS"], dungeonA, dungeonB, dungeonC)
return zo_strformat(format, dungeons)
end
local LSC = LibStub("LibSlashCommander")
LSC:Register("/lfg4pledges", function()
StartChatInput(GetLFGPledgesString())
end, L["LF_GROUP_PLEDGES_DESCRIPTION"])
local LSC = LibStub("LibSlashCommander")
LSC:Register({"/undaunted", "/pledges", "/dungeons"}, function(dayOffset)
d(GetPledgesString(dayOffset))
end, L["PLEDGE_COMMAND_DESCRIPTION"])
LSC:Register({"/undaunted2chat", "/pledges2chat", "/dungeons2chat"}, function(dayOffset)
StartChatInput(GetPledgesString(dayOffset))
end, L["SEND_COMMAND_DESCRIPTION"])
LSC:Register("/udlist", function() -- for getting indices of new dungeons
d("---- dungeons:")
local type = LFG_ACTIVITY_DUNGEON
for i = 1, GetNumLFGOptions(type) do
local name = GetLFGOption(type, i)
df("%d: %s", i, name)
end
end, L["UDLIST_COMMAND_DESCRIPTION"])
end)
You can’t perform that action at this time.