ESO Lua File v100012

ingame/inventory/sharedinventory.lua

[◄ back to folders ]
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
ZO_SharedInventoryManager = ZO_CallbackObject:Subclass()
function ZO_SharedInventoryManager:New(...)
    local sharedInventoryManager = ZO_CallbackObject.New(self)
    sharedInventoryManager:Initialize(...)
    return sharedInventoryManager
end
function ZO_SharedInventoryManager:Initialize()
    local namespace = tostring(self)
    local function OnInventoryItemDestroyed(eventCode, itemSoundCategory)
        PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_DESTROY)
    end
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_ITEM_DESTROYED, OnInventoryItemDestroyed)
    local function OnInventoryItemUsed(eventCode, itemSoundCategory)
        PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_USE)
    end
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_ITEM_USED, OnInventoryItemUsed)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_OPEN_FENCE, function() 
        self:RefreshInventory(BAG_BACKPACK) 
        self:RefreshInventory(BAG_WORN)
    end)
    self.bagCache = {}
    self.questCache = {}
    self.refresh = ZO_Refresh:New()
    self.refresh:AddRefreshGroup("inventory",
    {
        RefreshAll = function()
            self:RefreshInventory(BAG_BACKPACK)
            self:RefreshInventory(BAG_WORN)
        end,
        RefreshSingle = function(...)
            self:RefreshSingleSlot(...)
        end,
    })
    self.refresh:AddRefreshGroup("guild_bank",
    {
        RefreshAll = function()
            self:RefreshInventory(BAG_GUILDBANK)
        end,
    })
    self.refresh:AddRefreshGroup("quest_inventory",
    {
        RefreshAll = function()
            self:RefreshAllQuests()
        end,
        RefreshSingle = function(questIndex)
            self:RefreshSingleQuest(questIndex)
        end,
    })
    local function OnFullInventoryUpdated()
        self.refresh:RefreshAll("inventory")
        self.refresh:UpdateRefreshGroups()
    end
    local function OnInventorySlotUpdated(eventCode, bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
        if updateReason == INVENTORY_UPDATE_REASON_DURABILITY_CHANGE then
            local newCondition = GetItemCondition(bagId, slotIndex)
            if newCondition == 100 then
                self:FireCallbacks("ItemRepaired", bagId, slotIndex)
            end
        end
        self.refresh:UpdateRefreshGroups()
        self.refresh:RefreshSingle("inventory", bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
        if bagId == BAG_BACKPACK then
            if isNewItem and GetCraftingInteractionType() == CRAFTING_TYPE_INVALID then
                PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_ACQUIRE)
            end
        elseif GetInteractionType() == INTERACTION_BANK and bagId == BAG_BANK then
            PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_SLOT)
        end
        self:FireCallbacks("SingleSlotInventoryUpdate", bagId, slotIndex)
    end
    local function OnGuldBankUpdated()
        self.refresh:RefreshAll("guild_bank")
        self:FireCallbacks("FullInventoryUpdate", BAG_GUILDBANK)
    end
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_FULL_UPDATE, OnFullInventoryUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnInventorySlotUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_OPEN_GUILD_BANK, OnGuldBankUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_CLOSE_GUILD_BANK, OnGuldBankUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_SELECTED, OnGuldBankUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_DESELECTED, OnGuldBankUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_ITEMS_READY, OnGuldBankUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_OPEN_ERROR, OnGuldBankUpdated)
    local function OnGuildBankInventorySlotUpdated(eventCode, slotIndex)
        self.refresh:RefreshSingle("inventory", BAG_GUILDBANK, slotIndex)
        self:FireCallbacks("SingleSlotInventoryUpdate", BAG_GUILDBANK, slotIndex)
    end
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_ITEM_ADDED, OnGuildBankInventorySlotUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_ITEM_REMOVED, OnGuildBankInventorySlotUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_GUILD_BANK_UPDATED_QUANTITY, OnGuildBankInventorySlotUpdated)
    local function OnFullQuestInventoryUpdated()
        self.refresh:RefreshAll("quest_inventory")
        self.refresh:UpdateRefreshGroups()
    end 
    local function OnSingleQuestUpdated(eventCode, journalIndex)
        self.refresh:RefreshSingle("quest_inventory", journalIndex)
        self.refresh:UpdateRefreshGroups()
    end
    local function OnQuestRemoved(eventId, isCompleted, journalIndex, questName, zoneIndex, poiIndex)
        self.refresh:RefreshSingle("quest_inventory", journalIndex)
        self.refresh:UpdateRefreshGroups()
    end
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_QUEST_LIST_UPDATED, OnFullQuestInventoryUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_QUEST_CONDITION_COUNTER_CHANGED, OnSingleQuestUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_QUEST_TOOL_UPDATED, OnSingleQuestUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_QUEST_ADDED, OnSingleQuestUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_QUEST_ADVANCED, OnSingleQuestUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_QUEST_REMOVED, OnQuestRemoved)
    local function OnMoneyUpdated(eventCode, newMoney, oldMoney, reason)
        local wasInitialize = (reason == CURRENCY_CHANGE_REASON_PLAYER_INIT)
        local wasItemPurchased = (reason == CURRENCY_CHANGE_REASON_VENDOR) and (newMoney < oldMoney)
        if(not (wasItemPurchased or wasInitialize)) then
            PlaySound(SOUNDS.ITEM_MONEY_CHANGED)
        end
    end
    local function OnTelvarStonesUpdated(eventCode, newTelvarStones, oldTelvarStones, changeReason)
        local isExcludedReason = changeReason == CURRENCY_CHANGE_REASON_PLAYER_INIT or
                                 changeReason == CURRENCY_CHANGE_REASON_LOOT or
                                 changeReason == CURRENCY_CHANGE_REASON_PVP_KILL_TRANSFER or
                                 changeReason == CURRENCY_CHANGE_REASON_DEATH or
                                 changeReason == CURRENCY_CHANGE_REASON_BANK_FEE or
                                 (changeReason == CURRENCY_CHANGE_REASON_VENDOR and newTelvarStones < oldTelvarStones)
            
        if(not isExcludedReason) then
            PlaySound(SOUNDS.TELVAR_TRANSACT)
        end
    end
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_MONEY_UPDATE, OnMoneyUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_TELVAR_STONE_UPDATE, OnTelvarStonesUpdated)
    EVENT_MANAGER:RegisterForEvent(namespace, EVENT_PLAYER_ACTIVATED, OnFullInventoryUpdated)
