Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.23 KB | None | 0 0
  1. function CalculateHP(t)
  2.     incomingheals = UnitGetIncomingHeals(t) and UnitGetIncomingHeals(t) or 0
  3.     local PercentWithIncoming = 100 * ( UnitHealth(t) + incomingheals ) / UnitHealthMax(t)
  4.     local ActualWithIncoming = ( UnitHealthMax(t) - ( UnitHealth(t) + incomingheals ) )
  5.     return PercentWithIncoming, ActualWithIncoming
  6. end
  7.  
  8. function CanHeal(t)
  9.     if UnitInRange(t)
  10.             --Missing LOS Check
  11.             and UnitCanCooperate("player",t)
  12.             and not UnitIsCharmed(t)
  13.             and not UnitIsDeadOrGhost(t)
  14.             and UnitIsConnected(t)
  15.             and UnitDebuffID(t,104451) == nil -- Ice Tomb
  16.             and UnitDebuffID(t,76577) == nil -- Smoke Bomb
  17.     then return true else return false end
  18. end
  19.  
  20. function HealingEngine(MO, LOWHP, ACTUALHP)
  21.     R_Tanks = { }
  22.     local MouseoverCheck = MO or false
  23.     local ActualHP = ACTUALHP or false
  24.     local LowHPTarget = LOWHP or 80
  25.     lowhpmembers = 0
  26.     members = { { Unit = "player", HP = CalculateHP("player"), GUID = UnitGUID("player"), AHP = select(2, CalculateHP("player")) } }
  27.  
  28.     -- Check if the Player is apart of the Custom Table
  29.     for i=1, #R_CustomT do
  30.         if UnitGUID("player") == R_CustomT[i].GUID then
  31.             R_CustomT[i].Unit = "player"
  32.             R_CustomT[i].HP = CalculateHP("player")
  33.             R_CustomT[i].AHP = select(2, CalculateHP("player"))
  34.         end
  35.     end
  36.  
  37.     if IsInRaid() then
  38.         group = "raid"
  39.     elseif IsInGroup() then
  40.         group = "party"
  41.     end
  42.  
  43.     for i = 1, GetNumGroupMembers() do
  44.         local member, memberhp = group..i, CalculateHP(group..i)
  45.  
  46.         -- Checking all Party/Raid Members for Range/Health
  47.         if CanHeal(member) then
  48.             -- Checking if Member has threat
  49.             if UnitThreatSituation(member) == 3 then memberhp = memberhp - 3 end
  50.             -- Checking if Member has Beacon on them
  51.             if UnitBuffID(member, 53563) then memberhp = memberhp + 3 end
  52.             -- Searing Plasma Check
  53.             if UnitDebuffID(member, 109379) then memberhp = memberhp - 9 end
  54.             -- Checking if Member is a tank
  55.             if UnitGroupRolesAssigned(member) == "TANK" then
  56.                 memberhp = memberhp - 1
  57.                 table.insert(R_Tanks, { Unit = member, HP = memberhp, AHP = select(2, CalculateHP(member)) } )
  58.             end
  59.             -- If they are in the Custom Table add their info in
  60.             for i=1, #R_CustomT do
  61.                 if UnitGUID(member) == R_CustomT[i].GUID then
  62.                     R_CustomT[i].Unit = member
  63.                     R_CustomT[i].HP = memberhp
  64.                     R_CustomT[i].AHP = select(2, CalculateHP(member))
  65.                 end
  66.             end
  67.  
  68.             table.insert( members,{ Unit = group..i, HP = memberhp, GUID = UnitGUID(group..i), AHP = select(2, CalculateHP(group..i)) } )
  69.         end
  70.  
  71.         -- Checking Pets in the group
  72.         if CanHeal(group..i.."pet") then
  73.             local memberpet, memberpethp = nil, nil
  74.             if UnitAffectingCombat("player") then
  75.                 memberpet = group..i.."pet"
  76.                 memberpethp = CalculateHP(group..i.."pet") * 2
  77.             else
  78.                 memberpet = group..i.."pet"
  79.                 memberpethp = CalculateHP(group..i.."pet")
  80.             end
  81.  
  82.             -- Checking if Pet is apart of the CustomTable
  83.             for i=1, #R_CustomT do
  84.                 if UnitGUID(memberpet) == R_CustomT[i].GUID then
  85.                     R_CustomT[i].Unit = memberpet
  86.                     R_CustomT[i].HP = memberpethp
  87.                     R_CustomT[i].AHP = select(2, CalculateHP(memberpet))
  88.                 end
  89.             end
  90.             table.insert(members, { Unit = memberpet, HP = memberpethp, GUID = UnitGUID(memberpet), AHP = select(2, CalculateHP(memberpet)) } )
  91.         end
  92.     end
  93.  
  94.     -- So if we pass that ActualHP is true, then we will sort by most health missing. If not, we sort by lowest % of health.
  95.     if not ActualHP then
  96.         table.sort(members, function(x,y) return x.HP < y.HP end)
  97.         if #R_Tanks > 0 then
  98.             table.sort(R_Tanks, function(x,y) return x.HP < y.HP end)
  99.         end
  100.     elseif ActualHP then
  101.         table.sort(members, function(x,y) return x.AHP > y.AHP end)
  102.         if #R_Tanks > 0 then
  103.             table.sort(R_Tanks, function(x,y) return x.AHP > y.AHP end)
  104.         end
  105.     end
  106.  
  107.     -- Setting Low HP Members variable for AoE Healing
  108.     for i=1,#members do
  109.         if members[i].HP < LowHPTarget then
  110.             lowhpmembers = lowhpmembers + 1
  111.         end
  112.     end
  113.  
  114.     -- Checking Priority Targeting
  115.     if CanHeal("target") then
  116.         table.sort(members, function(x) return UnitIsUnit("target",x.Unit) end)
  117.     elseif CanHeal("mouseover") and GetMouseFocus() ~= WorldFrame and MouseoverCheck then
  118.         table.sort(members, function(x) return UnitIsUnit("mouseover",x.Unit) end)
  119.     end
  120. end
  121.  
  122. function CheckDistance(unit1,unit2)
  123.     local x1,y1 = GetPlayerMapPosition(unit1)
  124.     local x2,y2 = GetPlayerMapPosition(unit2)
  125.  
  126.     return sqrt( (x1-x2)^2 + (y1-y2)^2 )
  127. end
  128.  
  129. function UnitsClose(t, percent)
  130.     local PercentToHeal = percent or 85
  131.     local n = 0
  132.  
  133.     if distance and distance[1] then
  134.         for i=1,#members do
  135.             local x = CheckDistance(t,members[i].Unit)
  136.             if x ~= 0 and x < distance[1] and members[i].HP < PercentToHeal then n = n + 1 end
  137.         end
  138.     end
  139.     return n
  140. end
  141.  
  142. function GetDistance()
  143.     local playerx,playery = GetPlayerMapPosition("player")
  144.  
  145.     if GetCurrentMapAreaID() ~= xrnMap or GetCurrentMapDungeonLevel() ~= xrnDung then
  146.         xrnMap,xrnDung = GetCurrentMapAreaID(), GetCurrentMapDungeonLevel()
  147.         mp, distance = {}, {}
  148.     end
  149.  
  150.     if #members > 1 and #distance < 10 and playerx ~= 0 and playery ~= 0 then
  151.         for i=1,#members do
  152.             if CheckInteractDistance(members[i].Unit,2) then
  153.                 mp[members[i].Unit] = {GetPlayerMapPosition(members[i].Unit)}
  154.             elseif UnitInRange(members[i].Unit) and mp[members[i].Unit] then
  155.                 table.insert(distance,sqrt((mp[members[i].Unit][1] - playerx)^2 + (mp[members[i].Unit][2] - playery)^2))
  156.                 table.sort(distance)
  157.                 mp[members[i].Unit] = nil
  158.             end
  159.         end
  160.     end
  161. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement