diff --git a/AtlasLoot/Core/AtlasLoot.lua b/AtlasLoot/Core/AtlasLoot.lua index dce334b..a1b0aef 100644 --- a/AtlasLoot/Core/AtlasLoot.lua +++ b/AtlasLoot/Core/AtlasLoot.lua @@ -1350,8 +1350,8 @@ On the form of {Name, {normal, heroic, mythic, mythic1, mythic2, ... ,mythicN}} ]] function AL_FindId(name, difficulty) if ItemIDsDatabase[name] ~= nil then - return ItemIDsDatabase[name][difficulty] - else - return nil; + return ItemIDsDatabase[name][difficulty], true end + + return nil, false; end \ No newline at end of file diff --git a/AtlasLoot/Core/Search.lua b/AtlasLoot/Core/Search.lua index 6f00ba9..aeea25d 100644 --- a/AtlasLoot/Core/Search.lua +++ b/AtlasLoot/Core/Search.lua @@ -190,6 +190,7 @@ local SLOT_FILTERS = { ["ranged"] = "INVTYPE_RANGED", ["cloak"] = "INVTYPE_CLOAK", ["2hweapon"] = "INVTYPE_2HWEAPON", + ["2h"] = "INVTYPE_2HWEAPON", ["bag"] = "INVTYPE_BAG", ["tabard"] = "INVTYPE_TABARD", ["robe"] = "INVTYPE_ROBE", @@ -205,6 +206,38 @@ local SLOT_FILTERS = { ["relic"] = "INVTYPE_RELIC" }; +local TYPE_FILTERS = { + ["cloth"] = "Cloth", + ["leather"] = "Leather", + ["mail"] = "Mail", + ["plate"] = "Plate", + ["shield"] = "Shields", + ["libram"] = "Librams", + ["idol"] = "Idols", + ["totem"] = "Totems", + ["sigil"] = "Sigils", + + ["bow"] = "Bows", + ["crossbow"] = "Crossbows", + ["dagger"] = "Daggers", + ["gun"] = "Guns", + ["fishing poles"] = "Fishing Poles", + ["fist"] = "Fist Weapons", + ["miscellaneous"] = "Miscellaneous", + ["axe"] = "One-Handed Axes", + ["mace"] = "One-Handed Maces", + ["sword"] = "One-Handed Swords", + ["polearm"] = "Polearms", + ["stave"] = "Staves", + ["staves"] = "Staves", + ["staff"] = "Staves", + ["thrown"] = "Thrown", + ["2haxe"] = "Two-Handed Axes", + ["2hmace"] = "Two-Handed Maces", + ["2hsword"] = "Two-Handed Swords", + ["wand"] = "Wands", +} + local NON_EQUIPABLE_SLOTS = { ["INVTYPE_NON_EQUIP"] = true, ["INVTYPE_BODY"] = true, @@ -375,6 +408,41 @@ local function IsItemSlotMatch(term, itemEquipLoc) return slot == itemEquipLoc end +local function IsItemTypeMatch(term, itemEquipType) + if term.left ~= "type" then + return + end + + if term.relational ~= "=" then + ThrowQueryError("type searches should be in the form \"type=[typename]\"") + end + + local type = TYPE_FILTERS[term.right] + if not type then + ThrowQueryError("unrecognized type name: \"%s\"", term.right) + end + + return type == itemEquipType; +end + +local function IsItemDifficulty(term, itemName) + if term.left ~= "dif" then + return + end + + if term.relational ~= "=" then + ThrowQueryError("difficulty searches should be in the form \"dif=[difficulty]\"") + end + + if tonumber(term.right) > (#AtlasLoot_Difficulty.MythicPlus + 4) then + ThrowQueryError("difficulty should be a number: 1 - %i", #AtlasLoot_Difficulty.MythicPlus + 4) + end + + local _, hasDifficulty = AL_FindId(itemName, tonumber(term.right)); + + return hasDifficulty; +end + local function nameMatches(name, searchText) if AtlasLoot.db.profile.PartialMatching then return string.find(string.lower(name), searchText); @@ -383,7 +451,7 @@ local function nameMatches(name, searchText) end end -local function ItemMatchesTerm(term, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc) +local function ItemMatchesTerm(term, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc, itemType) if term.relational then return IsItemStatMatch(term, stats) or IsItemSocketMatch(term, stats) @@ -391,20 +459,32 @@ local function ItemMatchesTerm(term, itemName, stats, itemLvl, minLvl, itemQuali or IsMinLevelFilterMatch(term, minLvl) or IsItemSlotMatch(term, itemEquipLoc) or IsItemQualityMatch(term, itemQuality) + or IsItemTypeMatch(term, itemType) + or IsItemDifficulty(term, itemName) else return nameMatches(itemName, term.name) end end -local function ItemMatchesAllTerms(searchTerms, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc) +local function ItemMatchesAllTerms(searchTerms, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc, itemType) for _, term in ipairs(searchTerms) do - if not ItemMatchesTerm(term, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc) then + if not ItemMatchesTerm(term, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc, itemType) then return false end end return true end +local function TermsContainDifficulty(searchTerms) + for _, term in ipairs(searchTerms) do + if term.relational then + if term.left == "dif" then return tonumber(term.right) end + end + end + + return AtlasLoot_Difficulty.Normal; +end + local function ParseTerm(termText) for _, relational in ipairs(RELATIONAL_OPERATORS) do local operands = SplitString(termText, relational) @@ -431,9 +511,9 @@ end local function GetItemDetails(itemId, atlasName) -- Name, Link, Quality(num), iLvl(num), minLvl(num), itemType(localized string), itemSubType(localized string), stackCount(num), itemEquipLoc(enum), texture(link to a local file), displayId(num) - local itemName, _, itemQuality, itemLvl, minLvl, _, _, _, itemEquipLoc = GetItemInfo(itemId); + local itemName, _, itemQuality, itemLvl, minLvl, _, itemSubType, _, itemEquipLoc = GetItemInfo(itemId); if not itemName then itemName = gsub(atlasName, "=q%d=", "") end - return itemName, itemQuality, itemLvl, minLvl, itemEquipLoc, GetItemStats("item:"..itemId) + return itemName, itemQuality, itemLvl, minLvl, itemEquipLoc, itemSubType, GetItemStats("item:"..itemId) end local function GetSpellName(itemId, atlasName) @@ -449,15 +529,16 @@ end local function DoSearch(searchText) AtlasLootCharDB["SearchResult"] = {}; - AtlasLootCharDB.LastSearchedText = Text; + AtlasLootCharDB.LastSearchedText = searchText; - local function AddItemToSearchResult(itemId, itemType, itemName, dataID) + local function AddItemToSearchResult(itemId, itemType, itemName, dataID, difficulty) local lootPage = AtlasLoot_TableNames[dataID] and AtlasLoot_TableNames[dataID][1] or "Argh!"; - table.insert(AtlasLootCharDB["SearchResult"], { 0, itemId, itemType, itemName, lootPage, "", "", dataID.."|".."\"\"", [AtlasLoot_Difficulty.DIF_SEARCH] = 2}); + table.insert(AtlasLootCharDB["SearchResult"], { 0, itemId, itemType, itemName, lootPage, "", "", dataID.."|".."\"\""}); end - local searchTerms = ParseQuery(searchText) - local equipableFilterOn = AtlasLoot.db.profile.EquipableFilter + local searchTerms = ParseQuery(searchText); + local equipableFilterOn = AtlasLoot.db.profile.EquipableFilter; + local difficulty = TermsContainDifficulty(searchTerms); local function IsItemEquipableMatch(itemEquipLoc) return not equipableFilterOn or (itemEquipLoc and itemEquipLoc ~= '' and not NON_EQUIPABLE_SLOTS[itemEquipLoc]) end @@ -466,10 +547,14 @@ local function DoSearch(searchText) for _, v in ipairs(data) do local _, itemId, itemType, atlasName = unpack(v) + itemId = AL_FindId(string.sub(atlasName, 5), difficulty); + + itemId = tonumber(itemId); + if type(itemId) == "number" and itemId > 0 then - local itemName, itemQuality, itemLvl, minLvl, itemEquipLoc, stats = GetItemDetails(itemId, atlasName); - if IsItemEquipableMatch(itemEquipLoc) and ItemMatchesAllTerms(searchTerms, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc) then - AddItemToSearchResult(itemId, itemType, itemName, dataID) + local itemName, itemQuality, itemLvl, minLvl, itemEquipLoc, itemSubType, stats = GetItemDetails(itemId, atlasName); + if IsItemEquipableMatch(itemEquipLoc) and ItemMatchesAllTerms(searchTerms, itemName, stats, itemLvl, minLvl, itemQuality, itemEquipLoc, itemSubType) then + AddItemToSearchResult(itemId, itemType, itemName, dataID, difficulty); end elseif not equipableFilterOn and itemId and itemId ~= "" and string.sub(itemId, 1, 1) == "s" then local spellName = GetSpellName(itemId, atlasName) diff --git a/AtlasLoot/Core/SearchAdvanced.lua b/AtlasLoot/Core/SearchAdvanced.lua index b2136ca..2f82d85 100644 --- a/AtlasLoot/Core/SearchAdvanced.lua +++ b/AtlasLoot/Core/SearchAdvanced.lua @@ -34,27 +34,27 @@ AdvSearchSubMenuText = ""; AdvSearchSetup = false; AtlasLoot_FrameMenuList = { - ["EquipSubMenu"] = {AtlasLoot_EquipSubMenu, "AtlasLootAdvancedSearch_EquipSub", "Select Option", "equipType", "", "AtlasLootAdvancedSearch_WeaponSub"}; + ["EquipSubMenu"] = {AtlasLoot_EquipSubMenu, "AtlasLootAdvancedSearch_EquipSub", "Select Option", "type", "", "AtlasLootAdvancedSearch_WeaponSub"}; ["MythicSubMenu"] = {AtlasLoot_DiffSubMenu, "AtlasLootAdvancedSearch_MythicSub", "Mythic+ 1", "difficulty", 5}; - ["WeaponSubMenu"] = {AtlasLoot_WeaponSubMenu, "AtlasLootAdvancedSearch_WeaponSub", "Select Weapon Type", "equipType", ""}; + ["WeaponSubMenu"] = {AtlasLoot_WeaponSubMenu, "AtlasLootAdvancedSearch_WeaponSub", "Select Weapon Type", "type", ""}; } AtlasLoot_AdvancedSearchMenus = { ["Difficulty"] ={ [1] = { - {"Normal", "difficulty", 2, "MythicSubMenu", "Disable"}, + {"Normal", "difficulty", AtlasLoot_Difficulty.Normal, "MythicSubMenu", "Disable"}, }, [2] = { - {"Heroic", "difficulty", 3, "MythicSubMenu", "Disable"}, + {"Heroic", "difficulty", AtlasLoot_Difficulty.Heroic, "MythicSubMenu", "Disable"}, }, [3] = { - {"Mythic/Ascended", "difficulty", 4, "MythicSubMenu", "Disable"}, + {"Mythic/Ascended", "difficulty", AtlasLoot_Difficulty.Mythic, "MythicSubMenu", "Disable"}, }, [4] = { - {"Mythic Plus", "difficulty", 5, "MythicSubMenu", "MythicPlus"}, + {"Mythic Plus", "difficulty", AtlasLoot_Difficulty.MythicPlus[1], "MythicSubMenu", "MythicPlus"}, }, [5] = { - {"Bloodforged", "difficulty", 1, "MythicSubMenu", "Disable"}, + {"Bloodforged", "difficulty", AtlasLoot_Difficulty.Bloodforged, "MythicSubMenu", "Disable"}, }, }; @@ -97,7 +97,7 @@ AtlasLoot_AdvancedSearchMenus = { {"Wrist", "equip", "wrist", "EquipSubMenu", "ArmorType"}, }, [5] = { - {"Hands", "equip", "hands", "EquipSubMenu", "ArmorType"}, + {"Hands", "equip", "hand", "EquipSubMenu", "ArmorType"}, }, [6] = { {"Waist", "equip", "waist", "EquipSubMenu", "ArmorType"}, @@ -133,31 +133,31 @@ AtlasLoot_AdvancedSearchMenus = { ["ArmorType"] = { [1] = { - {"Cloth", "equipType", "cloth"}, + {"Cloth", "type", "Cloth"}, }, [2] = { - {"Leather", "equipType", "leather"}, + {"Leather", "type", "Leather"}, }, [3] = { - {"Mail", "equipType", "mail"}, + {"Mail", "type", "Mail"}, }, [4] = { - {"Plate", "equipType", "plate"}, + {"Plate", "type", "Plate"}, }, }; ["RelicType"] = { [1] = { - {"Idols", "equipType", "idol"}, + {"Idols", "type", "idol"}, }, [2] = { - {"Libram", "equipType", "libram"}, + {"Libram", "type", "libram"}, }, [3] = { - {"Totem", "equipType", "totem"}, + {"Totem", "type", "totem"}, }, [4] = { - {"Sigil", "equipType", "sigil"}, + {"Sigil", "type", "sigil"}, }, }; @@ -166,7 +166,7 @@ AtlasLoot_AdvancedSearchMenus = { {"One-Hand", "equip", "weapon", "WeaponSubMenu", "WeaponType"}, }, [2] = { - {"Two-Hand", "equip", "2hweapon", "WeaponSubMenu", "WeaponType"}, + {"Two-Hand", "equip", "2h", "WeaponSubMenu", "WeaponType"}, }, [3] = { {"Main Hand", "equip", "mainhand", "WeaponSubMenu", "WeaponType"}, @@ -181,43 +181,43 @@ AtlasLoot_AdvancedSearchMenus = { ["WeaponType"] = { [1] = { - {"Axe", "equipType", "#w1#"} + {"Axe", "type", "axe"} }, [2] = { - {"Mace", "equipType", "#w6#"} + {"Mace", "type", "mace"} }, [3] = { - {"Sword", "equipType", "#w10#"} + {"Sword", "type", "sword"} }, [4] = { - {"Polearm", "equipType", "#w7#"} + {"Polearm", "type", "polearm"} }, [5] = { - {"Dagger", "equipType", "#w4#"} + {"Dagger", "type", "dagger"} }, [6] = { - {"Staff", "equipType", "#w9#"} + {"Staff", "type", "stave"} }, [7] = { - {"Fist Weapon", "equipType", "#w13#"} + {"Fist Weapon", "type", "fist"} }, [8] = { - {"Bow", "equipType", "#w2#"} + {"Bow", "type", "bow"} }, [9] = { - {"Gun", "equipType", "#w5#"} + {"Gun", "type", "gun"} }, [10] = { - {"Crossbow", "equipType", "#w3#"} + {"Crossbow", "type", "crossbow"} }, [11] = { - {"Wand", "equipType", "#w12#"} + {"Wand", "type", "wand"} }, [12] = { - {"Thrown", "equipType", "#w11#"} + {"Thrown", "type", "thrown"} }, [13] = { - {"Shield", "equipType", "#w8#"} + {"Shield", "type", "shield"} }, }; } @@ -315,7 +315,7 @@ AtlasLoot_AdvancedSearchArguments = { AdvancedSearchOptions = { ["quality"] = "", ["equip"] = "", - ["equipType"] = "", + ["type"] = "", ["difficulty"] = 0, ["arg1"] = "", ["arg1op"] = "", @@ -341,7 +341,7 @@ function AtlasLoot_AdvancedSearchSetup() --Setup Mythic+ dropdown options; for i = 1, 30, 1 do AtlasLoot_AdvancedSearchMenus["MythicPlus"][i] = { - {"Mythic+ "..i, "difficulty", i + 4}; + {"Mythic+ "..i, "difficulty", AtlasLoot_Difficulty.MythicPlus[i]}; } end @@ -434,7 +434,7 @@ function AtlasLoot_AdvancedSearchReset() ["quality"] = "", ["equip"] = "", ["equipType"] = "", - ["difficulty"] = 0, + ["difficulty"] = AtlasLoot_Difficulty.Normal, ["arg1"] = "", ["arg1op"] = "", ["arg2"] = "", @@ -445,7 +445,6 @@ function AtlasLoot_AdvancedSearchReset() AtlasLootAdvancedSearch_Quality:SetText("Select Quality"); AtlasLootAdvancedSearch_Equip:SetText("Select Item Type"); - AtlasLootAdvancedSearch_Difficulty:Disable(); AtlasLootAdvancedSearch_Difficulty:SetText("Select Difficulty"); AtlasLootAdvancedSearch_Argument1:SetText("Select Option"); AtlasLootAdvancedSearch_Argument2:SetText("Select Option"); @@ -750,18 +749,29 @@ function AtlasLoot:AdvancedSearch(Text, args) return str; end + local function AdvancedSearchFixType(slot, subType) + if slot == "2h" and (subType == "axe" or subType == "sword" or subType == "mace") then + return slot..subType; + end + end + if AdvancedSearchOptions["quality"] ~= "" then advSearchString = AppendSearchString(advSearchString, "quality="..AdvancedSearchOptions["quality"]); end - if AdvancedSearchOptions["equipType"] ~= "" then - --advSearchString = AppendSearchString(advSearchString, AtlasLoot_FixText(AdvancedSearchOptions["equipType"])); - end - if AdvancedSearchOptions["equip"] ~= "" then advSearchString = AppendSearchString(advSearchString, "slot="..AdvancedSearchOptions["equip"]); end + if AdvancedSearchOptions["type"] ~= "" and AdvancedSearchOptions["type"] then + AdvancedSearchOptions["type"] = AdvancedSearchFixType(AdvancedSearchOptions["equip"], AdvancedSearchOptions["type"]) or AdvancedSearchOptions["type"]; + advSearchString = AppendSearchString(advSearchString, "type="..AdvancedSearchOptions["type"]); + end + + if AdvancedSearchOptions["difficulty"] ~= "" then + advSearchString = AppendSearchString(advSearchString, "dif="..AdvancedSearchOptions["difficulty"]); + end + for i = 1, 3, 1 do if AdvancedSearchOptions["arg"..i] ~= "" then if AdvancedSearchOptions["arg"..i.."op"] == "" then @@ -772,6 +782,6 @@ function AtlasLoot:AdvancedSearch(Text, args) advSearchString = AppendSearchString(advSearchString, AdvancedSearchOptions["arg"..i]..AdvancedSearchOptions["arg"..i.."op"]..args[i]); end end - print(string.lower(advSearchString)); + AtlasLoot:Search(string.lower(advSearchString)); end \ No newline at end of file