Advertisement
Guest User

Untitled

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