Skip to content

Commit

Permalink
Core/BossPrototype: Parse any nameplates that may already be showing …
Browse files Browse the repository at this point in the history
…on the first call to `RegisterEngageMob`
  • Loading branch information
funkydude committed Oct 10, 2024
1 parent 0a1b593 commit eaf08ce
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ files["**/AutoRole.lua"].ignore = {
}
files["**/Core/BossPrototype.lua"].ignore = {
"113/C_Item",
"113/C_NamePlate",
"113/C_Seasons",
"113/C_UIWidgetManager",
"113/C_UnitAuras",
Expand All @@ -76,6 +77,7 @@ files["**/Core/BossPrototype.lua"].ignore = {
}
files["**/Core/BossPrototype_Classic.lua"].ignore = {
"113/C_Item",
"113/C_NamePlate",
"113/C_Seasons",
"113/C_UIWidgetManager",
"113/C_UnitAuras",
Expand Down
27 changes: 19 additions & 8 deletions Core/BossPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local C_EncounterJournal_GetSectionInfo = isCata and function(key)
end or isRetail and C_EncounterJournal.GetSectionInfo or function(key)
return BigWigsAPI:GetLocale("BigWigs: Encounter Info")[key]
end
local UnitAffectingCombat, UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, UnitTokenFromGUID = UnitAffectingCombat, UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, loader.UnitTokenFromGUID
local UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, UnitTokenFromGUID = UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, loader.UnitTokenFromGUID
local GetSpellName, GetSpellTexture, GetTime, IsSpellKnown, IsPlayerSpell = loader.GetSpellName, loader.GetSpellTexture, GetTime, IsSpellKnown, IsPlayerSpell
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
local EJ_GetEncounterInfo = isCata and function(key)
Expand All @@ -58,7 +58,7 @@ local hasVoice = BigWigsAPI:HasVoicePack()
local bossUtilityFrame = CreateFrame("Frame")
local petUtilityFrame = CreateFrame("Frame")
local activeNameplateUtilityFrame, inactiveNameplateUtilityFrame = CreateFrame("Frame"), CreateFrame("Frame")
local engagedGUIDs, activeNameplates = {}, {}
local engagedGUIDs, activeNameplates, nameplateWatcher = {}, {}, nil
local enabledModules, unitTargetScans = {}, {}
local allowedEvents = {}
local difficulty, maxPlayers
Expand Down Expand Up @@ -460,7 +460,7 @@ function boss:Disable(isWipe)
petUtilityFrame:UnregisterEvent("UNIT_PET")
activeNameplateUtilityFrame:UnregisterEvent("NAME_PLATE_UNIT_ADDED")
inactiveNameplateUtilityFrame:UnregisterEvent("NAME_PLATE_UNIT_REMOVED")
activeNameplateUtilityFrame.nameplateWatcher:Stop()
nameplateWatcher:Stop()
engagedGUIDs = {}
activeNameplates = {}
unitTargetScans = {}
Expand Down Expand Up @@ -800,6 +800,7 @@ do
allowedEvents.UNIT_DIED = true
bossUtilityFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end

do
local UnitAffectingCombat = UnitAffectingCombat
activeNameplateUtilityFrame:SetScript("OnEvent", function(_, _, unit)
Expand All @@ -808,11 +809,10 @@ do
inactiveNameplateUtilityFrame:SetScript("OnEvent", function(_, _, unit)
activeNameplates[unit] = nil
end)
local nameplateWatcher = activeNameplateUtilityFrame:CreateAnimationGroup()
nameplateWatcher = activeNameplateUtilityFrame:CreateAnimationGroup()
nameplateWatcher:SetLooping("REPEAT")
local anim = nameplateWatcher:CreateAnimation()
anim:SetDuration(0.5)
activeNameplateUtilityFrame.nameplateWatcher = nameplateWatcher
nameplateWatcher:SetScript("OnLoop", function()
for unit in next, activeNameplates do
local guid = UnitGUID(unit)
Expand All @@ -837,6 +837,7 @@ do
end
end
end)
local GetNamePlates = C_NamePlate.GetNamePlates
--- Register a callback for a unit nameplate entering combat.
-- @param func callback function, passed (guid, mobId)
-- @number ... any number of mob ids
Expand All @@ -847,9 +848,18 @@ do
for i = 1, select("#", ...) do
eventMap[self]["UNIT_ENTERING_COMBAT"][select(i, ...)] = func
end
activeNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
inactiveNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
nameplateWatcher:Play()
if not nameplateWatcher:IsPlaying() then
activeNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
inactiveNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
local nameplates = GetNamePlates()
for i = 1, #nameplates do
local nameplateFrame = nameplates[i]
if nameplateFrame.namePlateUnitToken and UnitCanAttack("player", nameplateFrame.namePlateUnitToken) then
activeNameplates[nameplateFrame.namePlateUnitToken] = true
end
end
nameplateWatcher:Play()
end
end
end
--- Checks if a mob is engaged.
Expand Down Expand Up @@ -1238,6 +1248,7 @@ do
unitTargetScans[#unitTargetScans+1] = {self, func, solo and 0.1 or tankCheckExpiry, guid, 0} -- Tiny allowance when solo
end

local UnitAffectingCombat = UnitAffectingCombat
--- Start a repeating timer checking if your group is in combat with a boss.
function boss:CheckForEngage()
if self:IsEnabled() and not self:IsEngaged() then
Expand Down
27 changes: 19 additions & 8 deletions Core/BossPrototype_Classic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local C_EncounterJournal_GetSectionInfo = isCata and function(key)
end or isRetail and C_EncounterJournal.GetSectionInfo or function(key)
return BigWigsAPI:GetLocale("BigWigs: Encounter Info")[key]
end
local UnitAffectingCombat, UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, UnitTokenFromGUID = UnitAffectingCombat, UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, loader.UnitTokenFromGUID
local UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, UnitTokenFromGUID = UnitIsPlayer, UnitPosition, UnitIsConnected, UnitClass, loader.UnitTokenFromGUID
local GetSpellName, GetSpellTexture, GetTime, IsSpellKnown, IsPlayerSpell = loader.GetSpellName, loader.GetSpellTexture, GetTime, IsSpellKnown, IsPlayerSpell
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
local EJ_GetEncounterInfo = isCata and function(key)
Expand All @@ -58,7 +58,7 @@ local hasVoice = BigWigsAPI:HasVoicePack()
local bossUtilityFrame = CreateFrame("Frame")
local petUtilityFrame = CreateFrame("Frame")
local activeNameplateUtilityFrame, inactiveNameplateUtilityFrame = CreateFrame("Frame"), CreateFrame("Frame")
local engagedGUIDs, activeNameplates = {}, {}
local engagedGUIDs, activeNameplates, nameplateWatcher = {}, {}, nil
local enabledModules, unitTargetScans = {}, {}
local allowedEvents = {}
local difficulty, maxPlayers
Expand Down Expand Up @@ -532,7 +532,7 @@ function boss:Disable(isWipe)
petUtilityFrame:UnregisterEvent("UNIT_PET")
activeNameplateUtilityFrame:UnregisterEvent("NAME_PLATE_UNIT_ADDED")
inactiveNameplateUtilityFrame:UnregisterEvent("NAME_PLATE_UNIT_REMOVED")
activeNameplateUtilityFrame.nameplateWatcher:Stop()
nameplateWatcher:Stop()
engagedGUIDs = {}
activeNameplates = {}
unitTargetScans = {}
Expand Down Expand Up @@ -873,6 +873,7 @@ do
allowedEvents.UNIT_DIED = true
bossUtilityFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end

do
local UnitAffectingCombat = UnitAffectingCombat
activeNameplateUtilityFrame:SetScript("OnEvent", function(_, _, unit)
Expand All @@ -881,11 +882,10 @@ do
inactiveNameplateUtilityFrame:SetScript("OnEvent", function(_, _, unit)
activeNameplates[unit] = nil
end)
local nameplateWatcher = activeNameplateUtilityFrame:CreateAnimationGroup()
nameplateWatcher = activeNameplateUtilityFrame:CreateAnimationGroup()
nameplateWatcher:SetLooping("REPEAT")
local anim = nameplateWatcher:CreateAnimation()
anim:SetDuration(0.5)
activeNameplateUtilityFrame.nameplateWatcher = nameplateWatcher
nameplateWatcher:SetScript("OnLoop", function()
for unit in next, activeNameplates do
local guid = UnitGUID(unit)
Expand All @@ -910,6 +910,7 @@ do
end
end
end)
local GetNamePlates = C_NamePlate.GetNamePlates
--- Register a callback for a unit nameplate entering combat.
-- @param func callback function, passed (guid, mobId)
-- @number ... any number of mob ids
Expand All @@ -920,9 +921,18 @@ do
for i = 1, select("#", ...) do
eventMap[self]["UNIT_ENTERING_COMBAT"][select(i, ...)] = func
end
activeNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
inactiveNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
nameplateWatcher:Play()
if not nameplateWatcher:IsPlaying() then
activeNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
inactiveNameplateUtilityFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
local nameplates = GetNamePlates()
for i = 1, #nameplates do
local nameplateFrame = nameplates[i]
if nameplateFrame.namePlateUnitToken and UnitCanAttack("player", nameplateFrame.namePlateUnitToken) then
activeNameplates[nameplateFrame.namePlateUnitToken] = true
end
end
nameplateWatcher:Play()
end
end
end
--- Checks if a mob is engaged.
Expand Down Expand Up @@ -1311,6 +1321,7 @@ do
unitTargetScans[#unitTargetScans+1] = {self, func, solo and 0.1 or tankCheckExpiry, guid, 0} -- Tiny allowance when solo
end

local UnitAffectingCombat = UnitAffectingCombat
--- Start a repeating timer checking if your group is in combat with a boss.
function boss:CheckForEngage()
if self:IsEnabled() and not self:IsEngaged() then
Expand Down

0 comments on commit eaf08ce

Please sign in to comment.