annotate LFGFilter.lua @ 36:c68c0833cb6d

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