maybe this fixes the graph issue
[QuestHelper.git] / filter_base.lua
blob2dc28a57fc88a52535c1b741099b479a4631b0c1
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
10 if GetNumRaidMembers() > 0 then
11 avg_level = 0
12 count = 0
13 -- we is in a raid
14 for i = 1, 40 do
15 local liv = UnitLevel(string.format("raid%d", i))
16 if liv >= 1 then
17 avg_level = avg_level + liv
18 count = count + 1
19 end
20 end
21 elseif GetNumPartyMembers() > 0 then
22 -- we is in a party
23 for i = 1, 4 do
24 local liv = UnitLevel(string.format("party%d", i))
25 if liv >= 1 then
26 avg_level = avg_level + liv
27 count = count + 1
28 end
29 end
30 end
32 if count == 0 then -- welp
33 QuestHelper:TextOut("This should never, ever happen. Please tell Zorba about it!")
34 QuestHelper: Assert(false)
35 avg_level = UnitLevel("player")
36 count = 1
37 end
39 avg_level = avg_level / count
40 end
42 --[[
44 2 +2
45 3 +2
46 4 +2
47 5 +2 (+2 if dungeonflagged)
48 +6 and on: +15 (total of +25, the goal here is that, with default settings, lv60 raids shouldn't show up at lv80)
51 local function VirtualLevel(avg_level, count, dungeonflag)
52 QuestHelper: Assert(avg_level)
53 if dungeonflag == nil and count == 5 then dungeonflag = true end -- "nil" is kind of "default"
54 if count > 5 then dungeonflag = true end
56 if count <= 5 then avg_level = avg_level + 2 * count - 2 end
57 if count >= 5 and dungeonflag then avg_level = avg_level + 2 end
58 if count > 5 then avg_level = avg_level + 15 end
60 return avg_level
61 end
63 local filter_quest_level = QH_MakeFilter("filter_quest_level", function(obj)
64 if not QuestHelper_Pref.filter_level then return end
66 if not obj.type_quest then return end -- yeah it's fine
68 if obj.type_quest.objectives > 0 and obj.cluster.type_quest_finish then return end
70 local qtx
71 if obj.type_quest.variety == GROUP then
72 if obj.type_quest.groupsize > 0 then
73 qtx = VirtualLevel(obj.type_quest.level, obj.type_quest.groupsize, false)
74 else
75 qtx = VirtualLevel(obj.type_quest.level, 5, false) -- meh
76 end
77 elseif obj.type_quest.variety == LFG_TYPE_DUNGEON or obj.type_quest.variety == DUNGEON_DIFFICULTY2 then
78 qtx = VirtualLevel(obj.type_quest.level, 5, true)
79 elseif obj.type_quest.variety == LFG_TYPE_RAID then
80 qtx = VirtualLevel(obj.type_quest.level, 25, true)
81 else
82 qtx = VirtualLevel(obj.type_quest.level, 1, false)
83 end
85 if qtx > VirtualLevel(avg_level, count) + QuestHelper_Pref.level then return true end -- bzzt
86 end, {friendly_reason = QHText("FILTERED_LEVEL"), friendly_name = "level"})
88 local filter_quest_done = QH_MakeFilter("filter_quest_done", function(obj)
89 if not QuestHelper_Pref.filter_done then return end
91 if not obj.type_quest then return end -- yeah it's fine
92 if not obj.type_quest.done then return true end -- bzzt
93 end, {friendly_reason = QHText("FILTERED_COMPLETE"), friendly_name = "done"})
95 local filter_quest_watched = QH_MakeFilter("filter_quest_watched", function(obj)
96 if not QuestHelper_Pref.filter_watched then return end
98 if not obj.type_quest then return end
100 return not IsQuestWatched(obj.type_quest.index)
101 end, {friendly_reason = QHText("FILTERED_UNWATCHED"), friendly_name = "watched"})
103 -- Delay because of beql which is a bitch.
104 QH_AddNotifier(GetTime() + 5, function ()
105 local aqw_orig = AddQuestWatch -- yoink
106 AddQuestWatch = function(...)
107 QH_Route_Filter_Rescan("filter_quest_watched")
108 return aqw_orig(...)
110 local rqw_orig = RemoveQuestWatch -- yoink
111 RemoveQuestWatch = function(...)
112 QH_Route_Filter_Rescan("filter_quest_watched")
113 return rqw_orig(...)
115 end)
118 local filter_zone = QH_MakeFilter("filter_zone", function(obj)
119 if not QuestHelper_Pref.filter_zone then return end
121 return obj.loc.p ~= QuestHelper.i
122 end, {friendly_reason = QHText("FILTERED_ZONE"), friendly_name = "zone"})
124 local filter_blocked = QH_MakeFilter("filter_blocked", function(obj, blocked)
125 if not QuestHelper_Pref.filter_blocked then return end
127 return blocked
128 end, {friendly_reason = QHText("FILTERED_BLOCKED"), friendly_name = "blocked"})
130 QH_Route_RegisterFilter(filter_quest_level, "filter_quest_level")
131 QH_Route_RegisterFilter(filter_quest_done, "filter_quest_done")
132 QH_Route_RegisterFilter(filter_quest_watched, "filter_quest_watched")
133 QH_Route_RegisterFilter(filter_zone, "filter_zone")
134 QH_Route_RegisterFilter(filter_blocked, "filter_blocked")
139 function QH_WACKYLAND_ENABLE()
140 QH_WACKYLAND = true
141 local filter_wackyland = QH_MakeFilter("filter_wackyland", function(obj)
142 return math.random() < 0.5
143 end, {friendly_reason = "wacky", friendly_name = "wacky"})
144 QH_Route_RegisterFilter(filter_wackyland, "filter_wackyland")