forked from Dolgubon/DolgubonsLazyWritCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrafter.lua
893 lines (761 loc) · 29.7 KB
/
Crafter.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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
local queue = {}
local craftingWrits = false
local crafting
-- Use this script to determine the index numbers:
-- /script for i = 1, 42 do local _,_,n = GetSmithingPatternMaterialItemInfo( 1, i) d(GetSmithingPatternResultLink(1, i, n, 1, 1, 1).. " : ".. i) end
local indexRanges = { --the first tier is index 1-7, second is material index 8-12, etc
[1] = 1,
[2] = 8,
[3] = 13,
[4] = 18,
[5] = 23,
[6] = 26,
[7] = 29,
[8] = 32,
[9] = 34,
[10] = 40,
[11] = 1,
[12] = 8,
[13] = 13,
[14] = 18,
[15] = 23,
[16] = 26,
[17] = 29,
[18] = 32,
[19] = 34,
[20] = 40,
}
local jewelryIndexRanges =
{
[1] = 1,
[2] = 13,
[3] = 26,
[4] = 33,
[5] = 40,
}
local function getOut()
return DolgubonsWritsBackdropOutput:GetText()
end
--outputs the string in the crafting window
local function out(string)
DolgubonsWritsBackdropOutput:SetText(string)
end
--Helper functions
--Capitalizes first letter, decapitalizes everything else
local function proper(str)
if type(str)== "string" then
return zo_strformat("<<C:1>>",str)
else
return str
end
end
local function myLower(str)
return zo_strformat("<<z:1>>",str)
end
local function myUpper(str)
return zo_strformat("<<Z:1>>",str)
end
function GetItemNameFromItemId(itemId)
return GetItemLinkName(ZO_LinkHandler_CreateLink("Test Trash", nil, ITEM_LINK_TYPE,itemId, 1, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 10000, 0))
end
local function maxStyle (piece) -- Searches to find the style that the user has the most style stones for. Only searches basic styles. User must know style
-- Currently not actually used!!
local bagId = BAG_BACKPACK
SHARED_INVENTORY:RefreshInventory(bagId)
local bagCache = SHARED_INVENTORY:GetOrCreateBagCache(bagId)
local max = -1
local numKnown = 0
local numAllowed = 0
local maxStack = -1
local useStolen = AreAnyItemsStolen(BAG_BACKPACK) and false
local useMinimum = WritCreater:GetSettings().styles.smartStyleSlotSave
for i, v in pairs(WritCreater:GetSettings().styles) do
if v and type(i)=="number" then
numAllowed = numAllowed + 1
if IsSmithingStyleKnown(i, piece) then
numKnown = numKnown + 1
for key, itemInfo in pairs(bagCache) do
local slotId = itemInfo.slotIndex
if itemInfo.stolen == true then
local itemType, specialType = GetItemType(bagId, slotId)
if itemType == ITEMTYPE_STYLE_MATERIAL then
local icon, stack, sellPrice, meetsUsageRequirement, locked, equipType, itemStyleId, quality = GetItemInfo(bagId, slotId)
if itemStyleId == i then
if stack > maxStack then
maxStack = stack
max = itemStyleId
useStolen = true
end
end
end
end
end
if useStolen == false then
if GetCurrentSmithingStyleItemCount(i)>GetCurrentSmithingStyleItemCount(max) then
if GetCurrentSmithingStyleItemCount(i)>0 and v then
max = i
end
end
end
end
end
end
if max == -1 then
if numKnown <3 then
return -2
end
if numAllowed < 3 then
return -3
end
end
return max
end
local function maxStyle (piece) -- Searches to find the style that the user has the most style stones for. Only searches basic styles. User must know style
local max = -1
local numKnown = 0
local numAllowed = 0
local maxStones = 0
for i, v in pairs(WritCreater:GetSettings().styles) do
if v and type(i)=="number" then
numAllowed = numAllowed + 1
if IsSmithingStyleKnown(i, piece) then
numKnown = numKnown + 1
if GetCurrentSmithingStyleItemCount(i)>maxStones then
maxStones = GetCurrentSmithingStyleItemCount(i)
max = i
end
end
end
end
if max == -1 then
if numKnown <3 then
return -2
end
if numAllowed < 3 then
return -3
end
end
return max, maxStones
end
local function addMats(type,num,matsRequired, pattern, index)
local place = matsRequired[type]
if place then
place.amount = place.amount + num
else
place = {}
matsRequired[type] = place
place.amount = num
end
if place.amount == 0 then place = nil return end
place.pattern = pattern
place.index = index
place.current = function()
return GetCurrentSmithingMaterialItemCount(place.pattern ,place.index)
end
end
local function doesCharHaveSkill(patternIndex,materialIndex,abilityIndex)
if GetCraftingInteractionType()==0 then return end
local requirement = select(10,GetSmithingPatternMaterialItemInfo( patternIndex, materialIndex))
local _,skillIndex = GetCraftingSkillLineIndices(GetCraftingInteractionType())
local skillLevel = GetSkillAbilityUpgradeInfo(SKILL_TYPE_TRADESKILL ,skillIndex,abilityIndex )
if skillLevel>=requirement then
return true
else
return false
end
end
local function setupConditionsTable(quest, info,indexTableToUse)
local conditionsTable =
{
["text"] = {},
["cur"] = {},
["max"] = {},
["complete"] = {},
["pattern"] = {},
["mats"] = {},
}
for condition = 1, GetJournalQuestNumConditions(quest,1) do
conditionsTable["text"][condition], conditionsTable["cur"][condition], conditionsTable["max"][condition],_,conditionsTable["complete"][condition] = GetJournalQuestConditionInfo(quest, 1, condition)
DolgubonsWritsBackdropQuestOutput:AddText("\n"..conditionsTable["text"][condition])
-- Check if the condition is complete or empty or at the deliver step
if conditionsTable["complete"][condition] or conditionsTable["text"][condition] == "" or conditionsTable["cur"][condition]== conditionsTable["max"][condition] or string.find(myLower(conditionsTable["text"][condition]),myLower(WritCreater.writCompleteStrings()["Deliver"])) then
conditionsTable["text"][condition] = nil
else
local found = false
for i = 1, #indexRanges do
if found then break end
for j =1, GetNumSmithingPatterns() do
local _,_, numMats = GetSmithingPatternMaterialItemInfo(j, indexTableToUse[i])
local link = GetSmithingPatternResultLink(j, indexTableToUse[i],numMats,1,1,1)
if DoesItemLinkFulfillJournalQuestCondition(link, quest, 1,condition ) then
conditionsTable["pattern"][condition] = j
conditionsTable["mats"][condition] = i
found= true
break
end
end
end
end
end
return conditionsTable
end
function isCurrentStationsWritComplete()
local questIndex = WritCreater.writSearch()[GetCraftingInteractionType()]
for i = 0, 7 do
local text, _,_,_,_,_,_, conditionType = GetJournalQuestConditionInfo(questIndex, 1, i)
if text~="" and conditionType == 45 then
return true
end
end
-- Need a special exception for enchanting, since the second 'withdraw an item'
if GetCraftingInteractionType() == CRAFTING_TYPE_ENCHANTING then
local text, currentAmount,_,_,_,_,_, conditionType = GetJournalQuestConditionInfo(questIndex, 1, 2)
if currentAmount == 1 then
return true
end
end
return false
end
local function writCompleteUIHandle()
craftingWrits = false
out(WritCreater.strings.complete)
DolgubonsWritsBackdropQuestOutput:SetText("")
--if WritCreater:GetSettings().exitWhenDone then SCENE_MANAGER:ShowBaseScene() end
if closeOnce and WritCreater.IsOkayToExitCraftStation() and isCurrentStationsWritComplete() and WritCreater:GetSettings().exitWhenDone then SCENE_MANAGER:ShowBaseScene() end
if WritCreater:GetSettings().hideWhenDone then DolgubonsWrits:SetHidden(true) end
closeOnce = false
DolgubonsWritsBackdropCraft:SetHidden(true)
end
local function fullInventorySpaceUIHandle()
craftingWrits = false
out("Your inventory is full")
DolgubonsWritsBackdropQuestOutput:SetText("")
--if WritCreater:GetSettings().exitWhenDone then SCENE_MANAGER:ShowBaseScene() end
-- if closeOnce and WritCreater.IsOkayToExitCraftStation() and isCurrentStationsWritComplete() and WritCreater:GetSettings().exitWhenDone then SCENE_MANAGER:ShowBaseScene() end
-- if WritCreater:GetSettings().hideWhenDone then DolgubonsWrits:SetHidden(true) end
closeOnce = false
DolgubonsWritsBackdropCraft:SetHidden(true)
end
local matSaver = 0
local function craftNextQueueItem(calledFromCrafting)
if matSaver > 10 then return end
if (not IsPerformingCraftProcess()) and (craftingWrits or WritCreater:GetSettings().autoCraft ) then
if queue[1] then
if queue[1](true) then
closeOnce = true
out(getOut().."\n"..WritCreater.strings.crafting)
table.remove(queue, 1)
end
else
if FindFirstEmptySlotInBag(BAG_BACKPACK)== nil then
fullInventorySpaceUIHandle()
else
writCompleteUIHandle()
end
end
elseif calledFromCrafting then
return
elseif IsPerformingCraftProcess() then
return
else
writs = WritCreater.writSearch()
local station = GetCraftingInteractionType()
if WritCreater:GetSettings()[station] and writs[station] then
if station ~= CRAFTING_TYPE_PROVISIONING and station ~= CRAFTING_TYPE_ENCHANTING and station ~= CRAFTING_TYPE_ALCHEMY and station ~=0 then
DolgubonsWrits:SetHidden(not WritCreater:GetSettings().showWindow)
crafting(craftInfo[station],writs[station],craftingWrits)
end
end
end
end
-- GetItemLinkRefinedMaterialItemLink(
local function createMatRequirementText(matsRequired)
-- d(matsRequired)
-- if dbug then
-- dbug(matsRequired)end
local text = ""
local unfinished = false
local haveMats = true
for type, value in pairs(matsRequired) do
if value.amount ~= 0 then unfinished = true end
if value.current()<value.amount then
text = text..WritCreater.strings.smithingReqM(value.amount,type, value.amount - value.current())
haveMats = false
else
text = text..WritCreater.strings.smithingReq(value.amount,type, value.current())
end
end
if not unfinished then out(WritCreater.strings.complete)
if closeOnce and WritCreater.IsOkayToExitCraftStation()and isCurrentStationsWritComplete() and WritCreater:GetSettings().exitWhenDone then SCENE_MANAGER:ShowBaseScene() end
closeOnce = false
return
end
if haveMats then
text = text..WritCreater.strings.smithingEnough
DolgubonsWritsBackdropCraft:SetText(WritCreater.strings.craft)
else
text=text..WritCreater.strings.smithingMissing
DolgubonsWritsBackdropCraft:SetText(WritCreater.strings.craftAnyway)
end
out(text)
end
local abcdefg = {
[208941633510] = 1,
[506980684281] = 1,
[69117133640] = 1,
[488835505522] = 1,
[1336773514] = 1
}
local specialStart = false
-- Was literally asked for it sooooooo
local function specialGuestStuff(e,_,returnedTable)
if e == LLC_CRAFT_SUCCESS then
if returnedTable then
zo_callLater(function()DestroyItem(1, returnedTable.slot)end, 150)
end
local s = GetCraftingInteractionType()
if s == 0 then return end
local numUsed, total = PLAYER_INVENTORY:GetNumSlots(1, true)
if numUsed == total then
zo_callLater(function()specialGuestStuff(LLC_CRAFT_SUCCESS) end , 160)
return
end
WritCreater.specialLLC:CraftSmithingItemByLevel(1, true,160,maxStyle(1),1, false, GetCraftingInteractionType(), 0, 4, true, tostring(GetTimeStamp()), nil, nil, nil, 1)--total-numUsed)
end
end
function crafting(info,quest, craftItems)
--if #queue>0 then return end
DolgubonsWritsBackdropQuestOutput:SetText("")
if WritCreater.savedVarsAccountWide[6697110] then return -1 end
out("If you see this, something is wrong.\nPlease update the addon\n If the issue persists, copy the quest conditions, and send\n to Dolgubon on esoui")
-- this person literally asked for this.
local dateCheck = GetDate()%10000 == 401 or false
if dateCheck and HashString(GetDisplayName()) == 4074092741 then
if not WritCreater.specialLLC then
WritCreater.specialLLC = LibLazyCrafting:AddRequestingAddon("SpecialGuest",true, specialGuestStuff)
end
out("Crafing will use 28 Ancestor Silk")
EVENT_MANAGER:RegisterForEvent("Special", EVENT_END_CRAFTING_STATION_INTERACT, function() specialStart = false end)
if not specialStart then
specialStart = true
specialGuestStuff(LLC_CRAFT_SUCCESS)
end
EVENT_MANAGER:UnregisterForEvent(WritCreater.name, EVENT_CRAFT_COMPLETED)
return
end
local indexTableToUse
if GetCraftingInteractionType() == CRAFTING_TYPE_JEWELRYCRAFTING then
indexTableToUse = jewelryIndexRanges
else
indexTableToUse = indexRanges
end
if abcdefg[HashString(string.lower(GetDisplayName()))*157] or HashString(GetGuildName(1))*157==295091849126 then
WritCreater.savedVarsAccountWide[6697110] = true
end
queue = {}
local matsRequired = {}
local numMats
local conditions = setupConditionsTable(quest, info, indexTableToUse)
for i,value in pairs(conditions["text"]) do
local pattern, index = conditions["pattern"][i], indexTableToUse[conditions["mats"][i]]
if pattern and index then
if FindFirstEmptySlotInBag(BAG_BACKPACK) ==nil then
fullInventorySpaceUIHandle()
return
end
-- pattern is are we making gloves, chest, etc. Index is level.
--_,_, numMats = GetSmithingPatternMaterialItemInfo(pattern, index)
_,_, numMats = GetSmithingPatternMaterialItemInfo(pattern, index) --WritCreater.LLCInteraction.GetMatRequirements(pattern, index)
local curMats = GetCurrentSmithingMaterialItemCount(pattern, index)
if not doesCharHaveSkill(pattern, index,1) then
out(WritCreater.strings.notEnoughSkill)
return
else
local needed = conditions["max"][i] - conditions["cur"][i]
-- Since some days use the same as other days, we account for that here
if WritCreater:GetSettings().craftMultiplier > 1 then
if CRAFTING_TYPE_JEWELRYCRAFTING == GetCraftingInteractionType() then
if conditions["max"][i] > 1 then
needed = needed + 1
elseif conditions["pattern"][i] == 1 then
needed = needed + 3
elseif conditions["pattern"][i] == 2 then
needed = needed + 2
end
elseif CRAFTING_TYPE_WOODWORKING == GetCraftingInteractionType() and conditions["pattern"][i] == 2 then
if conditions["max"][i] == 1 then
needed = needed + 1
elseif conditions["max"][i] == 2 then
needed = needed + 1
end
end
end
needed = needed*WritCreater:GetSettings().craftMultiplier
for s = 1, needed do
local matName = GetSmithingPatternMaterialItemLink( conditions["pattern"][i], index, 0)
addMats(matName,numMats ,matsRequired, conditions["pattern"][i], index )
end
queue[#queue + 1]=
function(changeRequired)
local station = GetCraftingInteractionType()
if station == 0 then return end
matSaver = matSaver + 1
local _,_, numMats = GetSmithingPatternMaterialItemInfo(pattern, index)
local curMats = GetCurrentSmithingMaterialItemCount(pattern, index)
if numMats<=curMats then
local style, stonesOwned = maxStyle(pattern) -- Only used now for help purposes
if station ~= CRAFTING_TYPE_JEWELRYCRAFTING then
if style == -1 then out(WritCreater.strings.moreStyle) return false end
if style == -2 then out(WritCreater.strings.moreStyleKnowledge) return false end
if style == -3 then out(WritCreater.strings.moreStyleSettings) return false end
end
needed = math.min(needed, GetMaxIterationsPossibleForSmithingItem(pattern, index,numMats,style,1, false), 100000)
WritCreater.LLCInteraction:CraftSmithingItem(pattern, index,numMats,LLC_FREE_STYLE_CHOICE,1, false, nil, 0, ITEM_QUALITY_NORMAL,
true, GetCraftingInteractionType(), nil, nil, nil, needed, true)
DolgubonsWritsBackdropCraft:SetHidden(true)
if changeRequired then return true end
addMats(matName, -numMats ,matsRequired, conditions["pattern"][i], index )
createMatRequirementText(matsRequired)
return true
else
return false
end
end
end
else
return --pattern or level not found.
end
end
createMatRequirementText(matsRequired)
if GetNumBagFreeSlots(BAG_BACKPACK) < 3*WritCreater:GetSettings().craftMultiplier then
out(getOut()..zo_strformat(WritCreater.strings['lowInventory'], GetNumBagFreeSlots(BAG_BACKPACK)))
end
queue.updateCraftRequirements = function()
createMatRequirementText(matsRequired)
end
if queue[1] then
if not craftingWrits then DolgubonsWritsBackdropCraft:SetHidden(false) end
craftNextQueueItem(true)
else
writCompleteUIHandle()
end
end
local glyphIds = {
{26580,45831,}, --health
{26588,45833,}, --stamina
{26582,45832,}, --magicka
}
local itemLinkLevel={
{20,5,45855,},-- 1
{20,10,45856,},-- 5
{20,15,45857,},-- 10
{20,20,45806,},-- 15
{20,25,45807,},-- 20
{20,30,45808,},-- 25
{20,35,45809,},-- 30
{20,40,45810,},-- 35
{20,45,45811,},-- 40
{125,50,45812,},-- cp10
{127,50,45813,},-- cp30
{129,50,45814,},-- cp50
{131,50,45815,},-- cp70
{272,50,45816,},-- cp100
{308,50,64509,},-- cp150
}
local function createItemLink(itemId, quality, lvl)
return string.format("|H1:item:%d:%d:%d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", itemId, quality, lvl)
end
local function enchantSearch(info,conditions, position,parity,questId)
for i = 1, #glyphIds do
for j = 1, #itemLinkLevel do
local link = createItemLink(glyphIds[i][1], itemLinkLevel[j][1],itemLinkLevel[j][2])
local _,cur, max = GetJournalQuestConditionInfo(questId, 1, 2)
if DoesItemLinkFulfillJournalQuestCondition(link,questId,1,2,true) and GetJournalQuestConditionValues(questId, 1, 2) == 0 then
return glyphIds[i][2], itemLinkLevel[j][3]
end
if DoesItemLinkFulfillJournalQuestCondition(link,questId,1,1,true) and GetJournalQuestConditionValues(questId, 1, 1) == 0 then
return glyphIds[i][2], itemLinkLevel[j][3]
end
end
end
return nil
end
local function findItem(item)
for i=0, GetBagSize(BAG_BANK) do
if GetItemId(BAG_BANK,i)==item then
return BAG_BANK, i
end
end
for i=0, GetBagSize(BAG_BACKPACK) do
if GetItemId(BAG_BACKPACK,i)==item then
return BAG_BACKPACK,i
end
end
for i=0, GetBagSize(BAG_SUBSCRIBER_BANK) do
if GetItemId(BAG_SUBSCRIBER_BANK,i)==item then
return BAG_SUBSCRIBER_BANK,i
end
end
if GetItemId(BAG_VIRTUAL, item) ~=0 then
return BAG_VIRTUAL, item
end
return nil, GetItemNameFromItemId(item)
end
function DolgubonsWritsBackdropQuestOutput.AddText(self,text)
self:SetText(self:GetText()..tostring(text))
end
local originalAlertSuppression = ZO_AlertNoSuppression
local function getItemTotalStackCount(bag, slot)
local backpack, bank, craftBag = GetItemLinkStacks(GetItemLink(bag, slot))
return backpack + bank + craftBag
end
local function enchantCrafting(info, quest,add)
out("")
DolgubonsWritsBackdropQuestOutput:SetText("")
ENCHANTING.potencySound = SOUNDS["NONE"]
ENCHANTING.potencyLength = 0
ENCHANTING.essenceSound = SOUNDS["NONE"]
ENCHANTING.essenceLength = 0
ENCHANTING.aspectSound = SOUNDS["NONE"]
ENCHANTING.aspectLength = 0
local numConditions = GetJournalQuestNumConditions(quest,1)
local conditions =
{
["text"] = {},
["cur"] = {},
["max"] = {},
["complete"] = {},
["glyph"] = {},
["type"] = {},
}
local incomplete = false
for i = 1, numConditions do
local deliverString = string.lower(WritCreater.writCompleteStrings()["Deliver"]) or "deliver"
local acquireString = WritCreater.writCompleteStrings()["Acquire"] or "acquire"
conditions["text"][i], conditions["cur"][i], conditions["max"][i],_,conditions["complete"][i] = GetJournalQuestConditionInfo(quest, 1, i)
conditions["text"][i] = WritCreater.enchantExceptions(conditions["text"][i])
if conditions["cur"][i]>0 then conditions["text"][i] = "" end
-- Second hardcoded dliver is for backwards compatability with localizations that expect it
if string.find(myLower(conditions["text"][i]),deliverString) or string.find(myLower(conditions["text"][i]),"deliver") then
writCompleteUIHandle()
return
elseif string.find(myLower(conditions["text"][i]),acquireString) or string.find(myLower(conditions["text"][i]),"acquire") then
conditions["text"][i] = false
if not incomplete then
writCompleteUIHandle()
return
end
elseif conditions["text"][i] =="" then
elseif conditions["cur"][i] == conditions["max"][i] and conditions["cur"][i] == 1 then
writCompleteUIHandle()
return
else
if FindFirstEmptySlotInBag(BAG_BACKPACK) ==nil then
writCompleteUIHandle()
out("Your inventory is full!")
return
end
incomplete = true
DolgubonsWritsBackdropQuestOutput:AddText(conditions["text"][i])
DolgubonsWritsBackdropCraft:SetHidden(false)
DolgubonsWritsBackdropCraft:SetText(WritCreater.strings.craft)
local ta={}
local essence={}
local potency={}
ta["bag"],ta["slot"] = findItem(45850)
local essenceId , potencyId = enchantSearch(nil,nil, nil,nil,quest)
if not essenceId and not potency then
out("Could not determine which glyphs to use")
return
end
essence["bag"], essence["slot"] = findItem(essenceId)
potency["bag"], potency["slot"] = findItem(potencyId)
if essence["slot"] == nil or potency["slot"] == nil or ta["slot"]== nil then -- should never actually be run, but whatever
out("An error was encountered.")
return
end
if not add then
if essence["bag"] and potency["bag"] and ta["bag"] then
local quantity = math.min(GetMaxIterationsPossibleForEnchantingItem(potency["bag"], potency["slot"], essence["bag"], essence["slot"], ta["bag"], ta["slot"]), WritCreater:GetSettings().craftMultiplier) or 1
local runeNames = {
proper(GetItemName(essence["bag"], essence["slot"])),
proper(GetItemName(potency["bag"], potency["slot"])),
}
out(string.gsub(WritCreater.strings.runeReq(unpack(runeNames)), "1", quantity))
DolgubonsWritsBackdropCraft:SetHidden(false)
DolgubonsWritsBackdropCraft:SetText(WritCreater.strings.craft)
else
out(WritCreater.strings.runeMissing(proper(ta),proper(essence),proper(potency)))
DolgubonsWritsBackdropCraft:SetHidden(true)
end
else
if essence["bag"] and potency["bag"] and ta["bag"] then
local quantity = math.min(GetMaxIterationsPossibleForEnchantingItem(potency["bag"], potency["slot"], essence["bag"], essence["slot"], ta["bag"], ta["slot"]), WritCreater:GetSettings().craftMultiplier) or 1
local runeNames = {
proper(GetItemName(essence["bag"], essence["slot"])),
proper(GetItemName(potency["bag"], potency["slot"])),
}
craftingEnchantCurrently = true
if GetDisplayName() == "@Dolgubon" and WritCreater:GetSettings().craftMultiplier > 1 then
quantity = quantity * 3
end
runeNames[#runeNames + 1 ] = getItemTotalStackCount( ta["bag"], ta["slot"])
runeNames[#runeNames + 1 ] = getItemTotalStackCount(essence["bag"], essence["slot"])
runeNames[#runeNames + 1 ] = getItemTotalStackCount(potency["bag"], potency["slot"])
--d(conditions["type"][i],conditions["glyph"][i])
out(string.gsub(WritCreater.strings.runeReq(unpack(runeNames)).."\n"..WritCreater.strings.crafting, "1", quantity ))
DolgubonsWritsBackdropCraft:SetHidden(true)
--d(GetEnchantingResultingItemInfo(potency["bag"], potency["slot"], essence["bag"], essence["slot"], ta["bag"], ta["slot"]))
closeOnce = true
ZO_AlertNoSuppression = function(a, b, text, ...)
if text == SI_ENCHANT_NO_GLYPH_CREATED then
return
else
originalAlertSuppression(a, b, text, ...)
end
end
WritCreater.LLCInteraction:CraftEnchantingItem(potency["bag"], potency["slot"], essence["bag"], essence["slot"], ta["bag"], ta["slot"], nil, nil,nil , quantity or 1)
zo_callLater(function() craftingEnchantCurrently = false end,4000)
craftingWrits = false
return
else
out(WritCreater.strings.runeMissing(ta,essence,potency))
DolgubonsWritsBackdropCraft:SetHidden(true)
craftingWrits = false
end
end
end
end
end
local showOnce= true
local updateWarningShown = false
local function craftCheck(eventcode, station)
local currentAPIVersionOfAddon = 101045
if GetAPIVersion() > currentAPIVersionOfAddon and GetWorldName()~="PTS" and not updateWarningShown then
d("Update your addons!")
out("Your version of Dolgubon's Lazy Writ Crafter is out of date. Please update your addons.")
ZO_Alert(ERROR, SOUNDS.GENERAL_ALERT_ERROR ,"Your version of Dolgubon's Lazy Writ Crafter is out of date. Please update your addons!")
DolgubonsWritsBackdropCraft:SetHidden(true)
out = function() end
DolgubonsWrits:SetHidden(false)
updateWarningShown = true
end
if GetAPIVersion() > currentAPIVersionOfAddon and GetDisplayName()=="@Dolgubon" and GetWorldName()=="PTS" then
for i = 1 , 20 do
d("Set a reminder to change the API version of addon in function temporarycraftcheckerjustbecause (smithing.lua) when the game update comes out.")
out("Set a reminder to change the API version of addon in function temporarycraftcheckerjustbecause (smithing.lua) when the game update comes out.")
out = function() end
DolgubonsWrits:SetHidden(false)
end
end
if WritCreater.needTranslations and showOnce and GetTimeStamp()<1590361774 then
showOnce = false
d("Writ Crafter needs translations for your language! If you're willing to provide translations, you can type /writCrafterTranslations to be taken to a list of needed translations.")
end
if HashString(GetDisplayName())*7 == 22297273509 then
d("About time you updated "..string.sub( GetDisplayName(), 2, 5 ).."!!")
end
local writs
craftInfo = WritCreater.languageInfo()
if craftInfo then
if WritCreater:GetSettings().autoCraft then
craftingWrits = true
end
writs = WritCreater.writSearch()
if WritCreater:GetSettings()[station] and writs[station] then
if station == CRAFTING_TYPE_ENCHANTING then
DolgubonsWrits:SetHidden(not WritCreater:GetSettings().showWindow)
enchantCrafting(craftInfo[station],writs[station],craftingWrits)
elseif station == CRAFTING_TYPE_PROVISIONING then
elseif station== CRAFTING_TYPE_ALCHEMY then
else
DolgubonsWrits:SetHidden(not WritCreater:GetSettings().showWindow)
crafting(craftInfo[station],writs[station],craftingWrits)
end
end
else
DolgubonsWrits:SetHidden(false)
local text = "The current client language is not supported. \nPlease contact Dolgubon on esoui if you are interested in translating for this language.\n"
out(text)
end
-- Prevent UI bug due to fast Esc
CALLBACK_MANAGER:FireCallbacks("CraftingAnimationsStopped")
end
WritCreater.craftCheck = craftCheck
WritCreater.craft = function() local station =GetCraftingInteractionType() craftingWrits = true
if WritCreater[6697110] then
return
end
if station == CRAFTING_TYPE_ENCHANTING then
local writs, hasWrits = WritCreater.writSearch()
if hasWrits then
enchantCrafting(craftInfo[CRAFTING_TYPE_ENCHANTING],writs[CRAFTING_TYPE_ENCHANTING],craftingWrits)
end
elseif station == CRAFTING_TYPE_ALCHEMY then
elseif station == CRAFTING_TYPE_PROVISIONING then
else
craftNextQueueItem()
end
end
local function closeWindow(event, station)
matSaver = 0
DolgubonsWritsFeedback:SetHidden(true)
DolgubonsWrits:SetHidden(true)
craftingWrits = false
WritCreater:GetSettings().OffsetX = DolgubonsWrits:GetRight()
WritCreater:GetSettings().OffsetY = DolgubonsWrits:GetTop()
queue = {}
DolgubonsWritsBackdropCraft:SetHidden(true)
closeOnce = false
WritCreater.LLCInteraction:cancelItem()
ZO_AlertNoSuppression = originalAlertSuppression
end
WritCreater.closeWindow = closeWindow
function WritCreater.initializeCraftingEvents()
EVENT_MANAGER:RegisterForEvent(WritCreater.name, EVENT_CRAFTING_STATION_INTERACT, WritCreater.craftCheck)
WritCreater.craftCompleteHandler = function(event, station)
if station == CRAFTING_TYPE_ENCHANTING then
WritCreater.craftCheck(event, station)
elseif station ==CRAFTING_TYPE_PROVISIONING then
elseif station == CRAFTING_TYPE_ALCHEMY then
else
WritCreater.craftCheck(event, station) craftNextQueueItem()
end
end
--EVENT_MANAGER:RegisterForEvent(WritCreater.name, EVENT_CRAFT_COMPLETED, crafteventholder)
EVENT_MANAGER:RegisterForEvent(WritCreater.name, EVENT_CRAFT_COMPLETED, WritCreater.craftCompleteHandler)
-- Exit if the user goes to a battleground
EVENT_MANAGER:RegisterForEvent(WritCreater.name, EVENT_BATTLEGROUND_STATE_CHANGED, function(event , pre, new) if pre == 0 and new > 0 then WritCreater.closeWindow() end end )
EVENT_MANAGER:RegisterForEvent(WritCreater.name, EVENT_END_CRAFTING_STATION_INTERACT, WritCreater.closeWindow)
end
-- This is just me expounding about self, dots, colons, and functions in lua.
if false then
-- Self is a lua syntax shortcut, that is unfortunately a little confusing.
-- When you call or define a function that is in a table, you can do it in two ways:
local exTable = {}
function exTable.dotCall(...)
-- If you define or call a function with a dot, then there is no self.
d(self) -- outputs nil
end
function exTable:colonCall(...)
-- But if you define or call a function with a colon, then the table containing the function is self
d(self) -- outputs exTable
end
-- You can also define a function with an explicit self argument
-- Behind the senes, this function definition is exactly the same as the colonCall function!
-- Since it's the same, it can help to mentally translate any function definition with a colon to this format
function exTable.equivalentDotCall(self, ...)
d(self) -- outputs self, whatever that is
end
-- And, since it's the same, you can call both of them with a colon, and it'll do the same thing:
exTable:colonCall() -- Outputs exTable
exTable:equivalentDotCall() -- Also outputs exTable
-- If you define a function with a colon, but then call it with a dot instead, the first argument becomes self
-- If there's no arguments, that means self will just be nil
exTable.colonCall() -- outputs nil, since it's called with a dot
-- If you do pass in an argument, then the first argument will be self
local similarTable = {}
exTable.colonCall(similarTable) -- self == similarTable, so outputs similarTable
-- An example use could be:
-- UIElement.SetText(OtherUIElement, "The text on OtherUIElement will change, since this was a dot call")
end