end
function ZO_SharedInventoryManager:RefreshInventory(bagId)
    if self:HasBagCache(bagId) then
        self:PerformFullUpdateOnBagCache(bagId)
        self:FireCallbacks("FullInventoryUpdate", bagId)
    end
end
function ZO_SharedInventoryManager:RefreshSingleSlot(bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
    if self:HasBagCache(bagId) then
        local bagCache = self:GetBagCache(bagId)
        self:HandleSlotCreationOrUpdate(bagCache, bagId, slotIndex, isNewItem)
    end 
end
-- where ... are bag ids to combined into a single data table
function ZO_SharedInventoryManager:GenerateFullSlotData(optFilterFunction, ...)
    self.refresh:UpdateRefreshGroups()
    local numBagIds = select("#", ...)
    if numBagIds > 1 then
        local combinedCache = {}
        for i = 1, select("#", ...) do
            local bagId = select(i, ...)
            local bagCache = self:GetOrCreateBagCache(bagId)
            for slotIndex, itemData in pairs(bagCache) do
                if not optFilterFunction or optFilterFunction(itemData) then
                    combinedCache[#combinedCache + 1] = itemData
                end
            end
        end
        return combinedCache
    end
    local bagId = ...
    return self:GetOrCreateBagCache(bagId)
end
function ZO_SharedInventoryManager:GenerateSingleSlotData(bagId, slotIndex)
    self.refresh:UpdateRefreshGroups()
    local bagCache = self:GetOrCreateBagCache(bagId)
    if bagCache[slotIndex] then
        return bagCache[slotIndex]
    end
end
function ZO_SharedInventoryManager:IsFilteredSlotDataEmpty(optFilterFunction, ...)
    self.refresh:UpdateRefreshGroups()
    local numBagIds = select("#", ...)
    for i = 1, numBagIds do
        local bagId = select(i, ...)
        local bagCache = self:GetOrCreateBagCache(bagId)
        for slotIndex, itemData in pairs(bagCache) do
            if not optFilterFunction or optFilterFunction(itemData) then
                return false
            end
        end
    end
    return true
end
--Quest Items
function ZO_SharedInventoryManager:RefreshAllQuests()
    self:FireCallbacks("FullQuestUpdate")
end
function ZO_SharedInventoryManager:RefreshSingleQuest(questIndex)
    self:FireCallbacks("SingleQuestUpdate", questIndex)
end
function ZO_SharedInventoryManager:GenerateSingleQuestCache(questIndex)
    self.refresh:UpdateRefreshGroups()
    local singleQuestCache = self:GetOrCreateQuestCache(questIndex)
    if singleQuestCache then
        return singleQuestCache
    end
end
function ZO_SharedInventoryManager:GenerateFullQuestCache()
    self.refresh:UpdateRefreshGroups()
    
    for questIndex = 1, MAX_JOURNAL_QUESTS do
        self:GetOrCreateQuestCache(questIndex)
    end
    return self.questCache
end
-- Helper functions for new items
function ZO_SharedInventoryManager:AreAnyItemsNew(optFilterFunction, currentFilter, ...)
    self.refresh:UpdateRefreshGroups()
    for i = 1, select("#", ...) do
        local bagId = select(i, ...)
        local bagCache = self:GetOrCreateBagCache(bagId)
        for slotIndex, itemData in pairs(bagCache) do
            if itemData.brandNew and (not optFilterFunction or optFilterFunction(itemData, currentFilter)) then
                return true
            end
        end
    end
    return false
end
function ZO_SharedInventoryManager:ClearNewStatus(bagId, slotIndex)
    local slotData = self:GenerateSingleSlotData(bagId, slotIndex)
    if slotData then
        slotData.age = 0
        slotData.brandNew = nil
    end
end
function ZO_SharedInventoryManager:IsItemNew(bagId, slotIndex)
    local slotData = self:GenerateSingleSlotData(bagId, slotIndex)
    if slotData then
        return slotData.brandNew
    end
    return false
end 
function ZO_SharedInventoryManager:GetItemUniqueId(bagId, slotIndex)
    local slotData = self:GenerateSingleSlotData(bagId, slotIndex)
    if slotData then
        return slotData.uniqueId
    end
end
--[[ Shared Guild Bank functions ]]--
function ZO_SharedInventory_SelectAccessibleGuildBank(lastSuccessfulGuildBankId)
    local validId
    local numGuilds = GetNumGuilds()
    for i = 1, numGuilds do
        local guildId = GetGuildId(i)
        local bankPermission = DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_DEPOSIT) or DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_WITHDRAW) or DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_WITHDRAW_GOLD)
        if(bankPermission) then
            if(lastSuccessfulGuildBankId == guildId) then
                SelectGuildBank(guildId)
                return
            elseif(validId == nil) then
                validId = guildId
            end            
        end
    end
    if(validId) then
        SelectGuildBank(validId)
    elseif(numGuilds > 0) then
        SelectGuildBank(GetGuildId(1))
    end
