Added filtering of runes according to skill level.

Pontus Welin [10-27-16 - 03:33]
Added filtering of runes according to skill level.
Filename
EnchantMaker.lua
diff --git a/EnchantMaker.lua b/EnchantMaker.lua
index 6bd4673..a24c862 100644
--- a/EnchantMaker.lua
+++ b/EnchantMaker.lua
@@ -15,8 +15,9 @@ EnchMaker = {
         resultsWindowY = 0,
         mainWindowX = 0,
         mainWindowY = 0,
-        useUnknown = false,
+        useUnknownTraits = false,
         useMissing = false,
+        useUnknownSkill = false,
         training = 0,
         sameWindowCoords = false,
     },
@@ -220,45 +221,48 @@ end

 function EnchMaker.Enchant:conformsToSearch(searchTerms)
     searchTerms = searchTerms or {}
-    local potencyFiltersHit = true
+	local _, _, runeType, rankRequirement, rarityRequirement = GetItemCraftingInfo(self.ingredients[3].bag, self.ingredients[3].slot)
+	local isUsable = EnchantMakerSavedVariables.useUnknownSkill or DoesRunePassRequirements(runeType, rankRequirement, rarityRequirement)
+
+    local potencyFiltersHit = isUsable
     for k, v in pairs(searchTerms.potency) do
         potencyFiltersHit = false
         break
     end
     for k, v in pairs(searchTerms.potency) do
-        if k == self.ingredients[1].name then
-            potencyFiltersHit = true
-            break
+        if k == self.ingredients[1].name and isUsable then
+			potencyFiltersHit = true
+			break
         end
     end
     if not potencyFiltersHit then
         return false
     end

-    local essenceFiltersHit = true
+    local essenceFiltersHit = isUsable
     for k, v in pairs(searchTerms.essence) do
         essenceFiltersHit = false
         break
     end
     for k, v in pairs(searchTerms.essence) do
-        if k == self.ingredients[2].name then
-            essenceFiltersHit = true
-            break
-        end
+        if k == self.ingredients[2].name and isUsable then
+			essenceFiltersHit = true
+			break
+		end
     end
     if not essenceFiltersHit then
         return false
     end

-    local aspectFiltersHit = true
+    local aspectFiltersHit = isUsable
     for k, v in pairs(searchTerms.aspect) do
         aspectFiltersHit = false
         break
     end
     for k, v in pairs(searchTerms.aspect) do
-        if k == self.ingredients[3].name then
-            aspectFiltersHit = true
-            break
+        if k == self.ingredients[3].name and isUsable then
+			aspectFiltersHit = true
+			break
         end
     end
     if not aspectFiltersHit then
@@ -370,7 +374,7 @@ function EnchMaker.addAllStuffToInventory()
     for runestone, runeData in pairs(EnchMaker.allRunestones) do
         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.useUnknown then
+        if not EnchantMakerSavedVariables.useUnknownTraits then
             if runeData.runestoneType == "aspect" then
                 local _, _, earnedRank, _, _, _, _ = GetSkillAbilityInfo(8, 4, 1)
                 skillLevel = earnedRank
@@ -379,7 +383,7 @@ function EnchMaker.addAllStuffToInventory()
                 skillLevel = earnedRank
             end
         end
-        if EnchantMakerSavedVariables.useUnknown or runeData.skillRequirement == nil or skillLevel >= runeData.skillRequirement then
+        if EnchantMakerSavedVariables.useUnknownTraits or runeData.skillRequirement == nil or skillLevel >= runeData.skillRequirement then
             EnchMaker.Inventory.runestones[runeData.runestoneType][item] = 0
         end
     end
@@ -978,12 +982,12 @@ function EnchMaker.initMenu()
 			type = "checkbox",
 			name = GetString(ENCHANTMAKER_USE_UNKNOWN_TRAITS_SHORT),
 			tooltip = GetString(ENCHANTMAKER_USE_UNKNOWN_TRAITS_LONG),
-			getFunc = function() return EnchantMakerSavedVariables.useUnknown end,
-			setFunc = function(value) EnchantMakerSavedVariables.useUnknown = value end,
+			getFunc = function() return EnchantMakerSavedVariables.useUnknownTraits end,
+			setFunc = function(value) EnchantMakerSavedVariables.useUnknownTraits = value end,
 			width = full,	-- full or "half" (optional)
 			warning = nil,	--(optional)

-			default = EnchMaker.dataDefaults.useUnknown,
+			default = EnchMaker.dataDefaults.useUnknownTraits,
 		},
 		{
 			type = "dropdown",
@@ -995,7 +999,7 @@ function EnchMaker.initMenu()
 			end,
 			setFunc = function(value)
 				if tonumber(value) > 0 then
-					EnchantMakerSavedVariables.useUnknown = true
+					EnchantMakerSavedVariables.useUnknownTraits = true
 				end
 				EnchantMakerSavedVariables.training = tonumber(value)
 			end,
@@ -1014,6 +1018,16 @@ function EnchMaker.initMenu()

 			default = EnchMaker.dataDefaults.useMissing,
 		},
+		{
+			type = "checkbox",
+			name = GetString(ENCHANTMAKER_USE_UNKNOWN_SKILL_SHORT),
+			tooltip = GetString(ENCHANTMAKER_USE_UNKNOWN_SKILL_LONG),
+			getFunc = function() return EnchantMakerSavedVariables.useUnknownSkill end,
+			setFunc = function(value) EnchantMakerSavedVariables.useUnknownSkill = value end,
+			width = full,	-- full or "half" (optional) -- or true?
+
+			default = EnchMaker.dataDefaults.useUnknownSkill,
+		},
 	}

 	LAM:RegisterOptionControls(ADDON_NAME, optionsTable)