fixed storage counts, indexing, item types and key usage

AssemblerManiac [02-17-18 - 07:20]
fixed storage counts, indexing, item types and key usage
Filename
IIfA/IIfA.lua
IIfA/IIfABackpack.lua
IIfA/IIfADataCollection.lua
diff --git a/IIfA/IIfA.lua b/IIfA/IIfA.lua
index c55ff36..5f7e317 100644
--- a/IIfA/IIfA.lua
+++ b/IIfA/IIfA.lua
@@ -432,7 +432,7 @@ function IIfA_onLoad(eventCode, addOnName)
 		IIfA.data.bConvertedGlyphs = true
 		IIfA.data.bConvertedLocType = true
 	end
-	if IIfA.data.bConvertedMotifs == nil and IIfA.data.DBv3 == nil then			-- 9-12-16 AM - added whole if to convert motifs to item ids
+	if IIfA.data.bConvertedMotifs == nil and IIfA.data.DBv2 ~= nil then			-- 9-12-16 AM - added whole if to convert motifs to item ids
 		for itemLink, DBItem in pairs(IIfA.data.DBv2) do
 			if itemLink:find("|") ~= nil then			-- not a numeric itemid, it's a link
 				local itemType = GetItemLinkItemType(itemLink)
@@ -461,7 +461,7 @@ function IIfA_onLoad(eventCode, addOnName)
 		IIfA.data.bConvertedMotifs = true
 	end

-	if IIfA.data.DBv3 == nil then
+	if IIfA.data.DBv2 ~= nil then
 		dbv3 = {}
 		for itemLink, DBItem in pairs(IIfA.data.DBv2) do
 			dbv3[itemLink] = {}
@@ -480,12 +480,13 @@ function IIfA_onLoad(eventCode, addOnName)
 			end
 		end
 		IIfA.data.DBv3 = dbv3
+		IIfA.data.DBv2 = nil
 	end

 	-- keep EU and US items apart
 	local worldName = GetWorldName():gsub(" Megaserver", "")
 	IIfA.data[worldName] = IIfA.data[worldName] or {}
-	if nil == IIfA.data[worldName].DBv3 then
+	if IIfA.data[worldName].DBv3 == nil then
 		 IIfA.data[worldName].DBv3 = IIfA.data.DBv3
 	end
 	IIfA.data.DBv3 = nil
diff --git a/IIfA/IIfABackpack.lua b/IIfA/IIfABackpack.lua
index 749def0..ee4aaf7 100644
--- a/IIfA/IIfABackpack.lua
+++ b/IIfA/IIfABackpack.lua
@@ -627,31 +627,9 @@ function IIfA:QueryAccountInventory(itemLink)
 	local newLocation = {}

 	itemType = GetItemLinkItemType(itemLink)
-	if itemType == ITEMTYPE_BLACKSMITHING_MATERIAL or
-		itemType == ITEMTYPE_ARMOR_TRAIT or
-		itemType == ITEMTYPE_BLACKSMITHING_BOOSTER or
-		itemType == ITEMTYPE_BLACKSMITHING_RAW_MATERIAL or
-		itemType == ITEMTYPE_CLOTHIER_BOOSTER or
-		itemType == ITEMTYPE_CLOTHIER_MATERIAL or
-		itemType == ITEMTYPE_CLOTHIER_RAW_MATERIAL or
-		itemType == ITEMTYPE_ENCHANTING_RUNE_ASPECT or
-		itemType == ITEMTYPE_ENCHANTING_RUNE_ESSENCE or
-		itemType == ITEMTYPE_ENCHANTING_RUNE_POTENCY or
-		itemType == ITEMTYPE_FLAVORING or
-		itemType == ITEMTYPE_INGREDIENT or
+	if CanItemLinkBeVirtual(itemLink) or
 		itemType == ITEMTYPE_LOCKPICK or
-		itemType == ITEMTYPE_LURE or
-		itemType == ITEMTYPE_POISON_BASE or
-		itemType == ITEMTYPE_POTION_BASE or
-		itemType == ITEMTYPE_RAW_MATERIAL or
-		itemType == ITEMTYPE_REAGENT or
 		itemType == ITEMTYPE_RECIPE or
-		itemType == ITEMTYPE_SPICE or
-		itemType == ITEMTYPE_STYLE_MATERIAL or
-		itemType == ITEMTYPE_WEAPON_TRAIT or
-		itemType == ITEMTYPE_WOODWORKING_BOOSTER or
-		itemType == ITEMTYPE_WOODWORKING_MATERIAL or
-		itemType == ITEMTYPE_WOODWORKING_RAW_MATERIAL or
 		itemType == ITEMTYPE_RACIAL_STYLE_MOTIF then
 		itemLink = IIfA:GetItemID(itemLink)
 	end