end
--[[ Private API ]]--
function ZO_SharedInventoryManager:GetOrCreateBagCache(bagId)
    if not self.bagCache[bagId] then
        self.bagCache[bagId] = {}
        self:PerformFullUpdateOnBagCache(bagId)
    end
    return self.bagCache[bagId]
end
function ZO_SharedInventoryManager:HasBagCache(bagId)
    return self.bagCache[bagId] ~= nil
end
function ZO_SharedInventoryManager:GetBagCache(bagId)
    return self.bagCache[bagId]
end
function ZO_SharedInventoryManager:PerformFullUpdateOnBagCache(bagId)
    local bagCache = self:GetBagCache(bagId)
    ZO_ClearTable(bagCache)
    if bagId == BAG_GUILDBANK then
        local slotIndex = GetNextGuildBankSlotId()
        while slotIndex do
            self:HandleSlotCreationOrUpdate(bagCache, bagId, slotIndex)
            slotIndex = GetNextGuildBankSlotId(slotIndex)
        end
    else
        local bagSlots = GetBagSize(bagId)
        for slotIndex = 0, bagSlots - 1 do
            self:HandleSlotCreationOrUpdate(bagCache, bagId, slotIndex)
        end
    end
end
local SHARED_INVENTORY_SLOT_RESULT_REMOVED = 1
local SHARED_INVENTORY_SLOT_RESULT_ADDED = 2
local SHARED_INVENTORY_SLOT_RESULT_UPDATED = 3
local SHARED_INVENTORY_SLOT_RESULT_NO_CHANGE = 4
local SHARED_INVENTORY_SLOT_RESULT_REMOVE_AND_ADD = 5
function ZO_SharedInventoryManager:HandleSlotCreationOrUpdate(bagCache, bagId, slotIndex, isNewItem)
    local existingSlotData = bagCache[slotIndex]
    local slotData, result = self:CreateOrUpdateSlotData(existingSlotData, bagId, slotIndex, isNewItem)
    bagCache[slotIndex] = slotData
    if result == SHARED_INVENTORY_SLOT_RESULT_REMOVED then
        self:FireCallbacks("SlotRemoved", bagId, slotIndex, existingSlotData)
    elseif result == SHARED_INVENTORY_SLOT_RESULT_ADDED then
        self:FireCallbacks("SlotAdded", bagId, slotIndex, slotData)
    elseif result == SHARED_INVENTORY_SLOT_RESULT_UPDATED then
        self:FireCallbacks("SlotUpdated", bagId, slotIndex, slotData)
    elseif result == SHARED_INVENTORY_SLOT_RESULT_REMOVE_AND_ADD then
        self:FireCallbacks("SlotRemoved", bagId, slotIndex, existingSlotData)
        self:FireCallbacks("SlotAdded", bagId, slotIndex, slotData)
    end
