try to debug another issue
[QuestHelper.git] / filter_base.lua
blobd0a8c1b35d61d70a45baa8eb8f4cf62b0d73f7f5
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 local filter_quest_raid_accessible = QH_MakeFilter("filter_quest_raid_accessible", function(obj)
143 if not QuestHelper_Pref.filter_raid_accessible then return end
145 if not obj.type_quest then return end -- yeah it's fine
146 if obj.type_quest.objectives > 0 and obj.cluster.type_quest_finish then return end -- you can turn in non-raid quests while in a raid
148 if obj.type_quest.variety == LFG_TYPE_RAID then return end -- these are always okay
149 if obj.type_quest.variety == PVP then return end -- these seem to be okay
151 if not qh_hackery_fakeraid and GetNumRaidMembers() == 0 then return end -- s'all good, we're not in a raid anyway
153 return true -- oh shit we're in a raid
154 end, {friendly_reason = QHText("FILTERED_RAID"), friendly_name = "raidaccessible"})
156 -- Delay because of beql which is a bitch.
157 QH_AddNotifier(GetTime() + 5, function ()
158 local aqw_orig = AddQuestWatch -- yoink
159 AddQuestWatch = function(...)
160 QH_Route_Filter_Rescan("filter_quest_watched")
161 return aqw_orig(...)
163 local rqw_orig = RemoveQuestWatch -- yoink
164 RemoveQuestWatch = function(...)
165 QH_Route_Filter_Rescan("filter_quest_watched")
166 return rqw_orig(...)
168 end)
171 local filter_zone = QH_MakeFilter("filter_zone", function(obj)
172 if not QuestHelper_Pref.filter_zone then return end
174 return obj.loc.p ~= QuestHelper.i
175 end, {friendly_reason = QHText("FILTERED_ZONE"), friendly_name = "zone"})
177 local filter_blocked = QH_MakeFilter("filter_blocked", function(obj, blocked)
178 if not QuestHelper_Pref.filter_blocked then return end
180 return blocked
181 end, {friendly_reason = QHText("FILTERED_BLOCKED"), friendly_name = "blocked"})
183 QH_Route_RegisterFilter(filter_quest_level, "filter_quest_level")
184 QH_Route_RegisterFilter(filter_quest_done, "filter_quest_done")
185 QH_Route_RegisterFilter(filter_quest_watched, "filter_quest_watched")
186 QH_Route_RegisterFilter(filter_quest_group, "filter_quest_group")
187 QH_Route_RegisterFilter(filter_quest_wintergrasp, "filter_quest_wintergrasp")
188 QH_Route_RegisterFilter(filter_quest_raid_accessible, "filter_quest_raid_accessible")
189 QH_Route_RegisterFilter(filter_zone, "filter_zone")
190 QH_Route_RegisterFilter(filter_blocked, "filter_blocked")
195 function qh_hackery_wackyland_enable()
196 QH_WACKYLAND = true
197 local filter_wackyland = QH_MakeFilter("filter_wackyland", function(obj)
198 return math.random() < 0.5
199 end, {friendly_reason = "wacky", friendly_name = "wacky"})
200 QH_Route_RegisterFilter(filter_wackyland, "filter_wackyland")