-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbrCombatManager.lua
More file actions
137 lines (116 loc) · 5.17 KB
/
brCombatManager.lua
File metadata and controls
137 lines (116 loc) · 5.17 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---@type _,br,NilName
local _,br,nn = ...
---@type br.Logging
local Log = br.Logging or {}
---@class br.CombatManager
---@field Initialize fun(self:br.CombatManager) #Initializes the Combat Manager
local cm = {}
br.CombatManager = cm
br.CombatManager.__index = br.CombatManager
cm.CombatLogFrame = {}
cm.InCombatFrame = {}
function cm:Initialize()
self.__index = self
--Combat Log Parser
self.CombatLogFrame = CreateFrame("Frame")
if br.clientTOC < 120000 then
self.CombatLogFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self.CombatLogFrame:SetScript("OnEvent", function(self, event, ...)
local timestamp, subevent, hideCaster,
sourceGUID, sourceName, sourceFlags, sourceRaidFlags,
destGUID, destName, destFlags, destRaidFlags,
spellId, spellName, spellSchool,
amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = CombatLogGetCurrentEventInfo()
if subevent and subevent == "UNIT_DIED" then
--print("UNIT_DIED: " .. tostring(destName) .. " " .. tostring(destGUID))
--Remove from ObjectManager
end
if subevent and subevent == "SPELL_CAST_FAILED" then
if sourceGUID == br.ActivePlayer.WoWGUID then
-- Log:Log("Spell Cast Failed: " .. tostring(spellName) .. " (" .. tostring(spellId) .. ") Reason: " .. tostring(amount))
end
end
--Track Summoned creatures/units
if subevent and subevent == "SPELL_SUMMON" then
-- Example: Log summon events
if sourceGUID == br.ActivePlayer.WoWGUID then
--Update OM to ensure object is there
br.ObjectManager:Update()
C_Timer.After(0.2, function()
local found = false
for k,v in pairs(br.ObjectManager.Units) do
if v.WoWGUID == destGUID then
v.FirstContact = GetTime()
v.IsCreatedByPlayer = true
found = true
break
end
end
if not found then
Log:LogError("Could not find summoned unit in ObjectManager: " .. destName .. " " .. tostring(destGUID))
end
end)
end
end
if subevent and subevent:find("DAMAGE") ~= nil then
-- if source or destination is player,summoned creature, or pet then unit is in combat with us
if sourceGUID == br.ActivePlayer.WoWGUID
or destGUID == br.ActivePlayer.WoWGUID
or br.ActivePlayer:PetGUID() and sourceGUID == br.ActivePlayer:PetGUID()
or br.ActivePlayer:PetGUID() and destGUID == br.ActivePlayer:PetGUID()
then
for k,v in pairs(br.ObjectManager.Units) do
if v.WoWGUID == destGUID and not(v.IsCreatedByPlayer or v.WoWGUID == br.ActivePlayer.WoWGUID) then
v.CombatWithPlayer = true
v.LastContact = GetTime()
if v.FirstContact == 0 then
v.FirstContact = GetTime()
end
break
end
end
end
end
end)
end
--Player In Combat handler
self.InCombatFrame = CreateFrame("Frame")
self.InCombatFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
self.InCombatFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
self.InCombatFrame:RegisterEvent("UNIT_SPELLCAST_FAILED")
self.InCombatFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self.InCombatFrame:RegisterEvent("LOOT_OPENED")
self.InCombatFrame:RegisterEvent("LOOT_CLOSED")
self.InCombatFrame:SetScript("OnEvent", function(self, event, ...)
if event == "LOOT_OPENED" then
br.ActivePlayer.IsLooting = true
end
if event == "LOOT_CLOSED" then
br.ActivePlayer.IsLooting = false
end
if event == "UNIT_SPELLCAST_FAILED" then
local unitID, spellName, _, _, spellID = ...
if unitID == "player" and spellID ~= nil then
Log:Log("Player Spell Cast Failed: " .. tostring(spellName) .. " (" .. tostring(spellID) .. ")")
end
end
if event == "UNIT_SPELLCAST_SUCCEEDED" then
local unitID, castGuid, spellID = ...
if unitID == "player" and spellID ~= nil then
--br.ActivePlayer.LastCastSpell = spellID
--Log:Log("Player Spell Cast Succeeded: " .. tostring(spellID))
end
end
if event == "PLAYER_REGEN_DISABLED" then
Log:Log("Player entered combat.")
br.ActivePlayer.InCombat = true
br.ActivePlayer.CombatStartTime = GetTime()
br.ActivePlayer.NeedsOpener = true
elseif event == "PLAYER_REGEN_ENABLED" then
Log:Log("Player exited combat.")
br.ActivePlayer.InCombat = false
br.ActivePlayer.NeedsOpener = false
end
end)
Log:Log("Combat Manager Initialized")
end