-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDASData.lua
186 lines (169 loc) · 5.4 KB
/
DASData.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
local DAS = DailyAutoShare
local p = DAS.DebugOut
function DAS.GetZoneId()
local ret = GetZoneId(GetUnitZoneIndex(UNITTAG_PLAYER))
if not ret then return 0 end
return DAS.subzones[ret] or ret
end
local typeTable = "table"
local typeString = "string"
local function evaluateNestedLists(tbl, zoneId)
if not tbl or {} == tbl then return tbl end
local addToRet = {}
for key, value in pairs(tbl) do
-- unpack sublists with string keys, because those are festival lists or so
if type(value) == typeTable and typeString == type(key) then
if DAS.GetActiveIn(key) then
if (DAS.QuestListTitles[zoneId] or {})[key] then
value._key = key
table.insert(addToRet, value)
else
for _, questName in pairs(value) do
table.insert(addToRet, questName)
end
end
end
else
table.insert(addToRet, value)
end
end
local ret = {}
for _, questName in pairs(addToRet) do
table.insert(ret, questName)
end
return ret
end
function DAS.GetZoneQuests(zoneId)
-- check if we have an ID
zoneId = zoneId or DAS.GetZoneId()
-- check if we're someone's subzone
zoneId = DAS.subzones[zoneId] or zoneId
return evaluateNestedLists(DAS.shareables[zoneId] or {}, zoneId)
end
function DAS.questCompleted(id)
local questText, questType = GetCompletedQuestInfo(id)
return nil ~= questText and #questText > 0
end
function DAS.RefreshFullBingoString()
local ret = ""
for _, questName in ipairs(DAS.GetActiveQuestNamesFromGui()) do
local bingoString = DAS.GetBingoStringFromQuestName(questName)
ret = ret .. bingoString .. " "
end
if (#ret > 0) then
ret = ret .. "+any"
end
DAS.fullBingoString = ret
end
function DAS.IsQuestActive(questName)
local zoneId = DAS.GetZoneId()
local questList = DAS.QuestLists[zoneId] or {}
for questListName, questListData in pairs(questList) do
if questListData[questName] then
return (DAS.GetQuestListItem(zoneId, questListName, "active"))
end
end
return true
end
function DAS.GetBingoIndexFromMessage(messageText)
local bingoArray = DAS.bingo[DAS.GetZoneId()]
if nil == bingoArray then return end
for bingo, questindex in pairs(bingoArray) do
if messageText:match(bingo) then
return questindex
end
end
end
function DAS.GetBingoIndexFromQuestName(questName)
for questIndex, checkQuestName in pairs(DAS.GetZoneQuests()) do
if questName == checkQuestName then
return questIndex
end
end
return 99
end
function DAS.GetBingoStringFromQuestName(questName)
local index = DAS.GetBingoIndexFromQuestName(questName)
local ret = ""
local zoneId = DAS.GetZoneId()
if index == 99 then return ret end
local bingoArray = DAS.bingo[zoneId] or {}
for bingoString, bingoIndex in pairs(bingoArray) do
if bingoIndex == index then ret = bingoString end
end
local bingoFallback = DAS.bingoFallback[zoneId] or {}
ret = bingoFallback[ret] or ret
if ret ~= "" then
if not(string.find(ret, "%+")) then ret = "+" .. ret end
if (string.find(ret, "%+%+")) then ret.gsub("%+%+", "%+") end
end
return ret, index
end
---@param zoneId number
---@param subList string subList code
---@param questName string
---@param bingo string|nil _(optional)_ custom bingo code for this quest
function DAS.makeNestedZoneTable(zoneId, subList, questName, bingo)
DAS.shareables[zoneId] = DAS.shareables[zoneId] or {}
DAS.shareables[zoneId][subList] = DAS.shareables[zoneId][subList] or {}
table.insert(DAS.shareables[zoneId][subList], questName)
DAS.bingo[zoneId] = DAS.bingo[zoneId] or {}
DAS.bingo[zoneId][subList] = bingo or subList
end
local zoneCloneDebug = "Couldn't copy zone <<1>> to zone <<2>>, one of the IDs was nil"
function DAS.zoneHasAdditionalId(zoneId2, zoneId)
if not zoneId and zoneId2 then
d(zo_strformat(zoneCloneDebug, zoneId, zoneId2))
return
end
DAS.questIds[zoneId2] = DAS.questIds[zoneId]
DAS.shareables[zoneId2] = DAS.shareables[zoneId]
DAS.bingo[zoneId2] = DAS.bingo[zoneId]
DAS.QuestLists[zoneId2] = DAS.QuestLists[zoneId]
DAS.questStarter[zoneId2] = DAS.questStarter[zoneId]
DAS.questFinisher[zoneId2] = DAS.questFinisher[zoneId]
end
function DAS.GetQuestNameFromIndex(bingoIndex)
return DAS.GetZoneQuests()[bingoIndex]
end
function DAS.GetQuestNameFromBingoString(bingoString)
local bingoIndex = DAS.GetBingoIndexFromMessage(bingoString)
if nil == bingoIndex then return end
return DAS.GetQuestNameFromIndex(bingoIndex)
end
function DAS.GetActiveQuestNamesFromGui()
DAS.activeBingoIndices = {}
local ret = {}
local questLabel
for i=1, #DAS.labels do
questLabel = DAS.labels[i]
if questLabel.dataBingoIndex then
if not questLabel:IsHidden() and (questLabel.dataQuestState == DAS_STATUS_ACTIVE) or (questLabel.dataQuestState == DAS_STATUS_TRACKED) then
table.insert(ret, questLabel.dataQuestName)
DAS.activeBingoIndices[questLabel.dataBingoIndex] = true
end
end
end
return ret
end
function DAS.GetOpenQuestNamesFromGui()
local ret = {}
local questLabel
for i=1, #DAS.labels do
questLabel = DAS.labels[i]
if (questLabel.dataQuestState == DAS_STATUS_OPEN) then
table.insert(ret, questLabel.dataQuestName)
end
end
return ret
end
function DAS.CacheTrackedQuestLists()
DAS.trackedListZones = {}
for listName, isActive in pairs(DAS.GetSettings().trackedLists) do
if isActive then
for k, v in pairs(DAS.subLists[listName] or {}) do
DAS.trackedListZones[k] = v
end
end
end
end