annotate LFGFilter.lua @ 18:caae3287d83c

add support for Blackrock Foundry (zone, not bosses for the moment)
author ovolkov
date Thu, 05 Feb 2015 04:21:54 +0300
parents ba1754998685
children 8dc3e648abeb
rev   line source
ovolkov@7 1 local dump = DevTools_Dump
ovolkov@3 2 LFGListFrame.SearchPanel.SearchBox:SetMaxLetters(2048)
ovolkov@0 3
ovolkov@3 4 local filter_expression_functions = setmetatable({}, {
ovolkov@3 5 __mode = "k",
ovolkov@3 6 __index = function(t, key)
ovolkov@3 7 local func, error = loadstring("return " .. key)
ovolkov@3 8 if error then print("Error in LFG filter expression:\n", error) end
ovolkov@3 9 t[key] = func
ovolkov@3 10 return func
ovolkov@3 11 end
ovolkov@3 12 })
ovolkov@3 13
ovolkov@10 14 local aliases = {
ovolkov@18 15 hm = "highmaul",
ovolkov@18 16 brf = "blackrock_foundry",
ovolkov@18 17 blackrockfoundry = "blackrock_foundry",
ovolkov@18 18 healers = "healer",
ovolkov@18 19 members = "member",
ovolkov@18 20 tanks = "tank",
ovolkov@18 21 damagers = "damager",
ovolkov@18 22 damage = "damager",
ovolkov@18 23 plates = "plate",
ovolkov@18 24 mails = "mail",
ovolkov@18 25 leathers = "leather",
ovolkov@18 26 cloths = "cloth",
ovolkov@18 27 clothies = "cloth",
ovolkov@10 28 }
ovolkov@10 29 for idx = 1, MAX_CLASSES do
ovolkov@10 30 local class_lc = CLASS_SORT_ORDER[idx]:lower()
ovolkov@10 31 aliases[class_lc .. "s"] = class_lc
ovolkov@10 32 end
ovolkov@10 33
ovolkov@11 34 local token_to_encounter_id = {
ovolkov@11 35 highmaul = {
ovolkov@12 36 lfg_dungeon_id = 849,
ovolkov@12 37 { "kargath", "bladefist", "kargath_bladefist" },
ovolkov@12 38 { "butcher", "the_butcher" },
ovolkov@12 39 { "tectus" },
ovolkov@12 40 { "brackenspore", "bracken" },
ovolkov@12 41 { "twin_orgon", "twins" },
ovolkov@12 42 { "koragh", "breaker" },
ovolkov@12 43 { "imperator", "margok" },
ovolkov@11 44 }
ovolkov@11 45 }
ovolkov@11 46
ovolkov@3 47 function LFGListSearchPanel_DoSearch(self)
ovolkov@3 48 local searchText = self.SearchBox:GetText();
ovolkov@3 49 local real_search, filter_expression = searchText:match("^([^=]-)=(.+)$")
ovolkov@3 50 if filter_expression then
ovolkov@3 51 filter_expression = filter_expression:lower()
ovolkov@3 52 self.filter_func = filter_expression_functions[filter_expression]
ovolkov@3 53 end
ovolkov@3 54 self.filter_expression = filter_expression
ovolkov@3 55
ovolkov@3 56 -- print("lfgsearch", real_search, filter_expression)
ovolkov@3 57 C_LFGList.Search(self.categoryID, real_search or searchText, self.filters, self.preferredFilters);
ovolkov@3 58 self.searching = true;
ovolkov@3 59 self.searchFailed = false;
ovolkov@3 60 self.selectedResult = nil;
ovolkov@3 61 LFGListSearchPanel_UpdateResultList(self);
ovolkov@3 62 LFGListSearchPanel_UpdateResults(self);
ovolkov@3 63 end
ovolkov@3 64
ovolkov@12 65 local localized_encounter_name_to_idx = {}
ovolkov@11 66
ovolkov@11 67 local function InsertEncounterStateAliases(result_env, raid_token, completed_encounters)
ovolkov@11 68 local encounter_aliases = token_to_encounter_id[raid_token]
ovolkov@11 69 if not encounter_aliases then return end
ovolkov@11 70
ovolkov@12 71 local lfg_dungeon_id = encounter_aliases.lfg_dungeon_id
ovolkov@12 72 local encounter_names = localized_encounter_name_to_idx[lfg_dungeon_id]
ovolkov@11 73 if not encounter_names then
ovolkov@11 74 encounter_names = {}
ovolkov@12 75 for idx = 1, GetLFGDungeonNumEncounters(lfg_dungeon_id) do
ovolkov@12 76 local bossName, texture, isKilled = GetLFGDungeonEncounterInfo(lfg_dungeon_id, idx)
ovolkov@12 77 encounter_names[bossName] = idx
ovolkov@12 78 end
ovolkov@12 79 localized_encounter_name_to_idx[lfg_dungeon_id] = encounter_names
ovolkov@11 80 end
ovolkov@11 81
ovolkov@11 82 for idx = 1, #completed_encounters do
ovolkov@11 83 local encounter_id = encounter_names[completed_encounters[idx]]
ovolkov@11 84 if encounter_id then
ovolkov@11 85 local aliases = encounter_aliases[encounter_id]
ovolkov@11 86 if aliases then
ovolkov@11 87 for alias_idx = 1, #aliases do
ovolkov@11 88 result_env[aliases[alias_idx]] = true
ovolkov@11 89 end
ovolkov@11 90 end
ovolkov@11 91 end
ovolkov@11 92 end
ovolkov@11 93 end
ovolkov@11 94
ovolkov@3 95 local result_env = {}
ovolkov@3 96 -- =highmaul and ((normal and (name:match("imp") or defeated == 6)) or (heroic and defeated == 2))
ovolkov@0 97 function LFGListUtil_SortSearchResults(results)
ovolkov@3 98 local self = LFGListFrame.SearchPanel
ovolkov@3 99 if self.filter_expression then
ovolkov@3 100 local check = self.filter_func
ovolkov@0 101 local shift_down = 0
ovolkov@0 102 local original_size = #results
ovolkov@0 103 for idx = 1, original_size do
ovolkov@3 104 local id = results[idx]
ovolkov@3 105 local _, activityID, name, comment, voiceChat, iLvl, age, numBNetFriends, numCharFriends, numGuildMates, isDelisted, leaderName, numMembers = C_LFGList.GetSearchResultInfo(id)
ovolkov@3 106 local completedEncounters = C_LFGList.GetSearchResultEncounterInfo(id)
ovolkov@3 107 local memberCounts = C_LFGList.GetSearchResultMemberCounts(id)
ovolkov@3 108
ovolkov@3 109 wipe(result_env)
ovolkov@3 110 result_env.name = name:lower()
ovolkov@3 111 result_env.comment = comment:lower()
ovolkov@3 112 result_env.ilvl = iLvl
ovolkov@3 113 -- TODO: should be calculated in meta
ovolkov@3 114 result_env.defeated = completedEncounters and #completedEncounters or 0
ovolkov@6 115 result_env.member = numMembers
ovolkov@6 116 result_env.tank = memberCounts.TANK
ovolkov@6 117 result_env.healer = memberCounts.HEALER
ovolkov@6 118 result_env.damager = memberCounts.DAMAGER + memberCounts.NOROLE
ovolkov@3 119 result_env.my_server = leaderName and not leaderName:find('-')
ovolkov@3 120
ovolkov@7 121 for idx = 1, numMembers do
ovolkov@7 122 local role, class, classLocalized = C_LFGList.GetSearchResultMemberInfo(id, idx)
ovolkov@7 123 local class_lc = class:lower()
ovolkov@7 124 local prev_count = result_env[class_lc]
ovolkov@7 125 result_env[class_lc] = prev_count and (prev_count + 1) or 0
ovolkov@7 126 end
ovolkov@7 127 for idx = 1, MAX_CLASSES do
ovolkov@7 128 local class_lc = CLASS_SORT_ORDER[idx]:lower()
ovolkov@7 129 local count = result_env[class_lc]
ovolkov@10 130 if not count then result_env[class_lc] = 0 end
ovolkov@7 131 end
ovolkov@7 132
ovolkov@11 133 local raid_token
ovolkov@3 134 if activityID == 37 then
ovolkov@11 135 raid_token = "highmaul"
ovolkov@3 136 result_env.normal = true
ovolkov@3 137 elseif activityID == 38 then
ovolkov@11 138 raid_token = "highmaul"
ovolkov@3 139 result_env.heroic = true
ovolkov@18 140 elseif activityID == 39 then
ovolkov@18 141 raid_token = "blackrock_foundry"
ovolkov@18 142 result_env.normal = true
ovolkov@18 143 elseif activityID == 40 then
ovolkov@18 144 raid_token = "blackrock_foundry"
ovolkov@18 145 result_env.heroic = true
ovolkov@3 146 end
ovolkov@3 147
ovolkov@17 148 if raid_token then
ovolkov@17 149 result_env[raid_token] = true
ovolkov@17 150 if completedEncounters then InsertEncounterStateAliases(result_env, raid_token, completedEncounters) end
ovolkov@17 151 end
ovolkov@11 152
ovolkov@11 153 result_env.dead = true
ovolkov@11 154 result_env.defeated = true
ovolkov@11 155
ovolkov@11 156 -- dump(result_env)
ovolkov@10 157
ovolkov@10 158 for alias, original in pairs(aliases) do result_env[alias] = result_env[original] end
ovolkov@10 159
ovolkov@10 160 -- dump(result_env)
ovolkov@7 161
ovolkov@3 162 local pass
ovolkov@3 163 if check then
ovolkov@3 164 setfenv(check, result_env)
ovolkov@3 165 pass = check()
ovolkov@3 166 end
ovolkov@3 167
ovolkov@3 168 if pass then
ovolkov@0 169 if shift_down > 0 then
ovolkov@3 170 results[idx - shift_down] = id
ovolkov@0 171 end
ovolkov@0 172 else
ovolkov@0 173 shift_down = shift_down + 1
ovolkov@0 174 end
ovolkov@3 175
ovolkov@0 176 end
ovolkov@0 177 for idx = original_size - shift_down + 1, original_size do
ovolkov@0 178 results[idx] = nil
ovolkov@0 179 end
ovolkov@0 180 end
ovolkov@3 181 table.sort(results, LFGListUtil_SortSearchResultsCB);
ovolkov@0 182 end
ovolkov@0 183
ovolkov@0 184 function LFGListUtil_SortSearchResultsCB(id1, id2)
ovolkov@0 185 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(id1);
ovolkov@0 186 local id2, activityID2, name2, comment2, voiceChat2, iLvl2, age2, numBNetFriends2, numCharFriends2, numGuildMates2, isDelisted2 = C_LFGList.GetSearchResultInfo(id2);
ovolkov@0 187
ovolkov@0 188 --If one has more friends, do that one first
ovolkov@0 189 if ( numBNetFriends1 ~= numBNetFriends2 ) then
ovolkov@0 190 return numBNetFriends1 > numBNetFriends2;
ovolkov@0 191 end
ovolkov@0 192
ovolkov@0 193 if ( numCharFriends1 ~= numCharFriends2 ) then
ovolkov@0 194 return numCharFriends1 > numCharFriends2;
ovolkov@0 195 end
ovolkov@0 196
ovolkov@0 197 if ( numGuildMates1 ~= numGuildMates2 ) then
ovolkov@0 198 return numGuildMates1 > numGuildMates2;
ovolkov@0 199 end
ovolkov@0 200
ovolkov@0 201 if ( activityID1 ~= activityID2 ) then
ovolkov@0 202 return activityID1 > activityID2;
ovolkov@0 203 end
ovolkov@0 204
ovolkov@0 205 --If we aren't sorting by anything else, just go by ID
ovolkov@0 206 return id1 < id2;
ovolkov@0 207 end
ovolkov@0 208
ovolkov@0 209 function LFGPrintRawResults()
ovolkov@0 210 local totalResults, results = C_LFGList.GetSearchResults()
ovolkov@0 211 for idx = 1, totalResults do
ovolkov@0 212 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(results[idx])
ovolkov@0 213 print(id1, activityID1, C_LFGList.GetActivityInfo(activityID1), '*', name1)
ovolkov@0 214 end
ovolkov@13 215 end