-
Notifications
You must be signed in to change notification settings - Fork 9
/
FurCData.lua
633 lines (559 loc) · 20.5 KB
/
FurCData.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
local currentChar = FurC.CharacterName
local task = LibAsync:Create("FurnitureCatalogue_ScanDataFiles")
local lastLink = nil
local recipeArray = nil
local ver = FurC.Constants.Versioning
local src = FurC.Constants.ItemSources
local getItemId = FurC.Utils.GetItemId
local getItemLink = FurC.Utils.GetItemLink
local getCurrentChar = FurC.Utils.GetCurrentChar
local function printItemLink(itemId)
if nil == itemId then
return
end
itemId = tostring(itemId)
local itemLink = nil
if #itemId > 55 then
itemLink = itemId
end
itemLink = itemLink or zo_strformat("|H1:item:<<1>>:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", itemId)
FurC.Logger:Info("[%s] = '',\t\t-- %s", itemId, GetItemLinkName(itemLink))
end
FurC.PrintItemLink = printItemLink
local function addDatabaseEntry(recipeKey, recipeArray)
if recipeKey and recipeArray and {} ~= recipeArray then
if FurC.settings.data[recipeKey] ~= nil then
for k, v in pairs(recipeArray) do
FurC.settings.data[recipeKey][k] = v
end
else
FurC.settings.data[recipeKey] = recipeArray
end
end
end
local function makeMaterial(recipeKey, recipeArray, tryPlaintext, forcePlaintext)
if
nil == recipeArray
or (nil == recipeArray.blueprint and nil == recipeArray.recipeIndex and nil == recipeArray.recipeListIndex)
then
return "couldn't get material list, please re-scan character knowledge"
end
local ret = ""
local ingredients = FurC.GetIngredients(recipeKey, recipeArray)
forcePlaintext = forcePlaintext or tryPlaintext and NonContiguousCount(ingredients) > 4
for ingredientLink, qty in pairs(ingredients) do
-- auto-capitalize because for some reason the ZOS API doesn't
local itemText = (
forcePlaintext and string.gsub(" " .. GetItemLinkName(ingredientLink), "%W%l", string.upper):sub(2)
) or ingredientLink
ret = zo_strformat("<<1>> <<2>>x <<3>>, ", ret, qty, itemText)
end
return ret:sub(0, -3)
end
FurC.GetMats = makeMaterial
function FurC.GetIngredients(itemLink, recipeArray)
recipeArray = recipeArray or FurC.Find(itemLink)
local ingredients = {}
if {} ~= recipeArray and recipeArray.blueprint then
local blueprintLink = getItemLink(recipeArray.blueprint)
local numIngredients = GetItemLinkRecipeNumIngredients(blueprintLink)
for ingredientIndex = 1, numIngredients do
local name, _, qty = GetItemLinkRecipeIngredientInfo(blueprintLink, ingredientIndex)
local ingredientLink = GetItemLinkRecipeIngredientItemLink(blueprintLink, ingredientIndex, LINK_STYLE_DEFAULT)
ingredients[ingredientLink] = qty
end
else
local _, name, numIngredients = GetRecipeInfo(recipeArray.recipeListIndex, recipeArray.recipeIndex)
for ingredientIndex = 1, numIngredients do
local name, _, qty =
GetRecipeIngredientItemInfo(recipeArray.recipeListIndex, recipeArray.recipeIndex, ingredientIndex)
local ingredientLink = GetRecipeIngredientItemLink(
recipeArray.recipeListIndex,
recipeArray.recipeIndex,
ingredientIndex,
LINK_STYLE_DEFAULT
)
ingredients[ingredientLink] = qty
end
end
return ingredients
end
local function parseFurnitureItem(itemLink, override) -- saves to DB, returns recipeArray
if
not (override or IsItemLinkPlaceableFurniture(itemLink) or GetItemLinkItemType(itemLink) == ITEMTYPE_FURNISHING)
then
return
end
local recipeKey = GetItemLinkItemId(itemLink)
local recipeArray = FurC.settings.data[recipeKey]
if nil ~= recipeArray then
return recipeArray
end
recipeArray = {}
addDatabaseEntry(recipeKey, recipeArray)
return recipeArray
end
local function parseBlueprint(blueprintLink) -- saves to DB, returns recipeArray
local itemLink = GetItemLinkRecipeResultItemLink(blueprintLink, LINK_STYLE_BRACKETS)
local blueprintId = getItemId(blueprintLink)
local recipeKey = getItemId(itemLink)
if
nil == recipeKey -- we don't have a key to access the database
or nil == itemLink -- we don't have an item link to parse
or nil == GetItemLinkName(itemLink) -- we didn't find an item result for our recipe
then
return
end
local recipeArray = FurC.settings.data[recipeKey] or {}
recipeArray.origin = recipeArray.origin or src.CRAFTING
recipeArray.craftingSkill = recipeArray.craftingSkill or GetItemLinkCraftingSkillType(blueprintLink)
recipeArray.blueprint = recipeArray.blueprint or getItemId(blueprintLink)
if IsItemLinkRecipeKnown(blueprintLink) then
local recipeChars = recipeArray.characters
if nil ~= recipeChars then
recipeChars[FurC.CharacterName] = true
else
recipeArray.characters = {}
recipeArray.characters[FurC.CharacterName] = true
end
end
addDatabaseEntry(recipeKey, recipeArray)
return recipeArray
end
---sets recipeArray, returns it
---@param itemOrBlueprintLink any
---@return table
function FurC.Find(itemOrBlueprintLink)
if tonumber(itemOrBlueprintLink) == itemOrBlueprintLink then
itemOrBlueprintLink = getItemLink(itemOrBlueprintLink)
end
-- do not return empty arrays. If this returns nil, abort!
if nil == itemOrBlueprintLink or #itemOrBlueprintLink == 0 then
return {}
end
if itemOrBlueprintLink == lastLink and nil ~= recipeArray then
return recipeArray
else
recipeArray = nil
lastLink = itemOrBlueprintLink
end
if IsItemLinkFurnitureRecipe(itemOrBlueprintLink) then
recipeArray = parseBlueprint(itemOrBlueprintLink)
elseif IsItemLinkPlaceableFurniture(itemOrBlueprintLink) then
recipeArray = parseFurnitureItem(itemOrBlueprintLink)
else
itemId = getItemId(itemOrBlueprintLink)
if itemId ~= nil and tonumber(itemId) > 0 and FurC.settings.data ~= nil then
recipeArray = FurC.settings.data[itemId]
end
end
return recipeArray or {}
end
function FurC.Delete(itemOrBlueprintLink) -- sets recipeArray, returns it - calls scanItemLink
local recipeArray = getItemId(itemOrBlueprintLink)
if nil == recipeArray then
return
end
if nil ~= recipeArray.itemId then
FurC.settings.data[recipeArray.itemId] = nil
end
end
function FurC.GetEntry(itemOrBlueprintLink)
local itemLink = (IsItemLinkFurnitureRecipe(itemOrBlueprintLink) and GetRecipeResultItemLink(itemOrBlueprintLink))
or itemOrBlueprintLink
local recipeArray = FurC.Find(itemLink)
FurC.Logger:Debug("Trying to get entry for %s: %s", itemLink, recipeArray)
if not recipeArray then
return
end
local itemId = getItemId(itemOrBlueprintLink)
if recipeArray.blueprint then
itemId = getItemId(GetItemLinkRecipeResultItemLink(blueprintLink))
end
return itemId, recipeArray
end
function FurC.IsFavorite(itemLink, recipeArray)
recipeArray = recipeArray or FurC.Find(itemLink)
return recipeArray.favorite
end
-- ToDo: move to fave reference table?
function FurC.Fave(itemLink, recipeArray)
recipeArray = recipeArray or FurC.Find(itemLink)
recipeArray.favorite = not recipeArray.favorite
if not recipeArray.favorite then
recipeArray.favorite = nil
end
FurC.UpdateGui()
end
local function scanRecipeIndices(recipeListIndex, recipeIndex) -- returns recipeArray or nil, initialises
local itemLink = GetRecipeResultItemLink(recipeListIndex, recipeIndex, LINK_STYLE_BRACKETS)
if nil == itemLink or #itemLink == 0 or not IsItemLinkPlaceableFurniture(itemLink) then
return
end
local recipeKey = getItemId(itemLink)
local recipeArray = FurC.settings.data[recipeKey] or {}
recipeArray.origin = src.CRAFTING
recipeArray.version = recipeArray.version or 2
recipeArray.recipeListIndex = recipeArray.recipeListIndex or recipeListIndex
recipeArray.recipeIndex = recipeArray.recipeIndex or recipeIndex
recipeArray.characters = recipeArray.characters or {}
if GetRecipeInfo(recipeListIndex, recipeIndex) then
recipeArray.characters[getCurrentChar()] = true
FurC.settings.accountCharacters = FurC.settings.accountCharacters or {}
FurC.settings.accountCharacters[getCurrentChar()] = FurC.settings.accountCharacters[getCurrentChar()] or true
end
addDatabaseEntry(recipeKey, recipeArray)
return recipeArray
end
function FurC.TryCreateRecipeEntry(recipeListIndex, recipeIndex) -- returns scanRecipeIndices, called from Events.lua
return scanRecipeIndices(recipeListIndex, recipeIndex)
end
function FurC.IsAccountKnown(recipeKey, recipeArray)
if recipeKey == nil and recipeArray == nil then
return false
end
recipeArray = recipeArray or FurC.settings.data[recipeKey]
return not (nil == recipeArray or nil == recipeArray.characters or NonContiguousCount(recipeArray.characters) == 0)
end
function FurC.CanCraft(recipeKey, recipeArray)
if recipeKey == nil and recipeArray == nil then
return false
end
recipeArray = recipeArray or FurC.settings.data[recipeKey]
if FurC.IsAccountKnown(recipeKey, recipeArray) then
return recipeArray.characters[getCurrentChar()]
end
return false
end
function FurC.GetCraftingSkillType(recipeKey, recipeArray)
local itemLink = getItemLink(recipeKey)
local craftingSkillType = GetItemLinkCraftingSkillType(itemLink)
if 0 == craftingSkillType and recipeArray.blueprint then
craftingSkillType = GetItemLinkRecipeCraftingSkillType(getItemLink(recipeArray.blueprint))
elseif 0 == craftingSkillType and recipeArray.recipeListIndex and recipeArray.recipeIndex then
_, _, _, _, _, _, craftingSkillType = GetRecipeInfo(recipeArray.recipeListIndex, recipeArray.recipeIndex)
end
return craftingSkillType
end
local function scanCharacter()
local listName, numRecipes
for recipeListIndex = 1, GetNumRecipeLists() do
listName, numRecipes = GetRecipeListInfo(recipeListIndex)
for recipeIndex = 1, numRecipes do
scanRecipeIndices(recipeListIndex, recipeIndex) -- returns true on success
end
end
FurC.Logger:Debug(GetString(SI_FURC_DEBUG_CHARSCANCOMPLETE))
end
FurC.ScanCharacter = scanCharacter
function FurC.RescanRumourRecipes()
local function rescan()
for itemId, recipeArray in pairs(FurC.settings.data) do
if recipeArray.source == src.RUMOUR then
local itemLink = recipeArray[itemLink]
if not FurC.RumourRecipes[itemLink] then
recipeArray.source = src.CRAFTING
recipeArray.origin = nil
end
end
end
end
if nil ~= task then
task:Call(rescan):Then(FurC.UpdateGui)
else
rescan()
FurC.UpdateGui()
end
end
local recipeArray
local function scanFromFiles(shouldScanCharacter)
local function parseZoneData(zoneName, zoneData, versionNumber, origin)
for vendorName, vendorData in pairs(zoneData) do
for itemId, itemData in pairs(vendorData) do
recipeArray = parseFurnitureItem(getItemLink(itemId), true)
if not recipeArray then
FurC.Logger:Debug("Error when scanning %s", itemId)
else
recipeArray.origin = origin
recipeArray.version = versionNumber
addDatabaseEntry(itemId, recipeArray)
end
end
end
end
local function scanRecipeFile()
local recipeKey, recipeArray
local function makeKeySet(versionData)
local keySet = {}
for k, v in pairs(versionData) do
table.insert(keySet, k)
end
return keySet
end
local function scanArray(ary, versionNumber, origin)
if nil == ary then
return
end
for _, recipeId in ipairs(ary) do
local recipeLink = getItemLink(recipeId)
local itemLink = GetItemLinkRecipeResultItemLink(recipeLink) or getItemLink(recipeId)
recipeArray = FurC.Find(itemLink) or parseBlueprint(recipeLink) or parseFurnitureItem(itemLink)
local recipeListIndex, recipeIndex = GetItemLinkGrantedRecipeIndices(recipeLink)
if nil == recipeArray then
FurC.Logger:Debug("scanRecipeFile: error for ID %s - %s", recipeId, itemLink)
else
recipeKey = getItemId(itemLink)
recipeArray.version = versionNumber
if not recipeArray.origin or origin ~= src.RUMOUR then
recipeArray.origin = origin
end
recipeArray.blueprint = recipeId
addDatabaseEntry(recipeKey, recipeArray)
end
end
end
for versionNumber, versionData in pairs(FurC.Recipes) do
scanArray(versionData, versionNumber, src.CRAFTING)
end
for versionNumber, versionData in pairs(FurC.RolisRecipes) do
scanArray(makeKeySet(versionData), versionNumber, src.CRAFTING)
end
for versionNumber, versionData in pairs(FurC.FaustinaRecipes) do
scanArray(makeKeySet(versionData), versionNumber, src.CRAFTING)
end
end
local function scanRolis()
for versionNumber, versionData in pairs(FurC.Rolis) do
for itemId, itemSource in pairs(versionData) do
recipeArray = parseFurnitureItem(getItemLink(itemId), true)
if nil ~= recipeArray then
recipeArray.version = versionNumber
recipeArray.origin = src.ROLIS
addDatabaseEntry(itemId, recipeArray)
end
end
end
for versionNumber, versionData in pairs(FurC.Faustina) do
for itemId, itemSource in pairs(versionData) do
recipeArray = parseFurnitureItem(getItemLink(itemId), true)
if nil ~= recipeArray then
recipeArray.version = versionNumber
recipeArray.origin = src.ROLIS
addDatabaseEntry(itemId, recipeArray)
end
end
end
end
local function scanFestivalFiles()
for versionNumber, versionData in pairs(FurC.EventItems) do
for eventName, eventData in pairs(versionData) do
for eventItemSource, eventItemData in pairs(eventData) do
for itemId, _ in pairs(eventItemData) do
recipeArray = {}
recipeArray.craftable = false
recipeArray.version = versionNumber
recipeArray.origin = src.FESTIVAL_DROP
addDatabaseEntry(itemId, recipeArray)
end
end
end
end
end
local function scanMiscItemFile()
for versionNumber, versionData in pairs(FurC.MiscItemSources) do
for origin, originData in pairs(versionData) do
for itemId, itemSource in pairs(originData) do
local itemLink = getItemLink(itemId)
recipeArray = parseFurnitureItem(getItemLink(itemId))
if nil ~= recipeArray then
recipeArray.version = versionNumber
-- make sure that we don't set rumour source from data file.
if not recipeArray.origin or origin ~= src.RUMOUR or recipeArray.origin == src.RUMOUR then
recipeArray.origin = origin
end -- 3.5: moved src.RUMOUR to beginning of table so it'll get overwritten
addDatabaseEntry(itemId, recipeArray)
else
if origin == src.RUMOUR then
FurC.Logger:Debug("invalid rumour item: %s (%s)", itemId, getItemLink(itemId))
else
FurC.Logger:Debug("scanMiscItemFile: Error when scanning item ID %s (origin %s)", itemId, origin)
end
end
end
end
end
end
local function scanVendorFiles()
FurC.InitAchievementVendorList()
local recipeKey, recipeArray, itemSource
for versionNumber, versionData in pairs(FurC.AchievementVendors) do
for zoneName, zoneData in pairs(versionData) do
parseZoneData(zoneName, zoneData, versionNumber, src.VENDOR)
end
end
for versionNumber, vendorData in pairs(FurC.LuxuryFurnisher) do
for itemId, itemData in pairs(vendorData) do
local recipeArray = {}
recipeArray.origin = src.LUXURY
recipeArray.version = versionNumber
addDatabaseEntry(itemId, recipeArray)
end
end
for versionNumber, versionData in pairs(FurC.PVP) do
for zoneName, zoneData in pairs(versionData) do
parseZoneData(zoneName, zoneData, versionNumber, src.PVP)
end
end
end
local function scanRumours()
for versionNumber, items in pairs(FurC.Rumours) do
for itemId, itemSource in pairs(items) do
recipeArray = parseFurnitureItem(getItemLink(itemId), true)
if nil ~= recipeArray then
recipeArray.version = versionNumber
recipeArray.origin = src.RUMOUR
addDatabaseEntry(itemId, recipeArray)
end
end
end
for index, blueprintId in pairs(FurC.RumourRecipes) do
local blueprintLink = getItemLink(blueprintId)
local itemLink = GetItemLinkRecipeResultItemLink(blueprintLink, LINK_STYLE_BRACKETS)
if #itemLink == 0 then
itemLink = blueprintLink
end
local itemId = getItemId(itemLink)
recipeArray = parseBlueprint(blueprintLink) or parseFurnitureItem(itemLink) or {}
if blueprintId ~= itemId then
recipeArray.blueprint = blueprintId
end
recipeArray.recipeListIndex, recipeArray.recipeIndex = GetItemLinkGrantedRecipeIndices(blueprintLink)
recipeArray.origin = src.RUMOUR
recipeArray.verion = recipeArray.version or ver.HOMESTEAD
addDatabaseEntry(itemId, recipeArray)
end
end
local function scanCharacterOrMaybeNot()
if shouldScanCharacter then
scanCharacter()
end
end
FurC.IsLoading(true)
if nil ~= task then
task
:Call(scanRecipeFile)
:Then(scanMiscItemFile)
:Then(scanVendorFiles)
:Then(scanRolis)
:Then(scanFestivalFiles)
:Then(scanCharacterOrMaybeNot)
:Then(scanRumours)
:Then(FurC.UpdateGui)
else
scanRecipeFile()
scanMiscItemFile()
scanVendorFiles()
scanRolis()
scanFestivalFiles()
scanCharacterOrMaybeNot()
scanRumours()
FurC.UpdateGui()
end
end
FurC.ScanFromFiles = scanFromFiles
local function getScanFromFiles()
if FurC.settings.version < FurC.version then
FurC.settings.version = FurC.version
return true
end
return FurC.settings.data == {}
end
local function getScanCharacter()
if nil == FurC.settings.accountCharacters[FurC.CharacterName] then
FurC.settings.accountCharacters[FurC.CharacterName] = false
return true
end
end
function FurC.ScanRecipes(shouldScanFiles, shouldScanCharacter) -- returns database
shouldScanFiles = shouldScanFiles or getScanFromFiles()
shouldScanCharacter = (shouldScanCharacter or getScanCharacter())
if shouldScanFiles then
FurC.Logger:Debug(GetString(SI_FURC_VERBOSE_SCANNING_DATA_FILE))
scanFromFiles(shouldScanCharacter)
elseif shouldScanCharacter then
FurC.Logger:Debug(GetString(SI_FURC_VERBOSE_SCANNING_CHARS))
scanCharacter()
end
end
function FurC.GetItemDescription(recipeKey, recipeArray, stripColor)
recipeKey = getItemId(recipeKey)
FurC.settings.emptyItemSources = FurC.settings.emptyItemSources or {}
recipeArray = recipeArray or FurC.Find(recipeKey)
if {} == recipeArray then
return ""
end
local origin = recipeArray.origin
if origin == src.CRAFTING or origin == src.WRIT_VENDOR then
return FurC.GetMats(recipeKey, recipeArray, stripColor)
end
if origin == src.ROLIS then
return FurC.getRolisSource(recipeKey, recipeArray, stripColor)
end
if origin == src.LUXURY then
return FurC.getLuxurySource(recipeKey, recipeArray, stripColor)
end
if origin == src.GUILDSTORE then
return GetString(SI_FURC_SEEN_IN_GUILDSTORE)
end
if origin == src.VENDOR then
return FurC.getAchievementVendorSource(recipeKey, recipeArray, stripColor)
end
if origin == src.FESTIVAL_DROP then
return FurC.getEventDropSource(recipeKey, recipeArray, stripColor)
end
if origin == src.PVP then
return FurC.getPvpSource(recipeKey, recipeArray, stripColor)
end
if origin == src.RUMOUR then
return FurC.getRumourSource(recipeKey, recipeArray, stripColor)
end
return FurC.getMiscItemSource(recipeKey, recipeArray, stripColor)
end
function FurC.ShouldBeInFurC(link)
link = getItemLink(link)
if not link then
return false
end
if IsItemLinkPlaceableFurniture(link) then
return nil == FurC.settings.data[getItemId(link)]
end
-- if not IsItemLinkFurnitureRecipe(link) then return false end
local resultLink = GetItemLinkRecipeResultItemLink(link, LINK_STYLE_BRACKETS)
if not resultLink then
return false
end
local resultId = getItemId(resultLink)
local recipeId = getItemId(link)
if not resultId or not recipeId or not IsItemLinkPlaceableFurniture(resultLink) then
return false
end
for _, versionData in pairs(FurC.Recipes) do
for _, id in ipairs(versionData) do
if id == recipeId then
return false
end
end
end
for _, versionData in pairs(FurC.FaustinaRecipes) do
if versionData[recipeId] then
return false
end
end
for _, versionData in pairs(FurC.RolisRecipes) do
if versionData[recipeId] then
return false
end
end
-- yeah okay, it should actually return false, but this is a util function for datamining
return nil == FurC.settings.data[resultId]
end