annotate LFGFilter.lua @ 30:1ff8e590959d

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