-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathWritWorthy.lua
More file actions
831 lines (747 loc) · 32.3 KB
/
WritWorthy.lua
File metadata and controls
831 lines (747 loc) · 32.3 KB
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
-- WritWorthy: Is this Master Writ worth doing?
--
-- In a master writ's tooltip, include the material cost for that writ
-- as both a gold total, and a gold per writ voucher reward.
local WritWorthy = _G['WritWorthy'] -- defined in WritWorthy_Define.lua
local WW = WritWorthy
local LAM2 = LibAddonMenu2
WritWorthy.name = "WritWorthy"
WritWorthy.version = "7.3.2"
WritWorthy.savedVarVersion = 1
WritWorthy.default = {
-- UI topleft, used by WritWorthyInventoryList.
position = { 50, 50 }
}
-- Default savedChariables: per-character saved data.
-- Initially just data about that character's inventory.
WritWorthy.defaultChar = {
-- key = Id64ToString() of a writ that the user has
-- asked to enquque for later crafting.
-- val = "queued" or "completed"
-- Yes we keep the "completed" rows around to
-- provide some UI feedback.
writ_unique_id = {}
}
local Util = WritWorthy.Util
local Fail = WritWorthy.Util.Fail
local Log = WritWorthy.Log
WritWorthy.ICON_TO_PARSER = {
["/esoui/art/icons/master_writ_blacksmithing.dds"] = WritWorthy.Smithing.Parser
, ["/esoui/art/icons/master_writ_clothier.dds" ] = WritWorthy.Smithing.Parser
, ["/esoui/art/icons/master_writ_woodworking.dds" ] = WritWorthy.Smithing.Parser
, ["/esoui/art/icons/master_writ_jewelry.dds" ] = WritWorthy.Smithing.Parser
, ["/esoui/art/icons/master_writ_alchemy.dds" ] = WritWorthy.Alchemy.Parser
, ["/esoui/art/icons/master_writ_enchanting.dds" ] = WritWorthy.Enchanting.Parser
, ["/esoui/art/icons/master_writ_provisioning.dds" ] = WritWorthy.Provisioning.Parser
}
-- Factory to return a parser who knows how to read this particular
-- master writ type.
--
-- Returns one
-- Smithing.Parser (BS/CL/WW)
-- Enchanting.Parser
-- Provisioning.Parser
-- Alchemy.Parser
--
function WritWorthy.CreateParser(item_link)
local icon, _, _, _, item_style = GetItemLinkInfo(item_link)
local parser_class = WritWorthy.ICON_TO_PARSER[icon]
if not parser_class then return nil end
-- Log.Debug("CreateParser: %s\n%s"
-- , item_link
-- , GenerateMasterWritBaseText(item_link)
-- )
return parser_class:New()
end
-- Convert a Master Writ item_link into the list of materials that
-- writ consumes, and the list of required trait or recipe knowledge
-- necessary to craft the item.
function WritWorthy.ToMatKnowList(item_link)
local parser = WritWorthy.CreateParser(item_link)
-- Log.Debug("ToMatKnowList: class:%s item_link:%s"
-- , (parser and parser.class) or "nil"
-- , item_link
-- )
if not parser then return nil end
if not parser:ParseItemLink(item_link) then
return Fail("WritWorthy: "..WW.Str("err_could_not_parse")), nil, parser
end
local mat_list = parser:ToMatList()
local know_list = nil
if parser.ToKnowList then
know_list = parser:ToKnowList()
end
return mat_list, know_list, parser
end
-- Convert a Master Writ item_link into an integer gold cost
-- for required materials.
----
function WritWorthy.ToMatCost(item_link)
-- Temporarily suspend all "dump matlist to chat"
-- to avoid scroll blindness
local save_mat_list_chat = WritWorthy.savedVariables.enable_mat_list_chat
WritWorthy.savedVariables.enable_mat_list_chat = nil
local mat_list = WritWorthy.ToMatKnowList(item_link)
local mat_total = WritWorthy.MatRow.ListTotal(mat_list)
-- Restore mat list to chat setting now that we're
-- done with chat-flooding scan.
WritWorthy.savedVariables.enable_mat_list_chat = save_mat_list_chat
return Util.round(mat_total)
end
-- Convert a Master Writ item_link into the integer number of
-- writ vouchers it returns.
function WritWorthy.ToVoucherCount(item_link)
-- local reward_text = GenerateMasterWritRewardText(item_link)
local fields = Util.ToWritFields(item_link)
local vc = Util.round(fields.writ_reward / 10000)
return vc
end
-- Convert a writ link to a string with both the link and base text
-- that we can store and anyalyze later.
function WritWorthy.ToLinkBaseText(item_link)
if not item_link then return nil end
-- strip "Consume to start quest:\n" preamble
local base_text = GenerateMasterWritBaseText(item_link)
local writ_text = GenerateMasterWritRewardText(item_link)
-- d("b:"..tostring(base_text))
local req_text = base_text:gsub(".*\n","")
-- d("r:"..tostring(req_text))
return item_link .. "\t" .. req_text .."\t".. writ_text
end
local function tt_money(label, count, suffix)
return label..": "
.. Util.ToMoney(count)
.. (suffix or WW.Str("currency_suffix_gold"))
end
-- Return the text we should add to a tooltip.
function WritWorthy.MatTooltipText(mat_list, purchase_gold, voucher_ct)
-- No vouchers? No per-voucher cost.
if (not voucher_ct) or (voucher_ct < 1) then return nil end
-- No cost? No per-voucher cost.
if (not mat_list) and (not purchase_gold) then return nil end
-- Accumulators for totals and text
local tooltip_elements = {}
local total_gold = 0
local mat_gold = nil
if mat_list then
mat_gold = WritWorthy.MatRow.ListTotal(mat_list)
if mat_gold then
total_gold = total_gold + mat_gold
end
local s = tt_money(WW.Str("tooltip_mat_total"), mat_gold)
if not mat_gold then
s = "|c"..WritWorthy.Util.COLOR_RED..s.."|r"
end
table.insert( tooltip_elements, s)
end
if purchase_gold then
total_gold = total_gold + purchase_gold
table.insert( tooltip_elements
, tt_money(WW.Str("tooltip_purchase"), purchase_gold)
)
end
local per_voucher_gold = total_gold / voucher_ct
table.insert( tooltip_elements
, tt_money(WW.Str("tooltip_per_voucher"), per_voucher_gold)
)
if WritWorthy.savedVariables.sell_per_voucher then
local sell_total = WritWorthy.savedVariables.sell_per_voucher * voucher_ct
local sell_net = sell_total - (mat_gold or sell_total)
local msg = nil
if 0 < sell_net then
msg = string.format( "|c%s" .. WW.Str("tooltip_sell_for")
, WritWorthy.Util.COLOR_GREEN
, Util.ToMoney(sell_net))
else
msg = string.format( "|c%s" .. WW.Str("tooltip_sell_for_cannot")
, WritWorthy.Util.COLOR_ORANGE
, Util.ToMoney(sell_net))
end
table.insert(tooltip_elements, msg)
end
-- Avoid line breaks if we only have a couple elements.
if 3 <= #tooltip_elements then
tooltip_elements[1] = tooltip_elements[1] .. " " .. tooltip_elements[2]
table.remove(tooltip_elements,2)
return table.concat(tooltip_elements,"\n")
else
return table.concat(tooltip_elements, " ")
end
end
-- Return big red indicators for any required knowledge that you lack.
function WritWorthy.KnowTooltipText(know_list)
if not know_list then return nil end
local elements = {}
for i, know in ipairs(know_list) do
-- Include lines that don't duplicate what
-- Marify's Confirm Master Writ already report.
if ( (not (know.how and know.how.cmw))
-- Or include duplicates if no CMW loaded, or if
-- user intentionally requested duplicates.
or WritWorthy.CanShowCMWDuplicates()) then
local s = know:TooltipText()
if s then
table.insert(elements, s)
end
end
end
return table.concat(elements, "\n")
end
local function can_tooltip_mat(enable, mat_row)
if enable == WW.Str("lam_mat_tooltip_all") then
return true
end
if (enable == nil) or (enable == WW.Str("lam_mat_tooltip_missing_only")) then
return mat_row:HaveCt() < mat_row.ct
end
return false
end
-- Return list of materials, with low/insufficient materials in orange/red.
function WritWorthy.MatHaveCtTooltipText(mat_list)
if not WritWorthy.CanShowCMWDuplicates() then return nil end
if not mat_list then return nil end
local enable = WritWorthy.savedVariables.enable_mat_list_tooltip
if enable == WW.Str("lam_mat_tooltip_off") then return nil end
local elements = {}
for i, mat_row in ipairs(mat_list) do
if can_tooltip_mat(enable, mat_row) then
local name = Util.decaret(GetItemLinkName(mat_row.link))
local need_ct = mat_row.ct or 1
local have_ct = mat_row:HaveCt() or 0
local color = Util.COLOR_WHITE
if have_ct < need_ct then
color = Util.COLOR_RED
end
local s = string.format( "|c%s%s %d/%d|r"
, color
, name
, need_ct
, have_ct
)
table.insert(elements, s)
end
end
return table.concat(elements, "\n")
end
local function can_dump_matlist(enable, parser)
if enable == WW.Str("lam_mat_list_all") then
return true
elseif enable == WW.Str("lam_mat_list_alchemy_only")
and parser
and parser.class == WritWorthy.Alchemy.Parser.class then
return true
end
return false
end
-- Add text to a tooltip.
--
-- control: the tooltip, responds to :AddLine(text)
-- link: the item whose tip ZOScode is showing.
-- purchase_gold: if set, this is a tooltip for a guild store listing.
-- Include this cost in the gold-per-voucher calculation.
-- (optional, nil ok)
--
function WritWorthy.TooltipInsertOurText(control, item_link, purchase_gold, unique_id, style)
-- Only fire for master writs.
if ITEMTYPE_MASTER_WRIT ~= GetItemLinkItemType(item_link) then return end
local mat_list, know_list, parser = WritWorthy.ToMatKnowList(item_link)
if not parser then return end
local voucher_ct = WritWorthy.ToVoucherCount(item_link)
local mat_text = WritWorthy.MatTooltipText(mat_list, purchase_gold, voucher_ct)
if not mat_text then return end
if WritWorthy.savedVariables.enable_mat_price_tooltip ~= false then
control:AddLine(mat_text, style)
end
if can_dump_matlist(WritWorthy.savedVariables.enable_mat_list_chat, parser) then
WritWorthy.MatRow.ListDump(mat_list)
--WritWorthy.KnowDump(know_list)
end
local mat_have_text = WritWorthy.MatHaveCtTooltipText(mat_list)
if mat_have_text then
control:AddLine(mat_have_text, style)
end
local know_text = WritWorthy.KnowTooltipText(know_list)
if know_text then
control:AddLine(know_text, style)
end
local warning_text = parser.WarningText and parser:WarningText()
if warning_text then
control:AddLine(warning_text, style)
end
-- Can we append WritWorthy queued/completed status?
-- We can if this writ is in our backpack and thus
-- has a unique_id.
--
-- The unique_id for bag position usually comes in
-- from ZOS inventory UI, but we can also inject it
-- from the WritWorthyInventoryList UI
if not unique_id then
unique_id = control.WritWorthy_UniqueId
end
if unique_id
and WritWorthyInventoryList.singleton then
local inventory_data = WritWorthyInventoryList.singleton:UniqueIDToInventoryData(unique_id)
if inventory_data then
local text = nil
local color = nil
if inventory_data.ui_is_queued then
text = "WritWorthy: " .. WW.Str("tooltip_queued")
color = WritWorthyInventoryList.COLOR_TEXT_QUEUED
elseif inventory_data.ui_is_completed then
text = "WritWorthy: " .. WW.Str("tooltip_crafted")
color = WritWorthyInventoryList.COLOR_TEXT_COMPLETED
end
if color and text then
control:AddLine(Util.color(color, text), style)
end
end
end
end
-- Write a list of required knowledge to chat.
function WritWorthy.KnowDump(know_list)
if not know_list then
-- d("know_list:"..tostring(know_list))
return
end
local elements = {}
for i, know in ipairs(know_list) do
d(know:DebugText())
end
return table.concat(elements, "\n")
end
-- Scan inventory, return list of { link="xxx", parser=ParserXXX }
-- one element for each master writ found.
function WritWorthy:ScanInventoryForMasterWrits()
local result_list = {}
local bag_list = {BAG_BACKPACK}
if self.savedVariables.enable_banked_vouchers then
bag_list = {BAG_BACKPACK, BAG_BANK, BAG_SUBSCRIBER_BANK }
end
-- Temporarily suspend all "dump matlist to chat"
-- to avoid scroll blindness
local save_mat_list_chat = self.savedVariables.enable_mat_list_chat
self.savedVariables.enable_mat_list_chat = nil
for _,bag_id in ipairs(bag_list) do
local slot_ct = GetBagSize(bag_id)
for slot_index = 0, slot_ct do
local item_link = GetItemLink(bag_id, slot_index, LINK_STYLE_DEFAULT)
local parser = WritWorthy.CreateParser(item_link)
if not (parser and parser:ParseItemLink(item_link)) then
parser = nil
end
if parser then
local unique_id = WritWorthy.UniqueID(bag_id, slot_index)
local llc_req = {}
if parser.ToDolRequest then
llc_req = parser:ToDolRequest(unique_id)
end
local inventory_data =
{ item_link = item_link
, parser = parser
, unique_id = unique_id
, llc_func = llc_req["function"]
, llc_args = llc_req.args
}
table.insert(result_list, inventory_data)
end
end
end
-- Restore mat list to chat setting now that we're
-- done with chat-flooding scan.
self.savedVariables.enable_mat_list_chat = save_mat_list_chat
return result_list
end
function WritWorthy.UniqueID(bag_id, slot_index)
-- GetItemUniqueId(bag_id, slot_index) returns an id64
-- that cannot be rendered directly in savedVariables
-- or tostring(). Call ZOS function Id64ToString() to
-- turn it into something usable and saveable and
-- restorable. Do all our unique_id thinking in
-- strings, not id64.
local id64 = GetItemUniqueId(bag_id, slot_index)
local unique_id = Id64ToString(id64)
return unique_id
end
-- Inventory UI: Save/Restore UI Position --------------------------------------------------
-- Tooltip Intercept ---------------------------------------------------------
-- Monkey-patch ZOS' ItemTooltip with our own after-overrides. Lets ZOS code
-- create and show the original tooltip, and then we come in and insert our
-- own stuff.
--
-- Based on CraftStore's CS.TooltipHandler().
-- Updated 2019-05 by Sirinsidiator to work with AwesomeGuildStore 1.1.
--
function WritWorthy.TooltipInterceptInstall()
local tt=ItemTooltip.SetBagItem
ItemTooltip.SetBagItem=function(control,bagId,slotIndex,...)
tt(control,bagId,slotIndex,...)
WritWorthy.TooltipInsertOurText(control,GetItemLink(bagId,slotIndex)
, nil -- purchase_gold
, WritWorthy.UniqueID(bagId, slotIndex))
end
local tt=ItemTooltip.SetLootItem
ItemTooltip.SetLootItem=function(control,lootId,...)
tt(control,lootId,...)
WritWorthy.TooltipInsertOurText(control,GetLootItemLink(lootId))
end
local tt=PopupTooltip.SetLink
PopupTooltip.SetLink=function(control,link,...)
tt(control,link,...)
WritWorthy.TooltipInsertOurText(control,link)
end
local function SetupTradingHouseItemTooltipHook()
local tt=ItemTooltip.SetTradingHouseItem
ItemTooltip.SetTradingHouseItem=function(control,tradingHouseIndex,...)
tt(control,tradingHouseIndex,...)
local _,_,_,_,_,_,purchase_gold = GetTradingHouseSearchResultItemInfo(tradingHouseIndex)
WritWorthy.TooltipInsertOurText(control
, GetTradingHouseSearchResultItemLink(tradingHouseIndex)
, purchase_gold
)
end
end
if AwesomeGuildStore then
AwesomeGuildStore:RegisterCallback(AwesomeGuildStore.callback.AFTER_INITIAL_SETUP, SetupTradingHouseItemTooltipHook)
else
SetupTradingHouseItemTooltipHook()
end
local function SetupGamepadTooltip()
local leftGamepadTooltip = GAMEPAD_TOOLTIPS:GetTooltip(GAMEPAD_LEFT_TOOLTIP)
ZO_PostHook(leftGamepadTooltip, "LayoutMasterWritItem", function (self, itemLink)
local section = self:AcquireSection(self:GetStyle("bodySection"))
WritWorthy.TooltipInsertOurText(section, itemLink, nil, nil, self:GetStyle("bodyDescription"))
self:AddSection(section)
end)
end
SetupGamepadTooltip()
end
-- UI ------------------------------------------------------------------------
function WritWorthy:CreateSettingsWindow()
local lam_addon_id = "WritWorthy_LAM"
local panelData = {
type = "panel",
name = self.name,
displayName = self.name,
author = "ziggr",
version = self.version,
--slashCommand = "/gg",
registerForRefresh = false,
registerForDefaults = false,
}
local cntrlOptionsPanel = LAM2:RegisterAddonPanel( lam_addon_id
, panelData
)
local optionsData = {
{ type = "checkbox"
, name = WW.Str("lam_mat_price_tt_title")
, tooltip = WW.Str("lam_mat_price_tt_desc")
, getFunc = function()
return self.savedVariables.enable_mat_price_tooltip ~= false
end
, setFunc = function(e)
self.savedVariables.enable_mat_price_tooltip = e
end
},
{ type = "dropdown"
, name = WW.Str("lam_mat_list_title")
, tooltip = WW.Str("lam_mat_list_desc")
, choices = { WW.Str("lam_mat_list_off")
, WW.Str("lam_mat_list_all")
, WW.Str("lam_mat_list_alchemy_only")
}
, getFunc = function()
return self.savedVariables.enable_mat_list_chat
end
, setFunc = function(e)
self.savedVariables.enable_mat_list_chat = e
end
},
{ type = "checkbox"
, name = WW.Str("lam_lib_price_title")
, tooltip = WW.Str("lam_lib_price_desc")
, getFunc = function()
return self.savedVariables.enable_lib_price
or (self.savedVariables.enable_lib_price == nil)
end
, setFunc = function(e)
self.savedVariables.enable_lib_price = e
end
},
{ type = "checkbox"
, name = WW.Str("lam_mm_fallback_title")
, tooltip = WW.Str("lam_mm_fallback_desc")
, getFunc = function()
return self.savedVariables.enable_mm_fallback
end
, setFunc = function(e)
self.savedVariables.enable_mm_fallback = e
end
},
{ type = "checkbox"
, name = WW.Str("lam_station_colors_title")
, tooltip = WW.Str("lam_station_colors_desc")
, getFunc = function()
return self.savedVariables.enable_station_colors
end
, setFunc = function(e)
self.savedVariables.enable_station_colors = e
end
},
{ type = "checkbox"
, name = WW.Str("lam_banked_vouchers_title")
, tooltip = WW.Str("lam_banked_vouchers_desc")
, getFunc = function()
return self.savedVariables.enable_banked_vouchers
end
, setFunc = function(e)
self.savedVariables.enable_banked_vouchers = e
end
},
{ type = "checkbox"
, name = WW.Str("lam_force_en_title")
, tooltip = WW.Str("lam_force_en_desc")
, getFunc = function()
return self.savedVariables.lang == "en"
end
, setFunc = function(e)
self.savedVariables.lang = e and "en"
end
, requiresReload = true
},
{ type = "dropdown"
, name = WW.Str("lam_mat_tooltip_title")
, tooltip = WW.Str("lam_mat_tooltip_desc")
, choices = { WW.Str("lam_mat_tooltip_off")
, WW.Str("lam_mat_tooltip_all")
, WW.Str("lam_mat_tooltip_missing_only")
}
, getFunc = function()
return self.savedVariables.enable_mat_list_tooltip or WW.Str("lam_mat_tooltip_missing_only")
end
, setFunc = function(e)
self.savedVariables.enable_mat_list_tooltip = e
end
},
}
-- Only show this checkbox if running Marify's
-- Confirm Master Writ.
if ConfirmMasterWrit then
local o =
{ type = "checkbox"
, name = WW.Str("lam_cmw_title")
, tooltip = WW.Str("lam_cmw_desc")
, getFunc = function()
return self.savedVariables.show_confirm_master_writ_duplicates
end
, setFunc = function(e)
self.savedVariables.show_confirm_master_writ_duplicates = e and true
end
}
table.insert(optionsData, o)
end
LAM2:RegisterOptionControls(lam_addon_id, optionsData)
end
-- Should we show the "Recipe not known" and other tooltip errors that
-- Marify's Confirm Master Writ also report?
function WritWorthy.CanShowCMWDuplicates()
-- If Confirm Master Writ isn't running, then
-- we're not duplicate/redundant. Definitely show.
if not ConfirmMasterWrit then return true end
-- If CMW is running, then honor the user's prefs.
return WritWorthy.savedVariables.show_confirm_master_writ_duplicates
end
-- SlashCommand --------------------------------------------------------------
function WritWorthy.Forget()
-- Forget everything this one character has already
-- crafted.
--
-- Helpful when testing on PTS and you want to keep
-- trying to craft the same few writs over and over.
WritWorthy.savedChariables.writ_unique_id = {}
end
function WritWorthy.ServerName()
local self = WritWorthy
if not self.server_name then
self.server_name = "NA"
local plat = GetCVar("LastPlatform") -- ""
if (plat == "Live-EU") then
self.server_name = "EU"
end
end
return self.server_name
end
function WritWorthy.Port()
local owner = "@ziggr"
local house_id = 62 -- Grand Psijic Villa
if WritWorthy.ServerName() == "NA" then
else
owner = "@PhnxZ"
house_id = 80 -- Stillwaters Retreat
end
-- Don't send the player in blind:
-- tell them where they're goind.
local house_collectible_id = GetCollectibleIdForHouse(house_id)
local house_name = GetCollectibleName(house_collectible_id)
local fmt = WW.Str("msg_port_house")
-- local msg = string.format(msg, owner, house_id)
Log.Info(fmt, owner, house_id)
-- Must use different function for jumping to your own house
-- vs. jumping to another player's house.
if owner == GetDisplayName() then
RequestJumpToHouse(house_id)
else
JumpToSpecificHouse(owner, house_id)
end
end
function WritWorthy.SlashCommand(arg1)
if arg1:lower() == WW.Str("slash_discover") then
d("|c999999WritWorthy: ".. WW.Str("status_discover").."|r")
WritWorthy.Smithing.Discover()
WritWorthy.DiscoverI18N()
elseif arg1:lower() == WW.Str("slash_forget") then
d("|c999999WritWorthy: "..WW.Str("status_forget") .."|r")
WritWorthy.Forget()
elseif arg1:lower() == WW.Str("slash_port") then
WritWorthy.Port()
elseif arg1:lower() == WW.Str("slash_count") then
local mwlist = WritWorthy:ScanInventoryForMasterWrits()
local mw_ct = #mwlist
local voucher_ct = 0
for _,mw in ipairs(mwlist) do
local vc = WritWorthy.ToVoucherCount(mw.item_link)
voucher_ct = voucher_ct + vc
end
d(string.format( "|c999999WritWorthy: "..WW.Str("count_writs_vouchers").."|r"
, mw_ct
, Util.ToMoney(voucher_ct)
))
elseif arg1:lower() == WW.Str("slash_auto") then
if WritWorthy_AutoQuest then
WritWorthy_AutoQuest()
end
elseif arg1:lower() == WW.Str("slash_mat") then
-- Lazy init of list window
if not WritWorthy.mat_ui_inited then
WritWorthy.MatUI:LazyInit()
WritWorthy.mat_ui_inited = true
WritWorthy.MatUI.RestorePos()
end
if WritWorthy.MatUI then
WritWorthy.MatUI.ToggleUI()
end
else
WritWorthyUI_ToggleUI()
end
end
function WritWorthy.RegisterSlashCommands()
local lsc = LibSlashCommander
if lsc then
local cmd = lsc:Register( "/writworthy"
, function(arg) WritWorthy.SlashCommand(arg) end
, WW.Str("slash_writworthy_desc"))
local sub_forget = cmd:RegisterSubCommand()
sub_forget:AddAlias(WW.Str("slash_forget"))
sub_forget:SetCallback(function() WritWorthy.SlashCommand(WW.Str("slash_forget")) end)
sub_forget:SetDescription(WW.Str("slash_forget_desc"))
local sub_count = cmd:RegisterSubCommand()
sub_count:AddAlias(WW.Str("slash_count"))
sub_count:SetCallback(function() WritWorthy.SlashCommand(WW.Str("slash_count")) end)
sub_count:SetDescription(WW.Str("slash_count_desc"))
local sub_port = cmd:RegisterSubCommand()
sub_port:AddAlias(WW.Str("slash_port"))
sub_port:SetCallback(function() WritWorthy.SlashCommand(WW.Str("slash_port")) end)
sub_port:SetDescription(WW.Str("slash_port_desc"))
if (GetDisplayName() == "@ziggr") then
local sub_discover = cmd:RegisterSubCommand()
sub_discover:AddAlias(WW.Str("slash_discover"))
sub_discover:SetCallback(function() WritWorthy.SlashCommand(WW.Str("slash_discover")) end)
sub_discover:SetDescription(WW.Str("slash_discover_desc"))
end
if WritWorthy.AQAddKeyBind then
local sub_auto = cmd:RegisterSubCommand()
sub_auto:AddAlias(WW.Str("slash_auto"))
sub_auto:SetCallback(function() WritWorthy.SlashCommand(WW.Str("slash_auto")) end)
sub_auto:SetDescription(WW.Str("slash_auto_desc"))
end
if WritWorthy.MatUI then
local sub_auto = cmd:RegisterSubCommand()
sub_auto:AddAlias(WW.Str("slash_mat"))
sub_auto:SetCallback(function() WritWorthy.SlashCommand(WW.Str("slash_mat")) end)
sub_auto:SetDescription(WW.Str("slash_mat_desc"))
end
else
SLASH_COMMANDS["/writworthy"] = WritWorthy.SlashCommand
end
end
-- Init ----------------------------------------------------------------------
function WritWorthy.OnAddOnLoaded(event, addonName)
if addonName == WritWorthy.name then
if not WritWorthy.version then return end
WritWorthy:Initialize()
WritWorthy.RegisterAGSInitCallback()
end
end
function WritWorthy:Initialize()
-- Account-wide for most things
self.savedVariables = ZO_SavedVars:NewAccountWide(
"WritWorthyVars"
, self.savedVarVersion
, nil
, self.default
)
-- Old pre-LibDebugLogger log? No lonnger useful,
-- remove it and save some SavedVariables space.
if self.savedVariables.log then
self.savedVariables.log = nil
end
-- Per-character for each character's inventory list.
self.savedChariables = ZO_SavedVars:New("WritWorthyVars"
, self.savedVarVersion
, nil
, self.defaultChar
)
WritWorthy.RegisterSlashCommands()
WritWorthy.Smithing.Init()
-- Swap in a preferred-language version of the
-- keybind string.
ZO_CreateStringId("SI_BINDING_NAME_WritWorthyUI_ToggleUI", WW.Str("keybind_writworthy"))
WritWorthy.TooltipInterceptInstall()
self:CreateSettingsWindow()
WritWorthy.InventoryList = WritWorthyInventoryList:New()
-- Load the LibLazyCrafting queue BEFORE we start up
-- the list UI. This gives the list UI actual queue
-- data to consume when deciding which checkboxes to
-- initially mark checked.
WritWorthyInventoryList.RestoreFromSavedChariables()
WritWorthy.InventoryList:BuildMasterlist()
WritWorthy.InventoryList:Refresh()
WritWorthyUI_RestorePos()
-- If WritWorthy_AutoQuest.lua is un-commented-out
-- in WritWorthy.txt, install its button in the
-- Inventory screen. If not, no auto-quest for you!
if WritWorthy["AQAddKeyBind"] then
WritWorthy:AQAddKeyBind()
end
-- Intentionally NOT initializing MatUI here. Only
-- init it if the player actually summons it.
-- You're doing too much in here at loading screen
-- time!
end
-- Postamble -----------------------------------------------------------------
EVENT_MANAGER:RegisterForEvent( WritWorthy.name
, EVENT_ADD_ON_LOADED
, WritWorthy.OnAddOnLoaded
)
-- Key binding strings must be defined earlier than
-- OnAddOnLoaded() time or the key binding will not
-- appear in Controls/Keybindings.
--
-- Category string is locked at file-load time and
-- cannot be changed. That's okay, we don't translate
-- our add-on name anyway.
--
-- Individual key binds can and should be replaced with
-- i18n strings later, once we've loaded savedVariables
-- and know which language the user prefers.
ZO_CreateStringId("SI_KEYBINDINGS_CATEGORY_WRIT_WORTHY", "WritWorthy")
ZO_CreateStringId("SI_BINDING_NAME_WritWorthyUI_ToggleUI", "Toggle window")