end
function ZO_SharedInventoryManager:CreateOrUpdateSlotData(existingSlotData, bagId, slotIndex, isNewItem)
    local icon, stackCount, sellPrice, meetsUsageRequirement, locked, equipType, _, quality = GetItemInfo(bagId, slotIndex)
    local launderPrice = GetItemLaunderPrice(bagId, slotIndex)
    local hadItemInSlotBefore = false
    local wasSameItemInSlotBefore = false
    local hasItemInSlotNow = (stackCount > 0)
    local newItemInstanceId = hasItemInSlotNow and GetItemInstanceId(bagId, slotIndex) or nil
    local slot = existingSlotData
    if not slot then
        if hasItemInSlotNow then
            slot = {}
        end
    else
        hadItemInSlotBefore = slot.stackCount > 0
        wasSameItemInSlotBefore = hadItemInSlotBefore and hasItemInSlotNow and slot.itemInstanceId == newItemInstanceId
    end
    if not hasItemInSlotNow then
        if hadItemInSlotBefore then
            return nil, SHARED_INVENTORY_SLOT_RESULT_REMOVED
        end
        return nil, SHARED_INVENTORY_SLOT_RESULT_NO_CHANGE
    end
    local rawNameBefore = slot.rawName;
    slot.rawName = GetItemName(bagId, slotIndex)
    if rawNameBefore ~= slot.rawName then
        slot.name = zo_strformat(SI_TOOLTIP_ITEM_NAME, slot.rawName)
    end
    slot.requiredLevel = GetItemRequiredLevel(bagId, slotIndex)
    slot.requiredVeterankRank = GetItemRequiredVeteranRank(bagId, slotIndex)
    if not wasSameItemInSlotBefore then
        slot.itemType = GetItemType(bagId, slotIndex)
        slot.uniqueId = GetItemUniqueId(bagId, slotIndex)
    end
    
    slot.iconFile = icon
    slot.stackCount = stackCount
    slot.sellPrice = sellPrice
    slot.launderPrice = launderPrice
    slot.stackSellPrice = stackCount * sellPrice
    slot.stackLaunderPrice = stackCount * launderPrice
    slot.bagId = bagId
    slot.slotIndex = slotIndex
    slot.meetsUsageRequirement = meetsUsageRequirement or (bagId == BAG_WORN) --Items flagged equipped unique can only have one equipped, which means once they are
    slot.locked = locked                                                      --equipped they are no longer equippable, but we don't want to color these items red
    slot.quality = quality                                                    --in GamepadInventory once they are equipped, because that doesn't make any sense.
    slot.equipType = equipType
    slot.isJunk = IsItemJunk(bagId, slotIndex)
    slot.statValue = GetItemStatValue(bagId, slotIndex) or 0
    slot.itemInstanceId = newItemInstanceId
    slot.brandNew = isNewItem
    slot.stolen = IsItemStolen(bagId, slotIndex)
    slot.filterData = { GetItemFilterTypeInfo(bagId, slotIndex) }
    slot.condition = GetItemCondition(bagId, slotIndex)
    if slot.stolen then
       TriggerTutorial(TUTORIAL_TRIGGER_ITEM_STOLEN)
    end
    if wasSameItemInSlotBefore and slot.age ~= 0 then
        -- don't modify the age, keep it the same relative sort - for now?
    elseif isNewItem then
        slot.age = GetFrameTimeSeconds()
    else
        slot.age = 0
    end
    if hadItemInSlotBefore then
        if isNewItem then
            return slot, SHARED_INVENTORY_SLOT_RESULT_REMOVE_AND_ADD
        else
            return slot, SHARED_INVENTORY_SLOT_RESULT_UPDATED
        end
    end
    return slot, SHARED_INVENTORY_SLOT_RESULT_ADDED
