forked from manavortex/DailyAutoShare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DasLog.lua
82 lines (73 loc) · 2.7 KB
/
DasLog.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local dayCached
local characterId = GetCurrentCharacterId()
local typeString = "string"
local clockBase = 1577858400
local clockWasAdjusted = false
---Returns days since 2020-01-01 06:00 UTC rounded down to the nearest whole number
---@return number
local function getToday()
-- Shift starting time to the current daily reset
if not clockWasAdjusted then
local clockOffset = GetDiffBetweenTimeStamps(GetTimeStamp() + GetTimeUntilNextDailyLoginRewardClaimS(), clockBase) % 86400
if clockOffset >= 43200 then clockOffset = clockOffset - 86400 end -- normalize to make EU clock the same day as NA
clockBase = clockBase + clockOffset -- should add -10800 on EU server, +14400 on NA/PTS [as of 2023]
clockWasAdjusted = true
end
return math.floor(GetDiffBetweenTimeStamps(GetTimeStamp(), clockBase) / 86400)
end
---Returns today's quest log for the current player character
---@return table
function DAS.GetShareableLog()
local day = getToday()
if nil == dayCached or dayCached ~= day then
local settings = DAS.globalSettings.completionLog or {}
-- initialize if empty
settings[characterId] = settings[characterId] or {}
-- pre4.5.0 compatibility, remove this in 4.5.1+
settings[characterId]._day = settings[characterId]._day or settings._day
-- purge the old entries
if settings[characterId]._day ~= day then
settings[characterId] = {}
-- store the day number per character
settings[characterId]._day = day
end
-- make sure it's set
DAS.globalSettings.completionLog = settings
dayCached = day
end
return DAS.globalSettings.completionLog[characterId]
end
---Get completion status (true or false) for the given quest
---@param questName any
---@return boolean
function DAS.IsQuestDone(questName)
if nil == questName or "" == questName or typeString ~= type(questName) then return false end
return DAS.GetShareableLog()[zo_strformat(questName)] or false
end
---Set completion status (true or false) for the given quest
---@param questName string
---@param isDone boolean
function DAS.LogQuest(questName, isDone)
if nil == questName or "" == questName or typeString ~= type(questName) then return end
DAS.GetShareableLog()[questName] = isDone
end
---Get DAS status ID for the given quest
---@param questName string
---@return number|nil
function DAS.GetQuestStatus(questName)
if nil == questName then return end
if nil ~= DAS.QuestNameTable[questName] then return DAS_STATUS_ACTIVE end
if DAS.IsQuestDone(questName) then
return DAS_STATUS_COMPLETE
end
return DAS_STATUS_OPEN
end
---Get log index for the given quest
---@param questName string
---@return number
function DAS.GetLogIndex(questName)
return DAS.QuestNameTable[questName] or 0
end
function DAS.handleLog()
return DAS.GetShareableLog()
end