Fixed matching algorithm for missing ingredients and skills.

Pontus Welin [10-27-16 - 20:53]
Fixed matching algorithm for missing ingredients and skills.
Filename
EnchantMaker.lua
diff --git a/EnchantMaker.lua b/EnchantMaker.lua
index 28b5ba1..d0bf527 100644
--- a/EnchantMaker.lua
+++ b/EnchantMaker.lua
@@ -311,12 +311,8 @@ end
 function EnchMaker.Enchant.show(resultButton)
     local enchant = EnchMaker.ResultEnchants[resultButton:GetParent()]

-    if EnchMaker.atEnchantingStation and not EnchantMakerSavedVariables.useMissing then
-        ENCHANTING:ClearSelections()
-        for k, v in pairs(enchant.ingredients) do
-            ENCHANTING:AddItemToCraft(v.bag, v.slot)
-        end
-    else
+	local haveAll = true
+    if not (EnchMaker.atEnchantingStation and not EnchantMakerSavedVariables.useMissing) then
         d("___________________________________")
         local minLevel = enchant.minLevel
         if minLevel >= 50 then
@@ -330,17 +326,20 @@ function EnchMaker.Enchant.show(resultButton)
         d("|c" .. enchant.qualityColor .. enchant.prefix .. " " .. EnchMaker.stripTrailingJunk(enchant.name) .. "|r" .. " - for level " .. minLevel .. " to " .. maxLevel)

         d(GetString(ENCHANTMAKER_MADE_WITH))
-        for i = 1, #enchant.ingredients do
-            --local ingredient = EnchMaker.Inventory.runestones[EnchMaker.allRunestones[enchant.ingredients[i].name].runestoneType]
-			d(enchant.ingredients[i].bag)
+		for i = 1, #enchant.ingredients do
 			local amount = EnchMaker.Inventory.runestones[EnchMaker.allRunestones[enchant.ingredients[i].name].runestoneType][enchant.ingredients[i]]
             d("|c" .. enchant.ingredients[i].qualityColor .. enchant.ingredients[i].name .. " (" .. amount .. ")|r")
-			if enchant.ingredients[i].bag ~= 0 then
-				ENCHANTING:ClearSelections()
-				ENCHANTING:AddItemToCraft(enchant.ingredients[i].bag, enchant.ingredients[i].slot)
+			if amount == 0 or amount == "0" then
+				haveAll = false
 			end
 		end
     end
