Skip to content

Commit

Permalink
failing clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
d87 committed Aug 11, 2016
1 parent c040003 commit 5888941
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 4 deletions.
171 changes: 168 additions & 3 deletions Aptechka.lua
Expand Up @@ -774,6 +774,12 @@ function Aptechka.GROUP_ROSTER_UPDATE(self,event,arg1)
self:RegisterEvent("PLAYER_REGEN_ENABLED")
end

if GetNumGroupMembers() > 1 then
Aptechka:ClusterRosterUpdate()
Aptechka:EnableSmartHeal()
else
Aptechka:DisableSmartHeal()
end

for unit, frames in pairs(Roster) do
for frame in pairs(frames) do
Expand Down Expand Up @@ -1597,7 +1603,7 @@ end



local arrowframe = CreateFrame("Frame")
local arrowframe = CreateFrame("Frame", nil, Aptechka)
Aptechka.arrowframe = arrowframe
-- arrowframe:SetScript("OnEvent", function(self, event, ...)
-- self[event](self, event, ...)
Expand Down Expand Up @@ -1652,8 +1658,8 @@ end
function arrowframe:Create()
if self.created then return end
self.created = true
self:SetWidth(20)
self:SetHeight(20)
self:SetWidth(30)
self:SetHeight(30)
self:SetFrameLevel(4)
local atex = self:CreateTexture(nil, "OVERLAY")
atex:SetAllPoints(self)
Expand Down Expand Up @@ -1699,3 +1705,162 @@ function arrowframe:Create()
self.texture:SetVertexColor(r,g,b)
end)
end


local function insertsort(T,func)
for i=2,#T do
local j = i
while j > 1 and func(T[j],T[j-1]) do
T[j],T[j-1] = T[j-1],T[j]
j=j-1
end
end
end

local sortfunc = function(a,b)
-- return (UnitHealthMax(a)-UnitHealth(a)) < (UnitHealthMax(b)-UnitHealth(b))
return (UnitHealth(a)/UnitHealthMax(a)) < (UnitHealth(b)/UnitHealthMax(b))
end

local HealthRoster = setmetatable({
Sort = function(self)
insertsort(self, sortfunc)
end
},{
__mode = 'k',
__index = function(t,k)
for i,v in ipairs(t) do
if v == k then return true end
end
end,
__newindex = function(t,k, v1)
for i,v in ipairs(t) do
if v == k then return end
end
table.insert(t,k)
end
})
HEALTHROSTER = HealthRoster

function DUMPROSTER()
for i,unit in ipairs(HealthRoster) do
print(UnitName(unit))
end
end


local function GetUnitDistanceSquared(unit1, unit2)
local y1, x1 = UnitPosition(unit1)
local y2, x2 = UnitPosition(unit2)
if not y1 or not y2 then return nil end

local xx = x2 - x1
local yy = y2 - y1

return xx*xx + yy*yy
end

local function IsValidTarget(unitid)
return not UnitIsDeadOrGhost(unitid) and
UnitIsConnected(unitid) and
UnitIsVisible(unitid) and
UnitHealth(unitid) ~= UnitHealthMax(unitid) and
not (UnitIsCharmed(unitid) and UnitIsEnemy("player", unitid))
end

function Aptechka:ClusterRosterUpdate()
for unit in pairs(Roster) do
HealthRoster[unit] = true
end
for i, unit in ipairs(HealthRoster) do
if not Roster[unit] then
table.remove(HealthRoster, i)
end
end
end
--
-- function Aptechka:ClusterHealthUpdate(unit, health, healthmax)
-- end

local cluster_spells

function Aptechka.UpdateSmartHeals()
if UnitExists("mouseover") then-- and (UnitInParty("mouseover") or UnitInRaid("mouseover") or UnitIsUnit("mouseover","player")) then
local originUnit = "mouseover"
-- for unit in pairs(Roster) do
-- if UnitIsUnit("mouseover", unit) then
-- originUnit = unit
-- break
-- end
-- end
-- if not originUnit then return end

HealthRoster:Sort()
for i, spellData in ipairs(cluster_spells) do
if select(2,GetSpellCooldown(spellData.spellID)) <= 1.5 then
local targets = 0
local maxtargets = spellData.maxtargets
local range = spellData.range
local color = spellData.color
for i,unit in ipairs(HealthRoster) do
if IsValidTarget(unit) then
local distance = GetUnitDistanceSquared(originUnit, unit)
if distance and distance < range then--and targets < maxtargets then
for frame in pairs(Roster[unit]) do
frame.smartheal:Show()
frame.smartheal:SetVertexColor(unpack(color))
targets = targets + 1
end
else
for frame in pairs(Roster[unit]) do
frame.smartheal:Hide()
end
end
end
end
end
end

else
for unit, frames in pairs(Roster) do
for frame in pairs(frames) do
frame.smartheal:Hide()
end
end
end
end

do
local cframe = CreateFrame("Frame", nil, Aptechka)
local UpdateFunction = Aptechka.UpdateSmartHeals
local cf_update_counter = 0
cframe:Hide()
cframe:SetScript("OnUpdate", function(self, elapsed)
cf_update_counter = cf_update_counter + elapsed
if cf_update_counter < 0.05 then return end

UpdateFunction()
end)


