1. local addon, ns = ...
  2. local cfg = ns.cfg
  3.  
  4. local SVal = function(val)
  5.     if val then
  6.         if (val >= 1e6) then
  7.             return ("%.1fm"):format(val / 1e6)
  8.         elseif (val >= 1e3) then
  9.             return ("%.1fk"):format(val / 1e3)
  10.         else
  11.             return ("%d"):format(val)
  12.         end
  13.     end
  14. end
  15.  
  16. local function hex(r, g, b)
  17.     if r then
  18.         if (type(r) == 'table') then
  19.             if(r.r) then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end
  20.         end
  21.         return ('|cff%02x%02x%02x'):format(r * 255, g * 255, b * 255)
  22.     end
  23. end
  24.  
  25. pcolors = setmetatable({
  26.     power = setmetatable({
  27.         ["MANA"] = {0.14, 0.35, 1.0},
  28.         ["RAGE"] = {1.0, 0.0, 0.0},
  29.         ["RUNIC_POWER"] = {0.44, 0.44, 0.44},
  30.         ["FOCUS"] = {1.0,0.75,0.25},
  31.         ["ENERGY"] = {1.0, 0.9, 0.35},
  32.         ["HAPPINESS"] = {0.0, 1.0, 1.0},
  33.         --["RUNES"] = {0.50, 0.50, 0.50},
  34.         ["AMMOSLOT"] = {0.80, 0.60, 0.00},
  35.         ["FUEL"] = {0.0, 0.55, 0.5},
  36.         ["SOUL_SHARDS"] = {0.46, 0.32, 0.87},
  37.         ["POWER_TYPE_HEAT"] = {0.55,0.57,0.61},
  38.         ["POWER_TYPE_OOZE"] = {0.76,1,0},
  39.         ["POWER_TYPE_BLOOD_POWER"] = {0.7,0,1},
  40.     }, {__index = oUF.colors.power}),
  41. }, {__index = oUF.colors})
  42.  
  43. oUF.Tags["fail:lfdrole"] = function(unit)
  44.     local role = UnitGroupRolesAssigned(unit)
  45.     if role == "HEALER" then
  46.         return "|cff8AFF30Heals|r"
  47.     elseif role == "TANK" then
  48.         return "|cffFFF130Tank|r"
  49.     elseif role == "DAMAGER" then
  50.         return "|cffFF6161DPS|r"
  51.     end
  52. end
  53.    
  54. oUF.TagEvents["fail:lfdrole"] = "PARTY_MEMBERS_CHANGED PLAYER_ROLES_ASSIGNED"
  55.  
  56. oUF.Tags['fail:hp']  = function(u)
  57.   if UnitIsDead(u) or UnitIsGhost(u) or not UnitIsConnected(u) then
  58.     return oUF.Tags['fail:DDG'](u)
  59.   else
  60.     local per = oUF.Tags['perhp'](u).."%" or 0
  61.     local min, max = UnitHealth(u), UnitHealthMax(u)
  62.     if u == "player" or u == "target" then
  63.       if min~=max then
  64.         return "|cFFFFAAAA"..SVal(min).."|r/"..SVal(max).."   "..per
  65.       else
  66.         return SVal(max).."   "..per
  67.       end
  68.     else
  69.       return per
  70.     end
  71.   end
  72. end
  73. oUF.TagEvents['fail:hp'] = 'UNIT_HEALTH'
  74.  
  75. oUF.Tags['fail:raidhp']  = function(u)
  76.   if UnitIsDead(u) or UnitIsGhost(u) or not UnitIsConnected(u) then
  77.     return oUF.Tags['fail:DDG'](u)
  78.   else
  79.     local per = oUF.Tags['perhp'](u).."%" or 0
  80.     return per
  81.   end
  82. end
  83. oUF.TagEvents['fail:raidhp'] = 'UNIT_HEALTH'
  84.  
  85. oUF.Tags['fail:color'] = function(u, r)
  86.     local _, class = UnitClass(u)
  87.     local reaction = UnitReaction(u, "player")
  88.    
  89.     if UnitIsDead(u) or UnitIsGhost(u) or not UnitIsConnected(u) then
  90.         return "|cffA0A0A0"
  91.     elseif (UnitIsTapped(u) and not UnitIsTappedByPlayer(u)) then
  92.         return hex(oUF.colors.tapped)
  93.     elseif (UnitIsPlayer(u)) then
  94.         return hex(oUF.colors.class[class])
  95.     elseif reaction then
  96.         return hex(oUF.colors.reaction[reaction])
  97.     else
  98.         return hex(1, 1, 1)
  99.     end
  100. end
  101. oUF.TagEvents['fail:color'] = 'UNIT_REACTION UNIT_HEALTH UNIT_HAPPINESS'
  102.  
  103. oUF.Tags["fail:afkdnd"] = function(unit)
  104.    
  105.     return UnitIsAFK(unit) and "" or UnitIsDND(unit) and "" or ""
  106. end
  107. oUF.TagEvents["fail:afkdnd"] = 'PLAYER_FLAGS_CHANGED UNIT_POWER UNIT_MAXPOWER'
  108.  
  109. oUF.Tags['fail:DDG'] = function(u)
  110.     if UnitIsDead(u) then
  111.         return "|cffCFCFCF Dead|r"
  112.     elseif UnitIsGhost(u) then
  113.         return "|cffCFCFCF Ghost|r"
  114.     elseif not UnitIsConnected(u) then
  115.         return "|cffCFCFCF D/C|r"
  116.     end
  117. end
  118. oUF.TagEvents['fail:DDG'] = 'UNIT_HEALTH'
  119.  
  120. oUF.Tags['fail:power']  = function(u)
  121.     local min, max = UnitPower(u), UnitPowerMax(u)
  122.     if min~=max then
  123.         return SVal(min).."/"..SVal(max)
  124.     else
  125.         return SVal(max)
  126.     end
  127. end
  128. oUF.TagEvents['fail:power'] = 'UNIT_POWER UNIT_MAXPOWER'
  129.  
  130. oUF.Tags['fail:pp'] = function(u)
  131.     if u == "player" or u == "target" then
  132.         local _, str = UnitPowerType(u)
  133.         if str then
  134.             return hex(pcolors.power[str] or {250/255,  75/255,  60/255})..SVal(UnitPower(u))
  135.         end
  136.     end
  137. end
  138. oUF.TagEvents['fail:pp'] = 'UNIT_POWER UNIT_MAXPOWER'
  139.  
  140. -- Level
  141. oUF.Tags["fail:level"] = function(unit)
  142.    
  143.     local c = UnitClassification(unit)
  144.     local l = UnitLevel(unit)
  145.     local d = GetQuestDifficultyColor(l)
  146.    
  147.     local str = l
  148.        
  149.     if l <= 0 then l = "??" end
  150.    
  151.     if c == "worldboss" then
  152.         str = string.format("|cff%02x%02x%02xBoss|r",250,20,0)
  153.     elseif c == "eliterare" then
  154.         str = string.format("|cff%02x%02x%02x%s|r|cff0080FFR|r+",d.r*255,d.g*255,d.b*255,l)
  155.     elseif c == "elite" then
  156.         str = string.format("|cff%02x%02x%02x%s|r+",d.r*255,d.g*255,d.b*255,l)
  157.     elseif c == "rare" then
  158.         str = string.format("|cff%02x%02x%02x%s|r|cff0080FFR|r",d.r*255,d.g*255,d.b*255,l)
  159.     else
  160.         if not UnitIsConnected(unit) then
  161.             str = "??"
  162.         else
  163.             if UnitIsPlayer(unit) then
  164.                 str = string.format("|cff%02x%02x%02x%s",d.r*255,d.g*255,d.b*255,l)
  165.             elseif UnitPlayerControlled(unit) then
  166.                 str = string.format("|cff%02x%02x%02x%s",d.r*255,d.g*255,d.b*255,l)
  167.             else
  168.                 str = string.format("|cff%02x%02x%02x%s",d.r*255,d.g*255,d.b*255,l)
  169.             end
  170.         end    
  171.     end
  172.    
  173.     return str
  174. end
  175. oUF.TagEvents["fail:level"] = "UNIT_LEVEL PLAYER_LEVEL_UP UNIT_CLASSIFICATION_CHANGED"
  176.  
  177. oUF.UnitlessTagEvents.PLAYER_REGEN_DISABLED = true
  178. oUF.UnitlessTagEvents.PLAYER_REGEN_ENABLED = true