LootManager = {}
LootManager.name = "LootManager"
LootManager.allCounts = {}
LootManager.savedVars = {}
--
--
function LootManager:OnAddOnLoad(event, addonName)
if addonName == LootManager.name then
LootManager:Initialize()
end
end
--
--
function LootManager:Initialize()
LootManager.allCounts["Kornblume"] = 0
LootManager.allCounts["Wiesenschaumkraut"] = 0
LootManager.allCounts["Wasserhyazinthe"] = 0
local def = {
left = 100,
top = 200
}
LootManager.savedVars = ZO_SavedVars:New("LootManagerTestVars", 1.0, nil, def)
LootManager:RestorePosition()
end
--
--
function LootManager:SetPosition()
LootManager.savedVars.left = LootManagerWindow:GetLeft()
LootManager.savedVars.top = LootManagerWindow:GetTop()
end
--
--
function LootManager:RestorePosition()
local left = LootManager.savedVars.left
local top = LootManager.savedVars.top
LootManagerWindow:ClearAnchors()
LootManagerWindow:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
end
--
--
function LootManager:GetBagOnInit()
local name
local itemName
local slotId
local count
local bagId = BAG_BACKPACK
local slots = GetBagSize(bagId)
for i=0, slots - 1 do
slotId = i
itemName = GetItemName(bagId, slotId)
name = zo_strformat(SI_UNIT_NAME, itemName)
count = GetItemTotalCount(bagId, slotId)
if name == "Wasserhyazinthe" then
LootManager.allCounts[name] = count
LootManager:UpdateUI(name, count)
end
if name == "Kornblume" then
LootManager.allCounts[name] = count
LootManager:UpdateUI(name, count)
end
if name == "Wiesenschaumkraut" then
LootManager.allCounts[name] = count
LootManager:UpdateUI(name, count)
end
end
LootManager:CheckMin()
EVENT_MANAGER:UnregisterForEvent(LootManager.name, EVENT_PLAYER_ACTIVATED)
end
--
-- When you put something in your bag it looks for ingredients and adds it to a list and updates the ui
function LootManager:BagUpdate( bagId, slotId, isNewItem, itemSoundCategory, updateReason)
local itemName = GetItemName(bagId, slotId)
local name = zo_strformat(SI_UNIT_NAME, itemName)
local totalCount = GetItemTotalCount(bagId, slotId)
if name == "Wasserhyazinthe" then
LootManager:UpdateUI(name, totalCount)
LootManager.allCounts[name] = totalCount
end
if name == "Kornblume" then
LootManager:UpdateUI(name, totalCount)
LootManager.allCounts[name] = totalCount
end
if name == "Wiesenschaumkraut" then
LootManager:UpdateUI(name, totalCount)
LootManager.allCounts[name] = totalCount
end
LootManager:CheckMin()
end
--
-- Check if the values are not nil - otherwise math.min() throws an error
function LootManager:CheckMin()
local countMin
if LootManager.allCounts["Wasserhyazinthe"] == nil or LootManager.allCounts["Kornblume"] == nil or LootManager.allCounts["Wiesenschaumkraut"] == nil then
countMin = 0
else
countMin = math.min(LootManager.allCounts["Wasserhyazinthe"], LootManager.allCounts["Kornblume"], LootManager.allCounts["Wiesenschaumkraut"])
end
LootManager:UpdateUI("Trank", countMin)
end
--
--
function LootManager:UpdateUI(labelName, value)
if labelName == "Wiesenschaumkraut" then
LootManagerWindowWiesenschaumkrautCount:SetText(value)
end
if labelName == "Kornblume" then
LootManagerWindowKornblumeCount:SetText(value)
end
if labelName == "Wasserhyazinthe" then
LootManagerWindowWasserhyazintheCount:SetText(value)
end
if labelName == "Trank" then
LootManagerWindowTrankCount:SetText(value)
end
end
--
--
EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_ADD_ON_LOADED, LootManager.OnAddOnLoad)
EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, LootManager.BagUpdate)
EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_PLAYER_ACTIVATED, LootManager.GetBagOnInit)