diff --git a/IIfA/IIfADataCollection.lua b/IIfA/IIfADataCollection.lua
index 9883418..b45a523 100644
--- a/IIfA/IIfADataCollection.lua
+++ b/IIfA/IIfADataCollection.lua
@@ -8,6 +8,7 @@ local function p(...) IIfA:DebugOut(...) end

 local function grabBagContent(bagId, override)
 	local bagItems = GetBagSize(bagId)
+	IIfA:DebugOut("grabBagContent - bagId = <<1>>", bagId)
 	for slotId=0, bagItems, 1 do
 		dbItem, itemKey = IIfA:EvalBagItem(bagId, slotId, false, nil, nil, nil, nil, override)
 	end
@@ -144,8 +145,8 @@ function IIfA:ScanBank()
 	end):Then(function()
 		grabBagContent(BAG_BANK)
 	end):Then(function()
-		IIfA:ClearLocationData(GetString(IIFA_BAG_BANK))
-		grabBagContent(GetString(BAG_SUBSCRIBER_BANK))
+		grabBagContent(BAG_SUBSCRIBER_BANK)
+	end):Then(function()
 		IIfA:ClearLocationData(GetString(IIFA_BAG_CRAFTBAG))
 		slotId = GetNextVirtualBagSlotId(slotId)
 		while slotId ~= nil do
@@ -333,6 +334,7 @@ local function getItemLink(bagId, slotId)
 		IIfA:SaveBagSlotIndex(bagId, slotId, itemLink)
 		return itemLink
 	end
+	if not IIfA.BagSlotInfo then return end
 	if nil == IIfA.BagSlotInfo[bagId] then return end
 	return IIfA.BagSlotInfo[bagId][slotId]
 end
@@ -346,25 +348,23 @@ local function getItemName(bagId, slotId, itemLink)
 end

 -- returns the item's db key, we only save under the item link if we need to save level information etc, else we use the ID
-local function getItemKey(itemLink, usedInCraftingType, itemType)
-
-	-- crafting materials get saved by ID
-	if usedInCraftingType ~= CRAFTING_TYPE_INVALID and
-	   itemType ~= ITEMTYPE_GLYPH_ARMOR and
-	   itemType ~= ITEMTYPE_GLYPH_JEWELRY and
-	   itemType ~= ITEMTYPE_GLYPH_WEAPON then
-	   return IIfA:GetItemID(itemLink)
-	end
-	-- raw materials
-	itemType = itemType or GetItemLinkItemType(itemLink)
-	if  itemType == ITEMTYPE_STYLE_MATERIAL or
-		itemType == ITEMTYPE_ARMOR_TRAIT or
-		itemType == ITEMTYPE_WEAPON_TRAIT or
-		itemType == ITEMTYPE_LOCKPICK or
-		itemType == ITEMTYPE_RAW_MATERIAL or
-		itemType == ITEMTYPE_RACIAL_STYLE_MOTIF or		-- 9-12-16 AM - added because motifs now appear to have level info in them
-		itemType == ITEMTYPE_RECIPE then
+function IIfA:GetItemKey(itemLink, usedInCraftingType, itemType)
+
+	if CanItemLinkBeVirtual(itemLink) then	-- anything that goes in the craft bag
 		return IIfA:GetItemID(itemLink)
+	elseif usedInCraftingType ~= CRAFTING_TYPE_INVALID and		-- crafting materials get saved by ID
+   		itemType ~= ITEMTYPE_GLYPH_ARMOR and
+   		itemType ~= ITEMTYPE_GLYPH_JEWELRY and
+   		itemType ~= ITEMTYPE_GLYPH_WEAPON then
+   		return IIfA:GetItemID(itemLink)
+	else
+		-- other oddball items that might have level info in them
+		itemType = itemType or GetItemLinkItemType(itemLink)
+		if	itemType == ITEMTYPE_LOCKPICK or
+			itemType == ITEMTYPE_RACIAL_STYLE_MOTIF or		-- 9-12-16 AM - added because motifs now appear to have level info in them
+			itemType == ITEMTYPE_RECIPE then
+			return IIfA:GetItemID(itemLink)
+		end
 	end
 	return itemLink
 end
@@ -396,7 +396,7 @@ local function getLocation(location, bagId)
 		return GetString(IIFA_BAG_CRAFTBAG)
 	elseif(bagId == BAG_GUILDBANK) then
 		return GetGuildName(GetSelectedGuildBankId())
-	elseif GetAPIVersion() >= 100022 and 0 < GetCollectibleForHouseBankBag(bagId) then
+	elseif 0 < GetCollectibleForHouseBankBag(bagId) then
 		return GetCollectibleForHouseBankBag(bagId)
 	end
 end
@@ -421,11 +421,10 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, itemCount, itemLink, itemName
 	IIfA.database = IIfA.database or {}
 	local DBv3 = IIfA.database

-	IIfA:DebugOut("trying to save <<1>> x<<2>>", itemLink, itemCount)
-
 	-- item link is either passed as arg or we need to read it from the system
 	itemLink = itemLink or getItemLink(bagId, slotId)

+	--IIfA:DebugOut("trying to save <<1>> x<<2>>", itemLink, itemCount)

 	-- return if we don't have any item to track
 	if nil == itemLink  then return end
@@ -438,7 +437,10 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, itemCount, itemLink, itemName


 	-- get item key from crafting type
-	local usedInCraftingType, itemType = GetItemCraftingInfo(bagId, slotId)
+	local usedInCraftingType, _ = GetItemCraftingInfo(bagId, slotId)
+	local itemType = GetItemType(bagId, slotId)
+
+	-- IIfA:DebugOut("CraftingType, ItemType <<1>>, <<2>>", usedInCraftingType, itemType)

 	local qty, itemQuality
 	_, qty, _, _, _, _, _, itemQuality = GetItemInfo(bagId, slotId)
@@ -448,18 +450,18 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, itemCount, itemLink, itemName
 		usedInCraftingType 	= GetItemLinkCraftingSkillType(itemLink)
 		itemType 			= GetItemLinkItemType(itemLink)
 	end
-	if usedInCraftingType == CRAFTING_TYPE_INVALID then usedInCraftingType = nil end
-	if itemType == 0 then itemType = nil end
-
-	local itemKey = getItemKey(itemLink, usedInCraftingType, itemType) or itemLink

-	IIfA:DebugOut("saving <<1>> x<<2>> -> <<3>>", itemLink, itemCount, itemKey)
+	local itemKey
+	if bagId == BAG_VIRTUAL then
+		itemKey = tostring(slotId)
+	else
+		itemKey = IIfA:GetItemKey(itemLink, usedInCraftingType, itemType) or itemLink
+	end

+	IIfA:DebugOut("saving slot=<<1>> <<2>> x<<3>> -> <<4>>", slotId, itemLink, itemCount, itemKey)

 	if nil == itemKey then return end

-
-
 	itemFilterType = GetItemFilterTypeInfo(bagId, slotId) or 0
 	DBitem = DBv3[itemKey]
 	location = locationID or getLocation(location, bagId) or EMPTY_STRING
@@ -553,22 +555,22 @@ function IIfA:CollectAll()
 			bagItems = GetBagSize(bagId)
 			if(bagId == BAG_WORN) then	--location for BAG_BACKPACK and BAG_WORN is the same so only reset once
 				IIfA:ClearLocationData(IIfA.currentCharacterId)
-				grabBagContent(BAG_WORN)
 			elseif(bagId == BAG_BANK) then	-- do NOT add BAG_SUBSCRIBER_BANK here, it'll wipe whatever already got put into the bank on first hit
 				IIfA:ClearLocationData(GetString(IIFA_BAG_BANK))
-				grabBagContent(BAG_BANK)
 			elseif(bagId == BAG_BACKPACK) then
 				IIfA:ClearLocationData(GetString(IIFA_BAG_BACKPACK))
-				grabBagContent(BAG_BACKPACK)
 			elseif(bagId == BAG_VIRTUAL)then
 				IIfA:ClearLocationData(GetString(IIFA_BAG_CRAFTBAG))
-				grabBagContent(BAG_VIRTUAL)
 			end
 	--		d("  BagItemCount=" .. bagItems)
 			if bagId ~= BAG_VIRTUAL and tracked then
-				for slotId=0, bagItems, 1 do
-					dbItem, itemKey = IIfA:EvalBagItem(bagId, slotId)
+				grabBagContent(bagId)
+				if bagId == BAG_BANK then
+					grabBagContent(BAG_SUBSCRIBER_BANK)
 				end
+--				for slotId=0, bagItems, 1 do
+--					dbItem, itemKey = IIfA:EvalBagItem(bagId, slotId)
+--				end
 			else -- it's bag virtual
 				slotId = GetNextVirtualBagSlotId(nil)
 				while slotId ~= nil do