end
--Quest Items Private API--
function ZO_SharedInventoryManager:GetOrCreateQuestCache(questIndex)
    if not self.questCache[questIndex] then
        self:PerformSingleUpdateOnQuestCache(questIndex)
    end
    return self.questCache[questIndex]
end
function ZO_SharedInventoryManager:PerformFullUpdateOnQuestCache()
    ZO_ClearTable(self.questCache)
    for questIndex = 1, MAX_JOURNAL_QUESTS do
        self:PerformSingleUpdateOnQuestCache(questIndex)
    end
end
function ZO_SharedInventoryManager:PerformSingleUpdateOnQuestCache(questIndex)
    self.questCache[questIndex] = nil
    if(IsValidQuestIndex(questIndex)) then
        -- First update all the tools for the quest...
        for toolIndex = 1, GetQuestToolCount(questIndex) do
            local icon, stack, _, name, questItemId = GetQuestToolInfo(questIndex, toolIndex)
            self:CreateQuestData(icon, stack, questIndex, toolIndex, QUEST_MAIN_STEP_INDEX, nil, name, questItemId, SEARCH_TYPE_QUEST_TOOL)
        end
        -- Then update all the collectable items...
        for stepIndex = QUEST_MAIN_STEP_INDEX, GetJournalQuestNumSteps(questIndex) do
            for conditionIndex = 1, GetJournalQuestNumConditions(questIndex, stepIndex) do
                local icon, stack, name, questItemId = GetQuestItemInfo(questIndex, stepIndex, conditionIndex)
                self:CreateQuestData(icon, stack, questIndex, nil, stepIndex, conditionIndex, name, questItemId, SEARCH_TYPE_QUEST_ITEM)
            end
        end
    end
