Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential new isHealer check #38

Open
rbgdevx opened this issue Nov 7, 2024 · 2 comments
Open

Potential new isHealer check #38

rbgdevx opened this issue Nov 7, 2024 · 2 comments

Comments

@rbgdevx
Copy link

rbgdevx commented Nov 7, 2024

Hey 👋🏼 I think i have a new way to check if someone is a healer.

In 10.1.5 if you remember they added the spec to the tooltip on hover of characters. This code i have working in my project right now and haven't had an issue yet, lmk what you think but if it works for you it would eliminate the dependency on details.

local Healers = {}
local HEALER_SPECS = {
  ["Restoration Druid"] = true,
  ["Restoration Shaman"] = true,
  ["Mistweaver Monk"] = true,
  ["Holy Priest"] = true,
  ["Holy Paladin"] = true,
  ["Discipline Priest"] = true,
  ["Preservation Evoker"] = true,
}
local isHealer = Healers[UnitGUID(unit)] and true or false
local tooltipData = GetUnitTooltip(unit)
if tooltipData then
  if
    tooltipData.guid
    and tooltipData.lines
    and #tooltipData.lines >= 3
    and tooltipData.type == Enum.TooltipDataType.Unit
  then
    if GUIDIsPlayer(tooltipData.guid) then
      if not Healers[tooltipData.guid] then
        for _, line in ipairs(tooltipData.lines) do
          if line and line.type == Enum.TooltipDataLineType.None then
            if line.leftText and line.leftText ~= "" and HEALER_SPECS[line.leftText] then
              Healers[tooltipData.guid] = true
              isHealer = true
              break
            end
          end
        end
      end
    end
  end
end
info.isHealer = isHealer

There may be a dynamic way to get spec names to store as a reference table but i don't know.

I could easily see it getting added to this function here

local function GetNameplateUnitInfo(frame, unit)

@Bodify
Copy link
Owner

Bodify commented Dec 20, 2024

Hey! Sorry for the late reply been very busy and somehow havent noticed. Thank you for the info, I knew something like this was maybe possible yeah but I never bothered looking more into it but its always nice to get it shown like this. I am and will be busy for quite a bit but hopefully things slow down a little soon and I can maybe play around with this. Have you done any more testing yourself since you posted it?

@rbgdevx
Copy link
Author

rbgdevx commented Dec 20, 2024

yes! in my nameplate-trinket addon i have a ton of new code but i made a function that runs on nameplate add

local Healers = {}
local HEALER_SPECS = {
  ["Restoration Druid"] = 105,
  ["Restoration Shaman"] = 264,
  ["Mistweaver Monk"] = 270,
  ["Holy Priest"] = 257,
  ["Holy Paladin"] = 65,
  ["Discipline Priest"] = 256,
  ["Preservation Evoker"] = 1468,
}
local function checkIsHealer(nameplate, guid)
  local unit = nameplate.namePlateUnitToken

  local isPlayer = UnitIsPlayer(unit)
  local _, _, classId = UnitClass(unit)
  local canBeHealer = classId ~= nil and HEALER_CLASS_IDS[classId] == true

  if isPlayer and canBeHealer and not Healers[guid] then
    local tooltipData = GetUnitTooltip(unit)
    if tooltipData then
      if
        tooltipData.guid
        and tooltipData.lines
        and #tooltipData.lines >= 3
        and tooltipData.type == Enum.TooltipDataType.Unit
      then
        for _, line in ipairs(tooltipData.lines) do
          if line and line.type == Enum.TooltipDataLineType.None then
            if line.leftText and line.leftText ~= "" then
              if Healers[tooltipData.guid] and HEALER_SPECS[line.leftText] then
                break
              end
              if Healers[tooltipData.guid] and not HEALER_SPECS[line.leftText] then
                Healers[tooltipData.guid] = nil
                break
              end
              if not Healers[tooltipData.guid] and HEALER_SPECS[line.leftText] then
                Healers[tooltipData.guid] = true
                break
              end
            end
          end
        end
      end
    end
  end
end

worth noting that the specs aren't localized though.

i also use this check when entering world, group roster update, and spec update

NS.isInGroup = function()
  return IsInRaid() or IsInGroup()
end

NS.isHealer = function(unit)
  return UnitGroupRolesAssigned(unit) == "HEALER"
end

NS.IterateGroupMembers = function(reversed, forceParty)
  local unit = (not forceParty and IsInRaid()) and "raid" or "party"
  local numGroupMembers = unit == "party" and GetNumSubgroupMembers() or GetNumGroupMembers()
  local i = reversed and numGroupMembers or (unit == "party" and 0 or 1)
  return function()
    local ret
    if i == 0 and unit == "party" then
      ret = "player"
    elseif i <= numGroupMembers and i > 0 then
      ret = unit .. i
    end
    i = i + (reversed and -1 or 1)
    return ret
  end
end
if NS.isInGroup() then
    for unit in NS.IterateGroupMembers() do
      local guid = UnitGUID(unit)
      if unit and guid then
        if NS.isHealer(unit) and not Healers[guid] then
          Healers[guid] = true
        end
        if not NS.isHealer(unit) and Healers[guid] then
          Healers[guid] = nil
        end
      end
    end
  else
    local guid = UnitGUID("player")
    if guid then
      if NS.isHealer("player") and not Healers[guid] then
        Healers[guid] = true
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants