Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created September 22, 2018 22:01
Show Gist options
  • Save Romain-P/cd470882937a2ef78c1cdf93abe29d4d to your computer and use it in GitHub Desktop.
Save Romain-P/cd470882937a2ef78c1cdf93abe29d4d to your computer and use it in GitHub Desktop.
if not ui_defined then
ui_defined = true
target = "target"
player = "player"
player_object = GetObjectWithGUID(UnitGUID(player))
focus = "focus"
arena1 = "arena1"
arena2 = "arena2"
arena3 = "arena3"
dotlist = {
agonie = 980,
corruption = 172,
affliction = 30108,
hanter = 48181,
singularite = 205179
}
spelllist = {
shadowbolt = 232670,
drain = 234153
}
proclist = {
shadowbolt = 264571,
}
cache = {}
function LoS(unit, otherUnit)
if not otherUnit then otherUnit = player end
if not UnitExists(otherUnit) then return end
if UnitIsVisible(unit) or 1 == 1 then
local X1, Y1, Z1 = ObjectPosition(unit);
local X2, Y2, Z2 = ObjectPosition(otherUnit);
return not TraceLine(X1, Y1, Z1 + 2, X2, Y2, Z2 + 2, 0x10);
end
end
function Power()
return WarlockPowerBar_UnitPower(player)
end
function HasDebuff(unit, x, atleast)
if atleast == nil or atleast == 0 then
atleast = 1
end
if not cache[x] then
cache[x] = GetSpellInfo(x)
end
local count = 0
local expire_timestamp
for i = 1, 40 do
local a, _, _, _, _, timestamp = UnitDebuff(unit, i)
if a == cache[x] then
count = count + 1
expire_timestamp = timestamp
end
end
return count >= atleast, count, expire_timestamp
end
function HasBuff(unit, x, atleast)
if atleast == nil or atleast == 0 then
atleast = 1
end
if not cache[x] then
cache[x] = GetSpellInfo(x)
end
local count = 0
local expire_timestamp
for i = 1, 40 do
local a, _, _, _, _, timestamp = UnitBuff(unit, i)
if a == cache[x] then
count = count + 1
expire_timestamp = timestamp
end
end
return count >= atleast, count, expire_timestamp
end
function SpellC(unit, x)
local cd = GetSpellCooldown(x)
if cd > 0 then return false end
CastSpellByID(x, unit)
return true
end
function Dot(unit, x, i, atleast_time)
if not i then i = 1 end
local cd = GetSpellCooldown(x)
local has, count, expiration = HasDebuff(unit, x, i)
if cd > 0 or (has and count >= i and (atleast_time == nil or expiration - GetTime() >= atleast_time)) then return false end
if x == dotlist.affliction and Power() < 1 then return false end
CastSpellByID(x, unit)
return true
end
targets = {}
function IsArena()
local state = IsActiveBattlefieldArena()
return state == true or state == 1
end
function RetrieveUnfocus()
if not IsArena() then return nil end
targets = {
[UnitGUID(arena1)] = arena1,
[UnitGUID(arena2)] = arena2,
[UnitGUID(arena3)] = arena3
}
local tar = UnitGUID(target)
local foc = UnitGUID(focus)
for k,v in pairs(targets) do
if k ~= tar and k ~= foc then
return v
end
end
return nil
end
function SwapFocus()
local unfocus = RetrieveUnfocus()
if not unfocus then return end
FocusUnit(unfocus)
end
function Do(x)
if not x then
x = RetrieveUnfocus()
if not x then return end
end
if HasBuff(player, proclist.shadowbolt) then
SpellC(x, spelllist.shadowbolt)
end
Dot(x, dotlist.agonie, 1, 5)
Dot(x, dotlist.corruption, 1, 3)
Dot(x, dotlist.affliction)
Dot(x, dotlist.singularite)
Dot(x, dotlist.hanter)
Dot(x, dotlist.affliction, 5)
SpellC(x, spelllist.drain)
end
arenasw = {
arena1,
arena2,
arena3
}
arenas = {
arena1,
arena2,
arena3,
arenapet1,
arenapet2,
arenapet3
}
function LowHealth()
if not IsArena() then return end
local hp
local lowest
local current
for _,v in ipairs(arenasw) do
current = UnitHealth(v)
if not hp or current < hp then
hp = current
lowest = v
end
end
return v
end
function ValidUnit(x)
return UnitExists(x) and not UnitIsDead(x)
end
function DoBest()
if HasBuff(player, proclist.shadowbolt) then
local lowest = LowHealth()
SpellC(lowest, spelllist.shadowbolt)
end
for _,v in ipairs(arenasw) do
if ValidUnit(v) and LoS(player, v)
and GetDistanceBetweenObjects(player_object, GetObjectWithGUID(UnitGUID(v))) <= 40 then
if Dot(v, dotlist.corruption, 1, 3) or Dot(v, dotlist.agonie, 1, 5) then
do return end
end
end
end
for _,v in ipairs(arenasw) do
if ValidUnit(v) and LoS(player, v)
and GetDistanceBetweenObjects(player_object, GetObjectWithGUID(UnitGUID(v))) <= 40 then
if Dot(v, dotlist.affliction) then
do break end
end
end
end
end
function SearchValidUnit(excluded)
for _, v in ipairs(arenasw) do
if ValidUnit(v) and UnitGUID(v) ~= UnitGUID(excluded) then
return v
end
end
return nil
end
function onEach()
if not IsArena() then return end
local tmp
if not ValidUnit(target) then
tmp = SearchValidUnit()
if not tmp then return end
TargetUnit(tmp)
end
if not ValidUnit(focus) then
tmp = SearchValidUnit(target)
if not tmp then return end
FocusUnit(tmp)
do return end
end
if UnitGUID(target) == UnitGUID(focus) then
tmp = SearchValidUnit(target)
if not tmp then return end
FocusUnit(tmp)
end
end
looptimer = CreateTimer(20, onEach)
sharedFrame = CreateFrame("FRAME", nil, UIParent)
sharedFrame:RegisterEvent("PLAYER_LOGIN")
sharedFrame:RegisterEvent("PLAYER_LOGOUT")
sharedFrame:SetScript("OnEvent",
function(...)
if looptimer == nil then return end
StopTimer(looptimer)
looptimer = nil
end
)
print("Hello Zavra.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment