-
Notifications
You must be signed in to change notification settings - Fork 8
/
MasterMerchant_Utils.lua
235 lines (205 loc) · 8.72 KB
/
MasterMerchant_Utils.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
local mmUtils = _G["MasterMerchant_Internal"]
local internal = _G["LibGuildStore_Internal"]
-- itemCache: formerly MasterMerchant.itemInformationCache
local itemCache = _G["MasterMerchant_ItemCache"]
local bonanzaCache = _G["MasterMerchant_BonanzaCache"]
-- /script _G["MasterMerchant_ItemCache"] = {}
-- Formerly ResetItemInformationCache
function mmUtils:ResetItemCache()
itemCache = { }
end
function mmUtils:ResetBonanzaCache()
bonanzaCache = { }
end
function mmUtils:ResetItemAndBonanzaCache()
mmUtils:ResetItemCache()
mmUtils:ResetBonanzaCache()
end
function mmUtils:ItemCacheHasPriceInfoById(theIID, itemIndex, daysRange)
local cache = itemCache
local itemInfo = cache[theIID] and cache[theIID][itemIndex] and cache[theIID][itemIndex][daysRange]
if itemInfo and itemInfo.avgPrice then return true end
return false
end
function mmUtils:ItemCacheHasInfoByItemLink(itemLink, daysRange)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
return mmUtils:ItemCacheHasPriceInfoById(itemID, itemIndex, daysRange)
end
-- Formerly ItemCacheHasBonanzaInfoById
function mmUtils:BonanzaCacheHasPriceInfoById(theIID, itemIndex, daysRange)
local cache = bonanzaCache
local itemInfo = cache[theIID] and cache[theIID][itemIndex] and cache[theIID][itemIndex][daysRange]
if itemInfo and itemInfo.bonanzaPrice then return true end
return false
end
function mmUtils:BonanzaCacheHasInfoByItemLink(itemLink, daysRange)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
return mmUtils:BonanzaCacheHasPriceInfoById(itemID, itemIndex, daysRange)
end
-- Formerly ItemCacheStats
function mmUtils:GetItemCacheStats(itemLink, daysRange)
local cache = itemCache
if mmUtils:ItemCacheHasInfoByItemLink(itemLink, daysRange) then
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
return cache[itemID][itemIndex][daysRange]
end
return nil
end
function mmUtils:GetBonanzaCacheStats(itemLink, daysRange)
local cache = bonanzaCache
if mmUtils:BonanzaCacheHasInfoByItemLink(itemLink, daysRange) then
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
return cache[itemID][itemIndex][daysRange]
end
return nil
end
-- This function is used to set item information in the cache.
-- It accepts the item's ID, itemIndex, daysRange, and itemInfo table.
-- The itemInfo table contains various information about the item.
function mmUtils:SetItemCacheById(itemID, itemIndex, daysRange, itemInfo)
-- Get the cache table for item information
local cache = itemCache
-- Initialize the cache structure if it doesn't exist yet
-- This ensures that the necessary nested tables are in place to store the item information
cache[itemID] = cache[itemID] or {}
cache[itemID][itemIndex] = cache[itemID][itemIndex] or {}
cache[itemID][itemIndex][daysRange] = cache[itemID][itemIndex][daysRange] or {}
-- Loop over each key-value pair in the itemInfo table
for key, value in pairs(itemInfo) do
-- Assign the value to the corresponding key in the cache
-- Note: We use a loop to assign individual values to the cache,
-- as graphInfo is assigned to the cache separately
cache[itemID][itemIndex][daysRange][key] = value
end
end
-- Formerly ItemCacheHasGraphInfoById
function mmUtils:CacheHasGraphInfoById(theIID, itemIndex, daysRange)
local cache = itemCache
local itemInfo = cache[theIID] and cache[theIID][itemIndex] and cache[theIID][itemIndex][daysRange]
if itemInfo and itemInfo.graphInfo then return true end
return false
end
function mmUtils:SetGraphInfoCacheById(itemID, itemIndex, daysRange, graphInfo)
local cache = itemCache
cache[itemID] = cache[itemID] or {}
cache[itemID][itemIndex] = cache[itemID][itemIndex] or {}
cache[itemID][itemIndex][daysRange] = cache[itemID][itemIndex][daysRange] or {}
cache[itemID][itemIndex][daysRange].graphInfo = graphInfo
end
function mmUtils:SetItemCacheByItemLink(itemLink, daysRange, itemInfo)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
mmUtils:SetItemCacheById(itemID, itemIndex, daysRange, itemInfo)
end
function mmUtils:SetBonanzaCacheById(itemID, itemIndex, daysRange, itemInfo)
local cache = itemCache
cache[itemID] = cache[itemID] or {}
cache[itemID][itemIndex] = cache[itemID][itemIndex] or {}
cache[itemID][itemIndex][daysRange] = itemInfo
end
function mmUtils:SetBonanzaCacheByItemLink(itemLink, daysRange, itemInfo)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
mmUtils:SetBonanzaCacheById(itemID, itemIndex, daysRange, itemInfo)
end
-- Formerly ClearPriceCacheById
function mmUtils:ClearItemCacheById(itemID, itemIndex)
local cache = itemCache
local itemInfo = cache[itemID] and cache[itemID][itemIndex]
if itemInfo then
for daysRange, info in pairs(itemInfo) do
info.avgPrice = nil
info.numSales = nil
info.numDays = nil
info.numItems = nil
info.numVouchers = nil
info.graphInfo = nil
end
end
end
-- Formerly ClearBonanzaCachePriceById
function mmUtils:ClearBonanzaCacheById(itemID, itemIndex)
local cache = bonanzaCache
local itemInfo = cache[itemID] and cache[itemID][itemIndex]
if itemInfo then
for daysRange, info in pairs(itemInfo) do
info.bonanzaPrice = nil
info.bonanzaListings = nil
info.bonanzaItemCount = nil
end
end
end
function mmUtils:ClearItemCacheByItemLink(itemLink)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
mmUtils:ClearItemCacheById(itemID, itemIndex)
end
-- /script mmUtils:ClearBonanzaPriceCacheByItemLink("|H1:item:54173:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h")
function mmUtils:ClearBonanzaPriceCacheByItemLink(itemLink)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
mmUtils:ClearBonanzaCacheById(itemID, itemIndex)
end
function mmUtils:GetGuildSales(guildName, displayName, dateRange)
local amountSold = (internal.guildSales and
internal.guildSales[guildName] and
internal.guildSales[guildName].sellers and
internal.guildSales[guildName].sellers[displayName] and
internal.guildSales[guildName].sellers[displayName].sales) and
internal.guildSales[guildName].sellers[displayName].sales[dateRange] or 0
return amountSold
end
function mmUtils:GetSalesCount(guildName, displayName, dateRange)
local countSold = (internal.guildSales and
internal.guildSales[guildName] and
internal.guildSales[guildName].sellers and
internal.guildSales[guildName].sellers[displayName] and
internal.guildSales[guildName].sellers[displayName].count) and
internal.guildSales[guildName].sellers[displayName].count[dateRange] or 0
return countSold
end
function mmUtils:GetSalesTaxes(guildName, displayName, dateRange)
local taxes = (internal.guildSales and
internal.guildSales[guildName] and
internal.guildSales[guildName].sellers and
internal.guildSales[guildName].sellers[displayName] and
internal.guildSales[guildName].sellers[displayName].tax) and
internal.guildSales[guildName].sellers[displayName].tax[dateRange] or 0
return taxes
end
function mmUtils:GetGuildPurchases(guildName, displayName, dateRange)
local amountPurchased = (internal.guildPurchases and
internal.guildPurchases[guildName] and
internal.guildPurchases[guildName].sellers and
internal.guildPurchases[guildName].sellers[displayName] and
internal.guildPurchases[guildName].sellers[displayName].sales) and
internal.guildPurchases[guildName].sellers[displayName].sales[dateRange] or 0
return amountPurchased
end
local MM_RANGE_CHOICES = {
[MM_RANGE_VALUE_NONE] = GetString(MM_RANGE_NONE),
[MM_RANGE_VALUE_ALL] = GetString(MM_RANGE_ALL),
[MM_RANGE_VALUE_FOCUS1] = GetString(MM_RANGE_FOCUS1),
[MM_RANGE_VALUE_FOCUS2] = GetString(MM_RANGE_FOCUS2),
[MM_RANGE_VALUE_FOCUS3] = GetString(MM_RANGE_FOCUS3),
}
function mmUtils:CreateDaysRangeChoices()
for rangeConstant, rangeString in pairs(MM_RANGE_CHOICES) do
MasterMerchant.daysRangeChoices[rangeConstant] = rangeString
MasterMerchant.daysRangeValues[rangeConstant] = rangeConstant
MasterMerchant.daysRangeLookup[rangeString] = rangeConstant
end
end
function mmUtils:UpdateDaysRangeSettings()
local keys = { "defaultDays", "shiftDays", "ctrlDays", "ctrlShiftDays" }
for _, key in ipairs(keys) do
local value = MasterMerchant.systemSavedVariables[key]
if type(value) == 'string' and MasterMerchant.daysRangeLookup[value] then
MasterMerchant.systemSavedVariables[key] = MasterMerchant.daysRangeLookup[value]
end
end
end