Merge branch 'master' of git://cams.pavlovian.net/questhelper
[QuestHelper.git] / filter_base.lua
blob9f30993d733c7341b9cfec32275d787a27c41a68
1 QuestHelper_File["filter_base.lua"] = "Development Version"
2 QuestHelper_Loadtime["filter_base.lua"] = GetTime()
4 local avg_level = UnitLevel("player")
5 local count = 1
7 function QH_Filter_Group_Sync()
8 avg_level = UnitLevel("player")
9 count = 1
11 if not QuestHelper_Pref.solo then
12 if GetNumRaidMembers() > 0 then
13 avg_level = 0
14 count = 0
15 -- we is in a raid
16 for i = 1, 40 do
17 local liv = UnitLevel(string.format("raid%d", i))
18 if liv >= 1 then
19 avg_level = avg_level + liv
20 count = count + 1
21 end
22 end
23 elseif GetNumPartyMembers() > 0 then
24 -- we is in a party
25 for i = 1, 4 do
26 local liv = UnitLevel(string.format("party%d", i))
27 if liv >= 1 then
28 avg_level = avg_level + liv
29 count = count + 1
30 end
31 end
32 end
33 end
35 if count == 0 then -- welp
36 QuestHelper:TextOut("This should never, ever happen. Please tell Zorba about it!")
37 QuestHelper: Assert(false)
38 avg_level = UnitLevel("player")
39 count = 1
40 end
42 avg_level = avg_level / count
43 end
45 --[[
47 2 +2
48 3 +2
49 4 +2
50 5 +2 (+2 if dungeonflagged)
51 +6 and on: +15 (total of +25, the goal here is that, with default settings, lv60 raids shouldn't show up at lv80)
54 local function VirtualLevel(avg_level, count, dungeonflag)
55 QuestHelper: Assert(avg_level)
56 if dungeonflag == nil and count == 5 then dungeonflag = true end -- "nil" is kind of "default"
57 if count > 5 then dungeonflag = true end
59 if count <= 5 then avg_level = avg_level + 2 * count - 2 end
60 if count >= 5 and dungeonflag then avg_level = avg_level + 2 end
61 if count > 5 then avg_level = avg_level + 15 end
63 return avg_level
64 end
66 local filter_quest_level = QH_MakeFilter("filter_quest_level", function(obj)
67 if not QuestHelper_Pref.filter_level then return end
69 if not obj.type_quest then return end -- yeah it's fine
71 if obj.type_quest.objectives > 0 and obj.cluster.type_quest_finish then return end
73 local qtx
74 if obj.type_quest.variety == GROUP then
75 if obj.type_quest.groupsize > 0 then
76 qtx = VirtualLevel(obj.type_quest.level, obj.type_quest.groupsize, false)
77 else
78 qtx = VirtualLevel(obj.type_quest.level, 5, false) -- meh
79 end
80 elseif obj.type_quest.variety == LFG_TYPE_DUNGEON or obj.type_quest.variety == DUNGEON_DIFFICULTY2 then
81 qtx = VirtualLevel(obj.type_quest.level, 5, true)
82 elseif obj.type_quest.variety == LFG_TYPE_RAID then
83 qtx = VirtualLevel(obj.type_quest.level, 25, true)
84 else
85 qtx = VirtualLevel(obj.type_quest.level, 1, false)
86 end
88 if qtx > VirtualLevel(avg_level, count) + QuestHelper_Pref.level then return true end -- bzzt
89 end, {friendly_reason = QHText("FILTERED_LEVEL"), friendly_name = "level"})
91 local filter_quest_group = QH_MakeFilter("filter_quest_group", function(obj)
92 if not QuestHelper_Pref.filter_group then return end
94 if not obj.type_quest then return end -- yeah it's fine
95 if obj.type_quest.objectives > 0 and obj.cluster.type_quest_finish then return end
96 if count > 1 and not QuestHelper_Pref.solo then return end
98 local expected_players = 1
99 if obj.type_quest.variety == GROUP then
100 if obj.type_quest.groupsize > 0 then
101 expected_players = obj.type_quest.groupsize
102 else
103 expected_players = 5
105 elseif obj.type_quest.variety == LFG_TYPE_DUNGEON or obj.type_quest.variety == ITEM_HEROIC then
106 expected_players = 5
107 elseif obj.type_quest.variety == LFG_TYPE_RAID then
108 expected_players = 10
111 if expected_players > QuestHelper_Pref.filter_group_param then return true end
112 end, {friendly_reason = QHText("FILTERED_GROUP"), friendly_name = "group"})
114 local filter_quest_wintergrasp = QH_MakeFilter("filter_quest_wintergrasp", function(obj)
115 if not QuestHelper_Pref.filter_wintergrasp then return end
117 if not obj.type_quest then return end
118 if obj.type_quest.objectives > 0 and obj.cluster.type_quest_finish then return end
120 if QuestHelper.collect_rc and QuestHelper.collect_rz and QuestHelper_IndexLookup[QuestHelper.collect_rc] and QuestHelper_IndexLookup[QuestHelper.collect_rc][QuestHelper.collect_rz] == 74 then return end
122 --print(obj.loc.p, obj.type_quest.variety, PVP, obj.type_quest.variety == PVP, obj.loc.p == 74 and obj.type_quest.variety == PVP)
124 if obj.loc.p == 74 and obj.type_quest.variety == PVP then return true end
125 end, {friendly_reason = QHText("FILTERED_WINTERGRASP"), friendly_name = "wintergrasp"})
127 local filter_quest_done = QH_MakeFilter("filter_quest_done", function(obj)
128 if not QuestHelper_Pref.filter_done then return end
130 if not obj.type_quest then return end -- yeah it's fine
131 if not obj.type_quest.done then return true end -- bzzt
132 end, {friendly_reason = QHText("FILTERED_COMPLETE"), friendly_name = "done"})
134 local filter_quest_watched = QH_MakeFilter("filter_quest_watched", function(obj)
135 if not QuestHelper_Pref.filter_watched then return end
137 if not obj.type_quest or not obj.type_quest.index then return end
139 return not IsQuestWatched(obj.type_quest.index)
140 end, {friendly_reason = QHText("FILTERED_UNWATCHED"), friendly_name = "watched"})
142 -- Delay because of beql which is a bitch.
143 QH_AddNotifier(GetTime() + 5, function ()
144 local aqw_orig = AddQuestWatch -- yoink
145 AddQuestWatch = function(...)
146 QH_Route_Filter_Rescan("filter_quest_watched")
147 return aqw_orig(...)
149 local rqw_orig = RemoveQuestWatch -- yoink
150 RemoveQuestWatch = function(...)
151 QH_Route_Filter_Rescan("filter_quest_watched")
152 return rqw_orig(...)
154 end)
157 local filter_zone = QH_MakeFilter("filter_zone", function(obj)
158 if not QuestHelper_Pref.filter_zone then return end
160 return obj.loc.p ~= QuestHelper.i
161 end, {friendly_reason = QHText("FILTERED_ZONE"), friendly_name = "zone"})
163 local filter_blocked = QH_MakeFilter("filter_blocked", function(obj, blocked)
164 if not QuestHelper_Pref.filter_blocked then return end
166 return blocked
167 end, {friendly_reason = QHText("FILTERED_BLOCKED"), friendly_name = "blocked"})
169 QH_Route_RegisterFilter(filter_quest_level, "filter_quest_level")
170 QH_Route_RegisterFilter(filter_quest_done, "filter_quest_done")
171 QH_Route_RegisterFilter(filter_quest_watched, "filter_quest_watched")
172 QH_Route_RegisterFilter(filter_quest_group, "filter_quest_group")
173 QH_Route_RegisterFilter(filter_quest_wintergrasp, "filter_quest_wintergrasp")
174 QH_Route_RegisterFilter(filter_zone, "filter_zone")
175 QH_Route_RegisterFilter(filter_blocked, "filter_blocked")
180 function QH_WACKYLAND_ENABLE()
181 QH_WACKYLAND = true
182 local filter_wackyland = QH_MakeFilter("filter_wackyland", function(obj)
183 return math.random() < 0.5
184 end, {friendly_reason = "wacky", friendly_name = "wacky"})
185 QH_Route_RegisterFilter(filter_wackyland, "filter_wackyland")