-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbrLooting.lua
More file actions
116 lines (98 loc) · 2.94 KB
/
brLooting.lua
File metadata and controls
116 lines (98 loc) · 2.94 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---@type _,br,_
local _,br,_ = ...
---@type br.Logging
local Log = br.Logging
---@class br.Looting
---@field Active boolean Whether the looting module is active
---@field Loot fun(self: br.Looting) Performs looting actions
local Looting = {}
Looting.Active = false
Looting.Target = nil
Looting.TimeoutTime = GetTime()
Looting.States = {
Idle = 0,
MovingToLoot = 1,
Interacting = 2,
WaitingForLoot = 3
}
Looting.State = Looting.States.Idle
function Looting:Loot()
if not br.DoLooting then return end
if UnitIsDeadOrGhost("player") then
self.State = Looting.States.Idle
br.ActivePlayer.IsLooting = false
return
end
if br.ActivePlayer.InCombat or br.ObjectManager:LootableCount() == 0 then
self.State = Looting.States.Idle
br.ActivePlayer.IsLooting = false
return
else
if not br.ActivePlayer.IsLooting then
self.State = Looting.States.MovingToLoot
self.TimeoutTime = GetTime()
self:Manager()
end
end
end
function Looting:Manager()
if not br.DoLooting then return end
if br.ObjectManager:LootableCount() == 0 then
self.State = Looting.States.Idle
br.ActivePlayer.IsLooting = false
return
end
if br.ActivePlayer.InCombat then
self.State = Looting.States.Idle
br.ActivePlayer.IsLooting = false
return
end
if GetTime() - self.TimeoutTime > 10 then
Log:Log("Looting timed out.")
self.State = Looting.States.Idle
br.ActivePlayer.IsLooting = false
return
end
local target = br.ObjectManager:ClosestLootable()
if not target then
self.State = Looting.States.Idle
br.ActivePlayer.IsLooting = false
return
end
br.ActivePlayer.IsLooting = true
if target:Distance() > br.api.InteractDistance then
self.State = Looting.States.MovingToLoot
self:MoveToLoot(target)
else
if self.State == Looting.States.MovingToLoot then
self.State = Looting.States.Interacting
C_Timer.After(.5,function()
self:InteractWithLoot(target)
end)
end
end
C_Timer.After(.7,function()
self:Manager()
end)
end
function Looting:MoveToLoot(target)
if target:Distance() > br.api.InteractDistance then
br.ClickToMove(br.ObjectLocation(target.guid))
br.SendMovementHeartbeat()
end
end
function Looting:InteractWithLoot(target)
self.State = Looting.States.WaitingForLoot
br.ObjectInteract(target.guid)
end
local frameLootWatch = CreateFrame("Frame")
frameLootWatch:RegisterEvent("LOOT_CLOSED")
frameLootWatch:SetScript("OnEvent", function(self, event, ...)
if event == "LOOT_CLOSED" then
Log:Log("Loot window closed.")
br.ActivePlayer.IsLooting = false
Looting.State = Looting.States.Idle
end
end)
br.Looting = Looting
Log:Log("BR Looting module loaded")