annotate LFGFilter.lua @ 26:c257f5127e68

don't use "defeated" as alias to "dead" - it is already used for counter of defeated bosses
author ovolkov
date Sat, 14 Feb 2015 15:23:02 +0300
parents c8a40c59216e
children 349253bf8332
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@23 44 },
ovolkov@23 45 blackrock_foundry = {
ovolkov@23 46 lfg_dungeon_id = 847,
ovolkov@11 47 }
ovolkov@11 48 }
ovolkov@11 49
ovolkov@3 50 function LFGListSearchPanel_DoSearch(self)
ovolkov@3 51 local searchText = self.SearchBox:GetText();
ovolkov@3 52 local real_search, filter_expression = searchText:match("^([^=]-)=(.+)$")
ovolkov@3 53 if filter_expression then
ovolkov@3 54 filter_expression = filter_expression:lower()
ovolkov@3 55 self.filter_func = filter_expression_functions[filter_expression]
ovolkov@3 56 end
ovolkov@3 57 self.filter_expression = filter_expression
ovolkov@3 58
ovolkov@3 59 -- print("lfgsearch", real_search, filter_expression)
ovolkov@3 60 C_LFGList.Search(self.categoryID, real_search or searchText, self.filters, self.preferredFilters);
ovolkov@3 61 self.searching = true;
ovolkov@3 62 self.searchFailed = false;
ovolkov@3 63 self.selectedResult = nil;
ovolkov@3 64 LFGListSearchPanel_UpdateResultList(self);
ovolkov@3 65 LFGListSearchPanel_UpdateResults(self);
ovolkov@3 66 end
ovolkov@3 67
ovolkov@12 68 local localized_encounter_name_to_idx = {}
ovolkov@11 69
ovolkov@22 70 local dead = true
ovolkov@22 71
ovolkov@11 72 local function InsertEncounterStateAliases(result_env, raid_token, completed_encounters)
ovolkov@11 73 local encounter_aliases = token_to_encounter_id[raid_token]
ovolkov@11 74 if not encounter_aliases then return end
ovolkov@11 75
ovolkov@12 76 local lfg_dungeon_id = encounter_aliases.lfg_dungeon_id
ovolkov@12 77 local encounter_names = localized_encounter_name_to_idx[lfg_dungeon_id]
ovolkov@11 78 if not encounter_names then
ovolkov@11 79 encounter_names = {}
ovolkov@12 80 for idx = 1, GetLFGDungeonNumEncounters(lfg_dungeon_id) do
ovolkov@12 81 local bossName, texture, isKilled = GetLFGDungeonEncounterInfo(lfg_dungeon_id, idx)
ovolkov@12 82 encounter_names[bossName] = idx
ovolkov@12 83 end
ovolkov@12 84 localized_encounter_name_to_idx[lfg_dungeon_id] = encounter_names
ovolkov@11 85 end
ovolkov@11 86
ovolkov@11 87 for idx = 1, #completed_encounters do
ovolkov@11 88 local encounter_id = encounter_names[completed_encounters[idx]]
ovolkov@11 89 if encounter_id then
ovolkov@11 90 local aliases = encounter_aliases[encounter_id]
ovolkov@22 91 result_env["boss" .. encounter_id] = dead
ovolkov@11 92 if aliases then
ovolkov@11 93 for alias_idx = 1, #aliases do
ovolkov@22 94 result_env[aliases[alias_idx]] = dead
ovolkov@11 95 end
ovolkov@11 96 end
ovolkov@11 97 end
ovolkov@11 98 end
ovolkov@11 99 end
ovolkov@11 100
ovolkov@3 101 local result_env = {}
ovolkov@3 102 -- =highmaul and ((normal and (name:match("imp") or defeated == 6)) or (heroic and defeated == 2))
ovolkov@0 103 function LFGListUtil_SortSearchResults(results)
ovolkov@3 104 local self = LFGListFrame.SearchPanel
ovolkov@3 105 if self.filter_expression then
ovolkov@3 106 local check = self.filter_func
ovolkov@0 107 local shift_down = 0
ovolkov@0 108 local original_size = #results
ovolkov@0 109 for idx = 1, original_size do
ovolkov@3 110 local id = results[idx]
ovolkov@3 111 local _, activityID, name, comment, voiceChat, iLvl, age, numBNetFriends, numCharFriends, numGuildMates, isDelisted, leaderName, numMembers = C_LFGList.GetSearchResultInfo(id)
ovolkov@3 112 local completedEncounters = C_LFGList.GetSearchResultEncounterInfo(id)
ovolkov@3 113 local memberCounts = C_LFGList.GetSearchResultMemberCounts(id)
ovolkov@3 114
ovolkov@3 115 wipe(result_env)
ovolkov@3 116 result_env.name = name:lower()
ovolkov@3 117 result_env.comment = comment:lower()
ovolkov@3 118 result_env.ilvl = iLvl
ovolkov@3 119 -- TODO: should be calculated in meta
ovolkov@3 120 result_env.defeated = completedEncounters and #completedEncounters or 0
ovolkov@6 121 result_env.member = numMembers
ovolkov@6 122 result_env.tank = memberCounts.TANK
ovolkov@6 123 result_env.healer = memberCounts.HEALER
ovolkov@6 124 result_env.damager = memberCounts.DAMAGER + memberCounts.NOROLE
ovolkov@3 125 result_env.my_server = leaderName and not leaderName:find('-')
ovolkov@3 126
ovolkov@7 127 for idx = 1, numMembers do
ovolkov@7 128 local role, class, classLocalized = C_LFGList.GetSearchResultMemberInfo(id, idx)
ovolkov@7 129 local class_lc = class:lower()
ovolkov@7 130 local prev_count = result_env[class_lc]
ovolkov@7 131 result_env[class_lc] = prev_count and (prev_count + 1) or 0
ovolkov@7 132 end
ovolkov@7 133 for idx = 1, MAX_CLASSES do
ovolkov@7 134 local class_lc = CLASS_SORT_ORDER[idx]:lower()
ovolkov@7 135 local count = result_env[class_lc]
ovolkov@10 136 if not count then result_env[class_lc] = 0 end
ovolkov@7 137 end
ovolkov@7 138
ovolkov@11 139 local raid_token
ovolkov@3 140 if activityID == 37 then
ovolkov@11 141 raid_token = "highmaul"
ovolkov@3 142 result_env.normal = true
ovolkov@3 143 elseif activityID == 38 then
ovolkov@11 144 raid_token = "highmaul"
ovolkov@3 145 result_env.heroic = true
ovolkov@18 146 elseif activityID == 39 then
ovolkov@18 147 raid_token = "blackrock_foundry"
ovolkov@18 148 result_env.normal = true
ovolkov@18 149 elseif activityID == 40 then
ovolkov@18 150 raid_token = "blackrock_foundry"
ovolkov@18 151 result_env.heroic = true
ovolkov@3 152 end
ovolkov@3 153
ovolkov@17 154 if raid_token then
ovolkov@17 155 result_env[raid_token] = true
ovolkov@17 156 if completedEncounters then InsertEncounterStateAliases(result_env, raid_token, completedEncounters) end
ovolkov@17 157 end
ovolkov@11 158
ovolkov@22 159 result_env.dead = dead
ovolkov@11 160
ovolkov@11 161 -- dump(result_env)
ovolkov@10 162
ovolkov@10 163 for alias, original in pairs(aliases) do result_env[alias] = result_env[original] end
ovolkov@10 164
ovolkov@10 165 -- dump(result_env)
ovolkov@7 166
ovolkov@3 167 local pass
ovolkov@3 168 if check then
ovolkov@3 169 setfenv(check, result_env)
ovolkov@3 170 pass = check()
ovolkov@3 171 end
ovolkov@3 172
ovolkov@3 173 if pass then
ovolkov@0 174 if shift_down > 0 then
ovolkov@3 175 results[idx - shift_down] = id
ovolkov@0 176 end
ovolkov@0 177 else
ovolkov@0 178 shift_down = shift_down + 1
ovolkov@0 179 end
ovolkov@3 180
ovolkov@0 181 end
ovolkov@0 182 for idx = original_size - shift_down + 1, original_size do
ovolkov@0 183 results[idx] = nil
ovolkov@0 184 end
ovolkov@0 185 end
ovolkov@3 186 table.sort(results, LFGListUtil_SortSearchResultsCB);
ovolkov@0 187 end
ovolkov@0 188
ovolkov@0 189 function LFGListUtil_SortSearchResultsCB(id1, id2)
ovolkov@0 190 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(id1);
ovolkov@0 191 local id2, activityID2, name2, comment2, voiceChat2, iLvl2, age2, numBNetFriends2, numCharFriends2, numGuildMates2, isDelisted2 = C_LFGList.GetSearchResultInfo(id2);
ovolkov@0 192
ovolkov@0 193 --If one has more friends, do that one first
ovolkov@0 194 if ( numBNetFriends1 ~= numBNetFriends2 ) then
ovolkov@0 195 return numBNetFriends1 > numBNetFriends2;
ovolkov@0 196 end
ovolkov@0 197
ovolkov@0 198 if ( numCharFriends1 ~= numCharFriends2 ) then
ovolkov@0 199 return numCharFriends1 > numCharFriends2;
ovolkov@0 200 end
ovolkov@0 201
ovolkov@0 202 if ( numGuildMates1 ~= numGuildMates2 ) then
ovolkov@0 203 return numGuildMates1 > numGuildMates2;
ovolkov@0 204 end
ovolkov@0 205
ovolkov@0 206 if ( activityID1 ~= activityID2 ) then
ovolkov@0 207 return activityID1 > activityID2;
ovolkov@0 208 end
ovolkov@0 209
ovolkov@0 210 --If we aren't sorting by anything else, just go by ID
ovolkov@0 211 return id1 < id2;
ovolkov@0 212 end
ovolkov@0 213
ovolkov@0 214 function LFGPrintRawResults()
ovolkov@0 215 local totalResults, results = C_LFGList.GetSearchResults()
ovolkov@0 216 for idx = 1, totalResults do
ovolkov@0 217 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(results[idx])
ovolkov@0 218 print(id1, activityID1, C_LFGList.GetActivityInfo(activityID1), '*', name1)
ovolkov@0 219 end
ovolkov@21 220 end
ovolkov@21 221
ovolkov@21 222 function LFGPrintFindDungeon(upper_limit, pattern)
ovolkov@21 223 local lower_limit = 1
ovolkov@21 224 if not pattern then
ovolkov@21 225 lower_limit = upper_limit
ovolkov@21 226 pattern = GetLFGDungeonInfo(upper_limit)
ovolkov@21 227 end
ovolkov@21 228 for idx = lower_limit, upper_limit do
ovolkov@21 229 local name = GetLFGDungeonInfo(idx)
ovolkov@21 230 if name and name:find(pattern) then
ovolkov@21 231 print(idx, name)
ovolkov@21 232 for enc_idx = 1, GetLFGDungeonNumEncounters(idx) do
ovolkov@21 233 local bossName, texture, isKilled = GetLFGDungeonEncounterInfo(idx, enc_idx)
ovolkov@21 234 print("*", enc_idx, bossName)
ovolkov@21 235 end
ovolkov@21 236 end
ovolkov@21 237 end
ovolkov@13 238 end