+	if haveAll then
+		ENCHANTING:ClearSelections()
+		for i = 1, #enchant.ingredients do
+			ENCHANTING:AddItemToCraft(enchant.ingredients[i].bag, enchant.ingredients[i].slot)
+		end
+	end
 end

 EnchMaker.Inventory = {
@@ -378,7 +377,6 @@ function EnchMaker.addAllStuffToInventory()
         local item = EnchMaker.Runestone:new{name = runeData.name, translation = runeData.translation, quality = runeData.quality, skillRequirement = runeData.skillRequirement, prefix = runeData.prefix, minLevel = runeData.minLevel, maxLevel = runeData.maxLevel}
         local skillLevel = 0
         if not EnchantMakerSavedVariables.useUnknownTraits then
-			d(runeData.runestoneType)
             if runeData.runestoneType == "aspect" then
                 local _, _, earnedRank, _, _, _, _ = GetSkillAbilityInfo(8, 4, 1)
                 skillLevel = earnedRank
@@ -387,7 +385,7 @@ function EnchMaker.addAllStuffToInventory()
                 skillLevel = earnedRank
             end
         end
-        if EnchantMakerSavedVariables.useUnknownTraits or runeData.skillRequirement == nil or skillLevel >= runeData.skillRequirement then
+        if EnchantMakerSavedVariables.useUnknownSkill or runeData.skillRequirement == nil or skillLevel >= runeData.skillRequirement then
             EnchMaker.Inventory.runestones[runeData.runestoneType][item] = 0
         end
     end
@@ -402,46 +400,51 @@ function EnchMaker.addStuffToInventoryForBag(bagId)

         if itemType == ITEMTYPE_ENCHANTING_RUNE_ASPECT or itemType == ITEMTYPE_ENCHANTING_RUNE_ESSENCE or itemType == ITEMTYPE_ENCHANTING_RUNE_POTENCY or itemType == ITEMTYPE_ENCHANTMENT_BOOSTER then
 			local _, stack, _, meetsUsageRequirement, _, _, _, quality = GetItemInfo(bagId, slotIndex)
-            if (meetsUsageRequirement or EnchantMakerSavedVariables.useUnknownSkill) and (itemType == ITEMTYPE_ENCHANTING_RUNE_ASPECT or itemType == ITEMTYPE_ENCHANTING_RUNE_ESSENCE or itemType == ITEMTYPE_ENCHANTING_RUNE_POTENCY) then
-                --translation = "Negate", prefix = "Splendid", skillRequirement = 9, minLevel = 57, maxLevel = 59
-                local runeData = EnchMaker.allRunestones[EnchMaker.stripTrailingJunk(GetItemName(bagId, slotIndex))]
-                local itemAlreadyInInventory = nil
-                for k, v in pairs(EnchMaker.Inventory.runestones[runeData.runestoneType]) do
-                    if k.name == runeData.name and v > 0 then
-                        itemAlreadyInInventory = k
-                        break
-                    end
-                end
-                if itemAlreadyInInventory ~= nil then
-                    EnchMaker.Inventory.runestones[runeData.runestoneType][itemAlreadyInInventory] = EnchMaker.Inventory.runestones[runeData.runestoneType][itemAlreadyInInventory] + stack
-                else
-					local item = EnchMaker.Runestone:new{name = runeData.name, translation = runeData.translation, quality = runeData.quality, skillRequirement = runeData.skillRequirement, prefix = runeData.prefix, minLevel = runeData.minLevel, maxLevel = runeData.maxLevel, bag = bagId, slot = slotIndex}
-					local qualityColor = GetItemQualityColor(quality)
-					item.qualityColor = EnchMaker.DEC_HEX(math.floor(((qualityColor["r"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["g"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["b"]) * 256) - 0.5))
-                    EnchMaker.Inventory.runestones[runeData.runestoneType][item] = stack
-                end
-            elseif meetsUsageRequirement or EnchantMakerSavedVariables.useUnknownSkill then
-                d("TODO: Handle ITEMTYPE_ENCHANTMENT_BOOSTER")
-                d(GetItemName(bagId, slotIndex))
-                -- translation = "Negate", prefix = "Splendid", skillRequirement = 9, minLevel = 57, maxLevel = 59
-                -- local item = EnchMaker.Runestone:new{EnchMaker.allRunestones[EnchMaker.stripTrailingJunk(GetItemName(bagId, slotIndex))]}
-                -- item.bag = bagId
-                -- item.slot = slotIndex
-                -- local qualityColor = GetItemQualityColor(quality)
-                -- item.qualityColor = EnchMaker.DEC_HEX(math.floor(((qualityColor["r"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["g"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["b"]) * 256) - 0.5))
-                -- local itemAlreadyInInventory = nil
-                -- for k, v in pairs(EnchMaker.Inventory.solvents) do
-                    -- if k.name == item.name then
-                        -- itemAlreadyInInventory = k
-                        -- break
-                    -- end
-                -- end
-                -- if itemAlreadyInInventory ~= nil then
-                    -- EnchMaker.Inventory.solvents[itemAlreadyInInventory] = EnchMaker.Inventory.solvents[itemAlreadyInInventory] + stack
-                -- else
-                    -- EnchMaker.Inventory.solvents[item] = stack
-                -- end
-            end
+            if (meetsUsageRequirement or EnchantMakerSavedVariables.useUnknownSkill) then
+				if (itemType == ITEMTYPE_ENCHANTING_RUNE_ASPECT or itemType == ITEMTYPE_ENCHANTING_RUNE_ESSENCE or itemType == ITEMTYPE_ENCHANTING_RUNE_POTENCY) then
+					--translation = "Negate", prefix = "Splendid", skillRequirement = 9, minLevel = 57, maxLevel = 59
+					local runeData = EnchMaker.allRunestones[EnchMaker.stripTrailingJunk(GetItemName(bagId, slotIndex))]
+					local itemAlreadyInInventory = nil
+					local count = nil
+					for k, v in pairs(EnchMaker.Inventory.runestones[runeData.runestoneType]) do
+						if k.name == runeData.name then
+							itemAlreadyInInventory = k
+							count = v
+							break
+						end
+					end
+
+					if itemAlreadyInInventory ~= nil then
+						EnchMaker.Inventory.runestones[runeData.runestoneType][itemAlreadyInInventory] = count + stack
+					else
+						local item = EnchMaker.Runestone:new{name = runeData.name, translation = runeData.translation, quality = runeData.quality, skillRequirement = runeData.skillRequirement, prefix = runeData.prefix, minLevel = runeData.minLevel, maxLevel = runeData.maxLevel, bag = bagId, slot = slotIndex}
+						local qualityColor = GetItemQualityColor(quality)
+						item.qualityColor = EnchMaker.DEC_HEX(math.floor(((qualityColor["r"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["g"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["b"]) * 256) - 0.5))
+						EnchMaker.Inventory.runestones[runeData.runestoneType][item] = stack
+					end
+				elseif itemType == ITEMTYPE_ENCHANTMENT_BOOSTER then
+					d("TODO: Handle ITEMTYPE_ENCHANTMENT_BOOSTER")
+					d(GetItemName(bagId, slotIndex))
+					-- translation = "Negate", prefix = "Splendid", skillRequirement = 9, minLevel = 57, maxLevel = 59
+					-- local item = EnchMaker.Runestone:new{EnchMaker.allRunestones[EnchMaker.stripTrailingJunk(GetItemName(bagId, slotIndex))]}
+					-- item.bag = bagId
+					-- item.slot = slotIndex
+					-- local qualityColor = GetItemQualityColor(quality)
+					-- item.qualityColor = EnchMaker.DEC_HEX(math.floor(((qualityColor["r"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["g"]) * 256) - 0.5)) .. EnchMaker.DEC_HEX(math.floor(((qualityColor["b"]) * 256) - 0.5))
+					-- local itemAlreadyInInventory = nil
+					-- for k, v in pairs(EnchMaker.Inventory.solvents) do
+						-- if k.name == item.name then
+							-- itemAlreadyInInventory = k
+							-- break
+						-- end
+					-- end
+					-- if itemAlreadyInInventory ~= nil then
+						-- EnchMaker.Inventory.solvents[itemAlreadyInInventory] = EnchMaker.Inventory.solvents[itemAlreadyInInventory] + stack
+					-- else
+						-- EnchMaker.Inventory.solvents[item] = stack
+					-- end
+				end
+			end
         end
 		slotIndex = ZO_GetNextBagSlotIndex(bagId, slotIndex)
     end
@@ -816,7 +819,8 @@ function EnchMaker.updateControls()
     local newHeight = 390
     if #EnchMaker.PotencyFilterControls == 0 then
         local index = 1
-        for _, k in pairs(EnchMaker.sortAndFlattenIngredients(EnchMaker.Inventory.runestones.additivePotency, function (a, b) return a.minLevel < b.minLevel end)) do
+		table.sort(EnchMaker.Inventory.runestones.additivePotency, function (a, b) return a.minLevel < b.minLevel end)
+        for k, v in pairs(EnchMaker.Inventory.runestones.additivePotency) do
             local controlName = "EnchantMaker" .. k.name:gsub(" ", "") .. "CheckBox"
             local control = WINDOW_MANAGER:GetControlByName(controlName)
             local labelControl = WINDOW_MANAGER:GetControlByName(controlName .. "Text")