Merge branch 'master' into translations
[QuestHelper.git] / filter_base.lua
blobad026dd1b15109804b42bcd993e9df78e3accdc0
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 == DUNGEON_DIFFICULTY2 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 if obj.loc.p == 74 and obj.type_quest.variety == PVP then return true end
123 end, {friendly_reason = QHText("FILTERED_WINTERGRASP"), friendly_name = "wintergrasp"})
125 local filter_quest_done = QH_MakeFilter("filter_quest_done", function(obj)
126 if not QuestHelper_Pref.filter_done then return end
128 if not obj.type_quest then return end -- yeah it's fine
129 if not obj.type_quest.done then return true end -- bzzt
130 end, {friendly_reason = QHText("FILTERED_COMPLETE"), friendly_name = "done"})
132 local filter_quest_watched = QH_MakeFilter("filter_quest_watched", function(obj)
133 if not QuestHelper_Pref.filter_watched then return end
135 if not obj.type_quest or not obj.type_quest.index then return end
137 return not IsQuestWatched(obj.type_quest.index)
138 end, {friendly_reason = QHText("FILTERED_UNWATCHED"), friendly_name = "watched"})
140 -- Delay because of beql which is a bitch.
141 QH_AddNotifier(GetTime() + 5, function ()
142 local aqw_orig = AddQuestWatch -- yoink
143 AddQuestWatch = function(...)
144 QH_Route_Filter_Rescan("filter_quest_watched")
145 return aqw_orig(...)
147 local rqw_orig = RemoveQuestWatch -- yoink
148 RemoveQuestWatch = function(...)
149 QH_Route_Filter_Rescan("filter_quest_watched")
150 return rqw_orig(...)
152 end)
155 local filter_zone = QH_MakeFilter("filter_zone", function(obj)
156 if not QuestHelper_Pref.filter_zone then return end
158 return obj.loc.p ~= QuestHelper.i
159 end, {friendly_reason = QHText("FILTERED_ZONE"), friendly_name = "zone"})
161 local filter_blocked = QH_MakeFilter("filter_blocked", function(obj, blocked)
162 if not QuestHelper_Pref.filter_blocked then return end
164 return blocked
165 end, {friendly_reason = QHText("FILTERED_BLOCKED"), friendly_name = "blocked"})
167 QH_Route_RegisterFilter(filter_quest_level, "filter_quest_level")
168 QH_Route_RegisterFilter(filter_quest_done, "filter_quest_done")
169 QH_Route_RegisterFilter(filter_quest_watched, "filter_quest_watched")
170 QH_Route_RegisterFilter(filter_quest_group, "filter_quest_group")
171 QH_Route_RegisterFilter(filter_quest_wintergrasp, "filter_quest_wintergrasp")
172 QH_Route_RegisterFilter(filter_zone, "filter_zone")
173 QH_Route_RegisterFilter(filter_blocked, "filter_blocked")
178 function QH_WACKYLAND_ENABLE()
179 QH_WACKYLAND = true
180 local filter_wackyland = QH_MakeFilter("filter_wackyland", function(obj)
181 return math.random() < 0.5
182 end, {friendly_reason = "wacky", friendly_name = "wacky"})
183 QH_Route_RegisterFilter(filter_wackyland, "filter_wackyland")