function Aptechka:EnableSmartHeal()
if not config.smartHealHelper then return end
if not config.SmartHeals then return end -- no spells for this class
local spec = GetSpecialization()
cluster_spells = config.SmartHeals[spec]
if cluster_spells then
cframe:Show()
else
cframe:Hide()
end
end

function Aptechka:DisableSmartHeal()
cframe:Hide()
for unit, frames in pairs(Roster) do
for frame in pairs(frames) do
frame.smartheal:Hide()
end
end
end
end
43 changes: 42 additions & 1 deletion config.lua
Expand Up @@ -59,8 +59,9 @@ config.enableDirectionArrow = true
config.incomingHealThreshold = 15000
config.incomingHealIgnorePlayer = false
config.showPhaseIcon = true
config.smartHealHelper = true
config.displayRoles = true
config.enableTraceHeals = false
config.enableTraceHeals = true
config.enableVehicleSwap = true
config.enableAbsorbBar = true
config.enableClickCasting = false
Expand Down Expand Up @@ -158,6 +159,7 @@ if playerClass == "PRIEST" then

-- Trace{id = 94472, type = "HEAL", minamount = 10000, assignto = { "spell3" }, color = { .2, 1, .2}, fade = .5, priority = 90 } -- Atonement
Trace{id = 204883, type = "HEAL", assignto = { "spell3" }, color = { 1, 1, 0}, fade = 0.7, priority = 96 } -- Circle of Healing
Trace{id = 596, type = "HEAL", assignto = { "spell3" }, color = { .5, .5, 1}, fade = 0.7, priority = 96 } -- Circle of Healing
-- Trace{id = 33076, type = "HEAL", assignto = { "spell3" }, color = { .3, 1, .3}, fade = 1, priority = 97 } -- PoM Trace

-- Trace{id = 47750, type = "HEAL", assignto = { "spell2", "spell3" }, color = { .3, 1, .3}, fade = 1.5, priority = 97 } -- PoM Trace
Expand All @@ -166,6 +168,23 @@ if playerClass == "PRIEST" then
--// Use Flash Heal for range check. Usual UnitInRange is about 38yd, not 41, tho it's probably good to have that margin. Disabled by default.

DispelTypes("MAGIC|DISEASE")

config.SmartHeals = {
[2] = { -- holy
[1] = { -- Prayer of Healing
spellID = 596,
range = 19.5 ^ 2,
maxtargets = 5,
color = {0.5,0.5,1}
},
-- [2] = { -- Circle of Healing
-- spellID = 204883,
-- range = 30 ^ 2,
-- maxtargets = 5,
-- color = {1,1,0}
-- },
}
}
end

if playerClass == "MONK" then
Expand All @@ -187,6 +206,17 @@ if playerClass == "MONK" then
--// Use Detox for range check. Usual UnitInRange is about 38yd, not 41, tho it's probably good to have that margin. Disabled by default.

DispelTypes("MAGIC|DISEASE|POISON")

config.SmartHeals = {
[2] = { -- Mistweaver
[1] = { -- Vivify
spellID = 116670,
range = 40 ^ 2,
maxtargets = 3,
color = {38/255, 221/255, 163/255}
},
}
}
end

if playerClass == "WARLOCK" then
Expand Down Expand Up @@ -268,6 +298,17 @@ if playerClass == "DRUID" then
--// Use Rejuvenation for range check. Usual UnitInRange is about 38yd, not 41, tho it's probably good to have that margin. Disabled by default.

DispelTypes("MAGIC|CURSE|POISON")

config.SmartHeals = {
[4] = { -- Restoratin
[1] = { -- Wild Growth
spellID = 48438,
range = 30 ^ 2,
maxtargets = 6,
color = { 0.4, 1, 0.4}
},
}
}
end
if playerClass == "MAGE" then
--A{ id = 1459, type = "HELPFUL", assignto = { "spell2" }, color = { .4 , .4, 1}, priority = 50 } --Arcane Intellect
Expand Down
11 changes: 11 additions & 0 deletions frame.lua
Expand Up @@ -775,6 +775,16 @@ AptechkaDefaultConfig.GridSkin = function(self)
-- roleicontex:SetVertexColor(0,0,0,0.2)
roleicon.texture = roleicontex

local aoemarker = hp:CreateTexture(nil, "ARTWORK")
aoemarker:SetDrawLayer("ARTWORK", 5)
aoemarker:SetTexture("Interface\\Addons\\Aptechka\\white")
aoemarker:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT",0,0)
aoemarker:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT",0,0)
aoemarker:SetHeight(1.5)
aoemarker:SetVertexColor(1,1,0)
aoemarker:Hide()



local topind = CreateIndicator(self,10,10,"TOP",self,"TOP",0,0)
local tr = CreateIndicator(self,10,10,"TOPRIGHT",self,"TOPRIGHT",0,0)
Expand Down Expand Up @@ -822,6 +832,7 @@ AptechkaDefaultConfig.GridSkin = function(self)
self.roleicon = roleicon
self.absorb = absorb
self.centericon = centericon
self.smartheal = aoemarker


self.OnMouseEnterFunc = OnMouseEnterFunc
Expand Down

0 comments on commit 5888941

Please sign in to comment.