end
function ZO_SharedInventoryManager:CreateQuestData(iconFile, stackCount, questIndex, toolIndex, stepIndex, conditionIndex, name, questItemId, searchType)
    if(stackCount > 0) then
        local questCache = self.questCache
        --store all tools and items in a subtable under the questIndex for faster access
        if(not questCache[questIndex]) then
            questCache[questIndex] = {}
        end
        local questItems = questCache[questIndex]
        local questItem =
        {
            name            = zo_strformat(SI_TOOLTIP_ITEM_NAME, name),
            iconFile        = iconFile,
            stackCount      = stackCount,
            questIndex      = questIndex,
            toolIndex       = toolIndex,
            stepIndex       = stepIndex,
            conditionIndex  = conditionIndex,
            sellPrice       = 0,
            stackSellPrice  = 0,
            filterData      = { ITEMFILTERTYPE_QUEST },
            questItemId        = questItemId,
            age             = 0, -- 0 for now, probably need to come up with a way to make these appear new when appropriate. maybe diffing what was there before with what's being added?
        }
        questItems[questItemId] = questItem
    end
end
SHARED_INVENTORY = ZO_SharedInventoryManager:New()
do
    local function UpdateMoney(currencyLabel, currencyOptions)
        ZO_CurrencyControl_SetSimpleCurrency(currencyLabel, CURT_MONEY, GetCarriedCurrencyAmount(CURT_MONEY), currencyOptions)
    end
    local function UpdateAlliancePoints(alliancePointsLabel, alliancePointsOptions)
        ZO_CurrencyControl_SetSimpleCurrency(alliancePointsLabel, CURT_ALLIANCE_POINTS, GetAlliancePoints(), alliancePointsOptions)
    end
    local function UpdateBankedMoney(currencyLabel, currencyOptions)
        ZO_CurrencyControl_SetSimpleCurrency(currencyLabel, CURT_MONEY, GetBankedMoney(), currencyOptions)
    end
    local function UpdateGuildBankedMoney(currencyLabel, currencyOptions)
        ZO_CurrencyControl_SetSimpleCurrency(currencyLabel, CURT_MONEY, GetGuildBankedMoney(), currencyOptions)
    end
    local function ConnectPlayerLabel(label, options, event, updateFnc)
        local dirty = true
        label:RegisterForEvent(event, function() 
            if label:IsHidden() then
                dirty = true
            else
                updateFnc(label, options)
                dirty = false
            end 
        end)
        local function CleanDirty()
            if dirty then
                dirty = false
                updateFnc(label, options)
            end
        end
        label:SetHandler("OnEffectivelyShown", CleanDirty)
        if not label:IsHidden() then
            CleanDirty()
        end
    end
    function ZO_SharedInventory_ConnectPlayerCurrencyLabel(currencyLabel, currencyOptions)
        ConnectPlayerLabel(currencyLabel, currencyOptions, EVENT_MONEY_UPDATE, UpdateMoney)
    end
    function ZO_SharedInventory_ConnectPlayerAlliancePointsLabel(alliancePointsLabel, alliancePointsOptions)
        ConnectPlayerLabel(alliancePointsLabel, alliancePointsOptions, EVENT_ALLIANCE_POINT_UPDATE, UpdateAlliancePoints)
    end
    function ZO_SharedInventory_ConnectBankedCurrencyLabel(currencyLabel, currencyOptions)
        ConnectPlayerLabel(currencyLabel, currencyOptions, EVENT_BANKED_MONEY_UPDATE, UpdateBankedMoney)
    end
    function ZO_SharedInventory_ConnectGuildBankedCurrencyLabel(currencyLabel, currencyOptions)
        ConnectPlayerLabel(currencyLabel, currencyOptions, EVENT_GUILD_BANKED_MONEY_UPDATE, UpdateGuildBankedMoney)
    end
end