annotate LFGFilter.lua @ 43:324bcc47f37a

remove debug
author rowaasr13
date Fri, 27 Jan 2017 10:34:43 +0300
parents bc6794e51c97
children 82db5d724aa5
rev   line source
ovolkov@29 1 -- [AUTOLOCAL START]
ovolkov@29 2 local CLASS_SORT_ORDER = CLASS_SORT_ORDER
ovolkov@29 3 local C_LFGList = C_LFGList
ovolkov@29 4 local GetLFGDungeonEncounterInfo = GetLFGDungeonEncounterInfo
ovolkov@29 5 local GetLFGDungeonNumEncounters = GetLFGDungeonNumEncounters
ovolkov@29 6 local MAX_CLASSES = MAX_CLASSES
ovolkov@7 7 local dump = DevTools_Dump
ovolkov@29 8 local match = string.match
ovolkov@29 9 local pairs = pairs
ovolkov@29 10 local setfenv = setfenv
ovolkov@29 11 local wipe = wipe
ovolkov@29 12 -- [AUTOLOCAL END]
ovolkov@29 13
ovolkov@3 14 LFGListFrame.SearchPanel.SearchBox:SetMaxLetters(2048)
ovolkov@0 15
ovolkov@3 16 local filter_expression_functions = setmetatable({}, {
ovolkov@3 17 __mode = "k",
ovolkov@3 18 __index = function(t, key)
ovolkov@3 19 local func, error = loadstring("return " .. key)
ovolkov@3 20 if error then print("Error in LFG filter expression:\n", error) end
ovolkov@3 21 t[key] = func
ovolkov@3 22 return func
ovolkov@3 23 end
ovolkov@3 24 })
ovolkov@3 25
ovolkov@10 26 local aliases = {
ovolkov@31 27 voice_chat = "voice",
ovolkov@18 28 hm = "highmaul",
ovolkov@18 29 brf = "blackrock_foundry",
ovolkov@18 30 blackrockfoundry = "blackrock_foundry",
ovolkov@36 31 hellfirecitadel = "hellfire_citadel",
ovolkov@36 32 hellfire = "hellfire_citadel",
ovolkov@36 33 hfc = "hellfire_citadel",
rowaasr13@42 34 en = "emerald_nightmare",
rowaasr13@42 35 tov = "trial_of_valor",
ovolkov@18 36 healers = "healer",
ovolkov@18 37 members = "member",
ovolkov@18 38 tanks = "tank",
ovolkov@18 39 damagers = "damager",
ovolkov@18 40 damage = "damager",
ovolkov@18 41 plates = "plate",
ovolkov@18 42 mails = "mail",
ovolkov@18 43 leathers = "leather",
ovolkov@18 44 cloths = "cloth",
ovolkov@18 45 clothies = "cloth",
ovolkov@10 46 }
ovolkov@10 47 for idx = 1, MAX_CLASSES do
ovolkov@10 48 local class_lc = CLASS_SORT_ORDER[idx]:lower()
ovolkov@10 49 aliases[class_lc .. "s"] = class_lc
ovolkov@10 50 end
ovolkov@10 51
ovolkov@11 52 local token_to_encounter_id = {
ovolkov@11 53 highmaul = {
ovolkov@12 54 lfg_dungeon_id = 849,
ovolkov@12 55 { "kargath", "bladefist", "kargath_bladefist" },
ovolkov@12 56 { "butcher", "the_butcher" },
ovolkov@12 57 { "tectus" },
ovolkov@12 58 { "brackenspore", "bracken" },
ovolkov@12 59 { "twin_orgon", "twins" },
ovolkov@12 60 { "koragh", "breaker" },
ovolkov@12 61 { "imperator", "margok" },
ovolkov@23 62 },
ovolkov@23 63 blackrock_foundry = {
ovolkov@30 64 lfg_dungeon_id = 847,
ovolkov@30 65 { "oregorger", "oreg" },
ovolkov@30 66 { "gruul" },
ovolkov@30 67 { "hansgar", "franzok", "hans", "franz", "hans_and_franz", "twins" },
ovolkov@30 68 { "beastlord", "darmac" },
ovolkov@30 69 { "flamebender", "kagraz" },
ovolkov@30 70 { "operator", "thogar" },
ovolkov@30 71 { "blast_furnace", "bf", "furnace", "blast" },
ovolkov@30 72 { "kromog" },
ovolkov@30 73 { "iron_maidens", "im", "maidens" },
ovolkov@30 74 { "blackhand" },
ovolkov@11 75 }
ovolkov@11 76 }
ovolkov@11 77
ovolkov@35 78 -- Don't forget to update it when according to Blizzard code
ovolkov@3 79 function LFGListSearchPanel_DoSearch(self)
ovolkov@3 80 local searchText = self.SearchBox:GetText();
ovolkov@3 81 local real_search, filter_expression = searchText:match("^([^=]-)=(.+)$")
ovolkov@3 82 if filter_expression then
ovolkov@3 83 filter_expression = filter_expression:lower()
ovolkov@3 84 self.filter_func = filter_expression_functions[filter_expression]
ovolkov@3 85 end
ovolkov@3 86 self.filter_expression = filter_expression
ovolkov@35 87
ovolkov@35 88 local languages = C_LFGList.GetLanguageSearchFilter();
ovolkov@35 89 C_LFGList.Search(self.categoryID, real_search or searchText, self.filters, self.preferredFilters, languages);
ovolkov@3 90 self.searching = true;
ovolkov@3 91 self.searchFailed = false;
ovolkov@3 92 self.selectedResult = nil;
ovolkov@3 93 LFGListSearchPanel_UpdateResultList(self);
ovolkov@3 94 LFGListSearchPanel_UpdateResults(self);
ovolkov@3 95 end
ovolkov@3 96
ovolkov@12 97 local localized_encounter_name_to_idx = {}
ovolkov@11 98
ovolkov@22 99 local dead = true
ovolkov@22 100
ovolkov@11 101 local function InsertEncounterStateAliases(result_env, raid_token, completed_encounters)
ovolkov@11 102 local encounter_aliases = token_to_encounter_id[raid_token]
ovolkov@11 103 if not encounter_aliases then return end
ovolkov@11 104
ovolkov@12 105 local lfg_dungeon_id = encounter_aliases.lfg_dungeon_id
ovolkov@12 106 local encounter_names = localized_encounter_name_to_idx[lfg_dungeon_id]
ovolkov@11 107 if not encounter_names then
ovolkov@11 108 encounter_names = {}
ovolkov@12 109 for idx = 1, GetLFGDungeonNumEncounters(lfg_dungeon_id) do
ovolkov@12 110 local bossName, texture, isKilled = GetLFGDungeonEncounterInfo(lfg_dungeon_id, idx)
ovolkov@12 111 encounter_names[bossName] = idx
ovolkov@12 112 end
ovolkov@12 113 localized_encounter_name_to_idx[lfg_dungeon_id] = encounter_names
ovolkov@11 114 end
ovolkov@11 115
ovolkov@11 116 for idx = 1, #completed_encounters do
ovolkov@11 117 local encounter_id = encounter_names[completed_encounters[idx]]
ovolkov@11 118 if encounter_id then
ovolkov@11 119 local aliases = encounter_aliases[encounter_id]
ovolkov@22 120 result_env["boss" .. encounter_id] = dead
ovolkov@11 121 if aliases then
ovolkov@11 122 for alias_idx = 1, #aliases do
ovolkov@22 123 result_env[aliases[alias_idx]] = dead
ovolkov@11 124 end
ovolkov@11 125 end
ovolkov@11 126 end
ovolkov@11 127 end
ovolkov@11 128 end
ovolkov@11 129
ovolkov@3 130 local result_env = {}
ovolkov@3 131 -- =highmaul and ((normal and (name:match("imp") or defeated == 6)) or (heroic and defeated == 2))
ovolkov@0 132 function LFGListUtil_SortSearchResults(results)
ovolkov@3 133 local self = LFGListFrame.SearchPanel
ovolkov@3 134 if self.filter_expression then
ovolkov@3 135 local check = self.filter_func
ovolkov@0 136 local shift_down = 0
ovolkov@0 137 local original_size = #results
ovolkov@0 138 for idx = 1, original_size do
ovolkov@3 139 local id = results[idx]
rowaasr13@41 140 local _, activityID, name, comment, voiceChat, iLvl, honorLevel, age, numBNetFriends, numCharFriends, numGuildMates, isDelisted, leaderName, numMembers = C_LFGList.GetSearchResultInfo(id)
ovolkov@3 141 local completedEncounters = C_LFGList.GetSearchResultEncounterInfo(id)
ovolkov@3 142 local memberCounts = C_LFGList.GetSearchResultMemberCounts(id)
ovolkov@3 143
ovolkov@3 144 wipe(result_env)
ovolkov@3 145 result_env.name = name:lower()
ovolkov@3 146 result_env.comment = comment:lower()
ovolkov@3 147 result_env.ilvl = iLvl
ovolkov@3 148 -- TODO: should be calculated in meta
ovolkov@3 149 result_env.defeated = completedEncounters and #completedEncounters or 0
ovolkov@6 150 result_env.member = numMembers
ovolkov@6 151 result_env.tank = memberCounts.TANK
ovolkov@6 152 result_env.healer = memberCounts.HEALER
ovolkov@6 153 result_env.damager = memberCounts.DAMAGER + memberCounts.NOROLE
ovolkov@3 154 result_env.my_server = leaderName and not leaderName:find('-')
ovolkov@31 155 if voiceChat and voiceChat ~= "" then
ovolkov@31 156 result_env.voice = voiceChat
ovolkov@31 157 end
ovolkov@3 158
ovolkov@7 159 for idx = 1, numMembers do
ovolkov@7 160 local role, class, classLocalized = C_LFGList.GetSearchResultMemberInfo(id, idx)
ovolkov@7 161 local class_lc = class:lower()
ovolkov@7 162 local prev_count = result_env[class_lc]
ovolkov@7 163 result_env[class_lc] = prev_count and (prev_count + 1) or 0
ovolkov@7 164 end
ovolkov@7 165 for idx = 1, MAX_CLASSES do
ovolkov@7 166 local class_lc = CLASS_SORT_ORDER[idx]:lower()
ovolkov@7 167 local count = result_env[class_lc]
ovolkov@10 168 if not count then result_env[class_lc] = 0 end
ovolkov@7 169 end
ovolkov@7 170
ovolkov@11 171 local raid_token
ovolkov@3 172 if activityID == 37 then
ovolkov@11 173 raid_token = "highmaul"
ovolkov@3 174 result_env.normal = true
ovolkov@3 175 elseif activityID == 38 then
ovolkov@11 176 raid_token = "highmaul"
ovolkov@3 177 result_env.heroic = true
ovolkov@18 178 elseif activityID == 39 then
ovolkov@18 179 raid_token = "blackrock_foundry"
ovolkov@18 180 result_env.normal = true
ovolkov@18 181 elseif activityID == 40 then
ovolkov@18 182 raid_token = "blackrock_foundry"
ovolkov@18 183 result_env.heroic = true
ovolkov@36 184 elseif activityID == 409 then
ovolkov@36 185 raid_token = "hellfire_citadel"
ovolkov@36 186 result_env.normal = true
ovolkov@36 187 elseif activityID == 410 then
ovolkov@36 188 raid_token = "hellfire_citadel"
ovolkov@36 189 result_env.heroic = true
rowaasr13@42 190 elseif activityID == 413 then
rowaasr13@42 191 raid_token = "emerald_nightmare"
rowaasr13@42 192 result_env.normal = true
rowaasr13@42 193 elseif activityID == 414 then
rowaasr13@42 194 raid_token = "emerald_nightmare"
rowaasr13@42 195 result_env.heroic = true
rowaasr13@42 196 elseif activityID == 456 then
rowaasr13@42 197 raid_token = "trial_of_valor"
rowaasr13@42 198 result_env.normal = true
rowaasr13@42 199 elseif activityID == 457 then
rowaasr13@42 200 raid_token = "trial_of_valor"
rowaasr13@42 201 result_env.heroic = true
ovolkov@3 202 end
ovolkov@3 203
ovolkov@17 204 if raid_token then
ovolkov@17 205 result_env[raid_token] = true
ovolkov@17 206 if completedEncounters then InsertEncounterStateAliases(result_env, raid_token, completedEncounters) end
ovolkov@17 207 end
ovolkov@11 208
ovolkov@22 209 result_env.dead = dead
ovolkov@11 210
ovolkov@11 211 -- dump(result_env)
ovolkov@10 212
ovolkov@10 213 for alias, original in pairs(aliases) do result_env[alias] = result_env[original] end
ovolkov@10 214
ovolkov@37 215 -- dump(result_env)
ovolkov@7 216
ovolkov@3 217 local pass
ovolkov@3 218 if check then
ovolkov@3 219 setfenv(check, result_env)
ovolkov@3 220 pass = check()
ovolkov@3 221 end
ovolkov@3 222
ovolkov@3 223 if pass then
ovolkov@0 224 if shift_down > 0 then
ovolkov@3 225 results[idx - shift_down] = id
ovolkov@0 226 end
ovolkov@0 227 else
ovolkov@0 228 shift_down = shift_down + 1
ovolkov@0 229 end
ovolkov@3 230
ovolkov@0 231 end
ovolkov@0 232 for idx = original_size - shift_down + 1, original_size do
ovolkov@0 233 results[idx] = nil
ovolkov@0 234 end
ovolkov@0 235 end
ovolkov@3 236 table.sort(results, LFGListUtil_SortSearchResultsCB);
ovolkov@0 237 end
ovolkov@0 238
ovolkov@0 239 function LFGListUtil_SortSearchResultsCB(id1, id2)
ovolkov@0 240 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(id1);
ovolkov@0 241 local id2, activityID2, name2, comment2, voiceChat2, iLvl2, age2, numBNetFriends2, numCharFriends2, numGuildMates2, isDelisted2 = C_LFGList.GetSearchResultInfo(id2);
ovolkov@0 242
ovolkov@0 243 --If one has more friends, do that one first
ovolkov@0 244 if ( numBNetFriends1 ~= numBNetFriends2 ) then
ovolkov@0 245 return numBNetFriends1 > numBNetFriends2;
ovolkov@0 246 end
ovolkov@0 247
ovolkov@0 248 if ( numCharFriends1 ~= numCharFriends2 ) then
ovolkov@0 249 return numCharFriends1 > numCharFriends2;
ovolkov@0 250 end
ovolkov@0 251
ovolkov@0 252 if ( numGuildMates1 ~= numGuildMates2 ) then
ovolkov@0 253 return numGuildMates1 > numGuildMates2;
ovolkov@0 254 end
ovolkov@0 255
ovolkov@0 256 if ( activityID1 ~= activityID2 ) then
ovolkov@0 257 return activityID1 > activityID2;
ovolkov@0 258 end
ovolkov@0 259
ovolkov@0 260 --If we aren't sorting by anything else, just go by ID
ovolkov@0 261 return id1 < id2;
ovolkov@0 262 end
ovolkov@0 263
ovolkov@0 264 function LFGPrintRawResults()
ovolkov@0 265 local totalResults, results = C_LFGList.GetSearchResults()
ovolkov@0 266 for idx = 1, totalResults do
ovolkov@0 267 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(results[idx])
ovolkov@0 268 print(id1, activityID1, C_LFGList.GetActivityInfo(activityID1), '*', name1)
ovolkov@0 269 end
ovolkov@21 270 end
ovolkov@21 271
ovolkov@21 272 function LFGPrintFindDungeon(upper_limit, pattern)
ovolkov@21 273 local lower_limit = 1
ovolkov@21 274 if not pattern then
ovolkov@37 275 lower_limit = upper_limit
ovolkov@21 276 pattern = GetLFGDungeonInfo(upper_limit)
ovolkov@21 277 end
ovolkov@21 278 for idx = lower_limit, upper_limit do
ovolkov@21 279 local name = GetLFGDungeonInfo(idx)
ovolkov@21 280 if name and name:find(pattern) then
ovolkov@21 281 print(idx, name)
ovolkov@21 282 for enc_idx = 1, GetLFGDungeonNumEncounters(idx) do
ovolkov@21 283 local bossName, texture, isKilled = GetLFGDungeonEncounterInfo(idx, enc_idx)
ovolkov@21 284 print("*", enc_idx, bossName)
ovolkov@21 285 end
ovolkov@21 286 end
ovolkov@21 287 end
ovolkov@13 288 end