-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoAdd.lua
99 lines (78 loc) · 2.58 KB
/
AutoAdd.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
local myname, ns = ...
local counters = setmetatable({}, {__index = function(t,i) return 0 end})
local buffed
local function GetFollowerWithBuff(mechanic, level)
local follower
local counter = counters[mechanic]
counters[mechanic] = counters[mechanic] - 1
for guid,buffs in pairs(buffed) do
if level == 100 or C_Garrison.GetFollowerLevel(guid) == level then
for i,buff in pairs(buffs) do
if buff.name == mechanic then
if ns.IsFollowerAvailable(guid, true) then
if counter == 0 then return end
counter = counter - 1
follower = guid
end
end
end
end
end
-- Remove buffs that a double-matched follower covers so we don't add
-- another follower that is not needed
if follower then
for i,buff in pairs(buffed[follower]) do
if buff.name ~= mechanic then
counters[buff.name] = counters[buff.name] - 1
end
end
end
return follower
end
local function EligibleFollower(follower, mission_level)
if not follower.isCollected then return false end
if follower.status then return false end
return follower.level < 100 and follower.level >= mission_level
end
local followers
local function NumPotentialFollowers(mission_level)
local count = 0
for _,follower in pairs(followers) do
if EligibleFollower(follower, mission_level) then count = count + 1 end
end
return count
end
local dirty = false
local MissionPage = GarrisonMissionFrame.MissionTab.MissionPage
hooksecurefunc(GarrisonMissionFrame, "ShowMission", function() dirty = true end)
hooksecurefunc(GarrisonMissionFrame.FollowerList, "UpdateData", function(self)
if not dirty then return end
dirty = false
local mission = MissionPage.missionInfo
wipe(counters)
local needed = mission.numFollowers
local _, _, _, _, _, _, _, missionbosses = C_Garrison.GetMissionInfo(mission.missionID)
buffed = C_Garrison.GetBuffedFollowersForMission(mission.missionID, false)
for _,boss in pairs(missionbosses) do
for _,mechanic in pairs(boss.mechanics) do
counters[mechanic.name] = counters[mechanic.name] + 1
end
end
for _,boss in pairs(missionbosses) do
for _,mechanic in pairs(boss.mechanics) do
local guid = GetFollowerWithBuff(mechanic.name, mission.level)
if guid then
needed = needed - 1
MissionPage:AddFollower(guid)
end
end
end
if needed == 0 or mission.level == 100 then return end
followers = C_Garrison.GetFollowers(LE_FOLLOWER_TYPE_GARRISON_6_0)
if NumPotentialFollowers(mission.level) > needed then return end
for _,follower in pairs(followers) do
if EligibleFollower(follower, mission.level) then
MissionPage:AddFollower(follower.followerID)
end
end
end)