Skip to content

Commit

Permalink
BattleRes: Inspect for engineer tinker
Browse files Browse the repository at this point in the history
  • Loading branch information
nebularg committed Jun 21, 2024
1 parent 8964bb3 commit 954a633
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions modules/BattleRes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local badBuffs = {
27827, -- Spirit of Redemption
5384, -- Feign Death
}
local engineerItem = 201409 -- Tinker: Arclight Vital Correctors
local engineerItem = { 201409, 201408, 201407 } -- Tinker: Arclight Vital Correctors
local engineerIcon = 4548853 -- inv_10_engineering_device_gadget1_color2
local resSpells = {
[20484] = true, -- Rebirth
Expand All @@ -24,7 +24,7 @@ local theDead = {}
local updateFunc
local brez
local inCombat = false
local isEngineer = false
local hasEngineer = {}
local active = {
[8] = true, -- Mythic+
[14] = true, -- Normal
Expand Down Expand Up @@ -84,7 +84,7 @@ local function createFrame()
icon:SetPoint("LEFT", remaining, "LEFT", 20, 0)
icon:SetTexture(engineerIcon)
icon:Hide()
brez.icon = icon
brez.engineerIcon = icon

local scroll = CreateFrame("ScrollingMessageFrame", nil, brez)
scroll:SetPoint("TOP", brez, "BOTTOM")
Expand Down Expand Up @@ -117,7 +117,11 @@ local function toggleShow()
if not brez then return end
if module.db.profile.showDisplay then
brez:Show()
brez.icon:SetShown(isEngineer)
if next(hasEngineer) then
brez.engineerIcon:Show()
else
brez.engineerIcon:Hide()
end
else
brez:Hide()
end
Expand Down Expand Up @@ -219,16 +223,23 @@ function module:OnRegister()
end

function module:OnStartup()
wipe(hasEngineer)
self:RegisterEvent("ZONE_CHANGED_NEW_AREA", "CheckOpen")
self:RegisterEvent("CHALLENGE_MODE_START")
oRA.RegisterCallback(self, "OnGroupChanged", "CheckOpen")
oRA.RegisterCallback(self, "OnPlayerInspect")
oRA.RegisterCallback(self, "OnPlayerRemove")
self:OnPlayerInspect(nil, UnitGUID("player"), "player")
self:CheckOpen()
end

function module:OnShutdown()
wipe(hasEngineer)
self:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
self:UnregisterEvent("CHALLENGE_MODE_START")
oRA.UnregisterCallback(self, "OnGroupChanged")
oRA.UnregisterCallback(self, "OnPlayerInspect")
oRA.UnregisterCallback(self, "OnPlayerRemove")
self:Close()
end

Expand All @@ -237,6 +248,28 @@ function module:CHALLENGE_MODE_START()
self:ScheduleTimer("CheckOpen", 1)
end

function module:OnPlayerInspect(_, guid, unit)
hasEngineer[guid] = nil
-- Check head and wrist for Tinker: Arclight Vital Correctors
for _, slot in ipairs{ 1, 9 } do
local itemLink = GetInventoryItemLink(unit, slot)
if itemLink then
for _, engineerItemId in next, engineerItem do
if tonumber(itemLink:match("item:%d+:%d*:(%d*):")) == engineerItemId then
hasEngineer[guid] = true
break
end
end
end
end
self:CheckOpen()
end

function module:OnPlayerRemove(_, guid)
hasEngineer[guid] = nil
self:CheckOpen()
end

do
local GetTime, GetSpellCharges = GetTime, GetSpellCharges
local function updateTime()
Expand Down Expand Up @@ -281,12 +314,12 @@ do
else
brez.remaining:SetTextColor(0,1,0)
end
if isEngineer then
if next(hasEngineer) then
local count = 1 -- GetItemCount(engineerItem)
if count > 0 then
brez.icon:SetVertexColor(1, 1, 1)
brez.engineerIcon:SetVertexColor(1, 1, 1)
else
brez.icon:SetVertexColor(1, 0.5, 0.5)
brez.engineerIcon:SetVertexColor(1, 0.5, 0.5)
end
end
end
Expand All @@ -301,38 +334,16 @@ do
end
end

local p = { 1, 9 }
local function canGroupRes()
isEngineer = false
if next(hasEngineer) then
return true
end
for _, player in next, oRA:GetGroupMembers() do
local _, class = UnitClass(player)
if class == "DRUID" or class == "DEATHKNIGHT" or class == "WARLOCK" or class == "PALADIN" then
return true
end
end

-- p[1], p[2] = GetProfessions()
-- for i = 1, 2 do
-- local index = p[i]
-- if index then
-- local _, _, rank, _, _, _, _, _, _, _, skillLineName = GetProfessionInfo(index)
-- if skillLineName == C_TradeSkillUI.GetTradeSkillDisplayName(2755) and rank > 50 then -- Shadowlands Engineering
-- isEngineer = true
-- return true
-- end
-- end
-- end

-- Check head and wrist for Tinker: Arclight Vital Correctors
for i = 1, 2 do
local slot = p[i]
local itemLink = GetInventoryItemLink("player", slot)
if tonumber(itemLink:match("item:%d+:%d*:(%d*):")) == engineerItem then
isEngineer = true
return true
end
end

return module.db.profile.alwaysShow
end

Expand Down

0 comments on commit 954a633

Please sign in to comment.