local core = CreateFrame("Frame")
core:SetScript("OnEvent", function(self, event, ...)
self[event](self, event, ...)
end)
core.CreatedPlates = {}
core.MindHarvest = {}
core.ByBossName = {}
core.ByName = {}
local numChildren = -1
local twipe = table.wipe
local tsort = table.sort
local tinsert = table.insert
local band = bit.band
local gsub = string.gsub
local tolower = string.lower
local match = string.match
core.RaidTargetReference = {
["STAR"] = 0x00000001,
["CIRCLE"] = 0x00000002,
["DIAMOND"] = 0x00000004,
["TRIANGLE"] = 0x00000008,
["MOON"] = 0x00000010,
["SQUARE"] = 0x00000020,
["CROSS"] = 0x00000040,
["SKULL"] = 0x00000080,
}
core.ByRaidIcon = {}
core.RaidIconCoordinate = {
[0] = { [0] = "STAR", [0.25] = "MOON", },
[0.25] = { [0] = "CIRCLE", [0.25] = "SQUARE", },
[0.5] = { [0] = "DIAMOND", [0.25] = "CROSS", },
[0.75] = { [0] = "TRIANGLE", [0.25] = "SKULL", },
}
local flagtort = {
[COMBATLOG_OBJECT_RAIDTARGET8] = "SKULL",
[COMBATLOG_OBJECT_RAIDTARGET7] = "CROSS",
[COMBATLOG_OBJECT_RAIDTARGET6] = "SQUARE",
[COMBATLOG_OBJECT_RAIDTARGET5] = "MOON",
[COMBATLOG_OBJECT_RAIDTARGET4] = "TRIANGLE",
[COMBATLOG_OBJECT_RAIDTARGET3] = "DIAMOND",
[COMBATLOG_OBJECT_RAIDTARGET2] = "CIRCLE",
[COMBATLOG_OBJECT_RAIDTARGET1] = "STAR",
}
local blacklist = {}
function core:CheckFilter(myPlate)
local name = gsub(self.mindHarvest.name:GetText(), '%s%(%*%)','')
local db = blacklist[name]
if db and db.enable then
if db.hide then
myPlate:Hide()
return
else
if(not myPlate:IsShown()) then
myPlate:Show()
end
end
elseif(not myPlate:IsShown()) then
myPlate:Show()
end
return true
end
function core:ScanFrames(...)
for index = 1, select('#', ...) do
local frame = select(index, ...)
local name = frame:GetName()
if(not core.CreatedPlates[frame] and (name and name:find("NamePlate%d"))) then
core:CreatePlate(frame)
end
end
end
function core:UpdateMindHarvestStatus(frame)
if frame.mindHarvest.guid and core.MindHarvest[frame.mindHarvest.guid] then
frame.mindHarvest:Hide()
else
frame.mindHarvest:Show()
if frame.mindHarvest.guid then
frame.mindHarvest.status:SetText("|cff66ff00+|r")
else
frame.mindHarvest.status:SetText("|cffff0000?|r")
end
end
end
function core:SetUnitInfo(myPlate)
local plateName = gsub(self.mindHarvest.name:GetText(), '%s%(%*%)','')
if self:GetAlpha() == 1 and core.targetName and (core.targetName == plateName) then
self.mindHarvest.guid = UnitGUID("target")
self.mindHarvest.unit = "target"
core:UpdateMindHarvestStatus(self)
self.mindHarvest:SetFrameLevel(2)
if((core.NumTargetChecks > -1) or self.mindHarvest.allowCheck) then
core.NumTargetChecks = core.NumTargetChecks + 1
if core.NumTargetChecks > 0 then
core.NumTargetChecks = -1
end
self.mindHarvest.allowCheck = nil
end
elseif self.mindHarvest.highlight:IsShown() and UnitExists("mouseover") and (UnitName("mouseover") == plateName) then
self.mindHarvest.guid = UnitGUID("mouseover")
if(self.mindHarvest.unit ~= "mouseover" or self.mindHarvest.allowCheck) then
self.mindHarvest.allowCheck = nil
end
core:UpdateMindHarvestStatus(self)
self.mindHarvest:SetFrameLevel(1)
self.mindHarvest.unit = "mouseover"
else
self.mindHarvest.unit = nil
self.mindHarvest:SetFrameLevel(0)
core:UpdateMindHarvestStatus(self)
end
end
function core:OnHide()
local myPlate = core.CreatedPlates[self]
self.mindHarvest.unitType = nil
self.mindHarvest.guid = nil
self.mindHarvest.unit = nil
self.mindHarvest.allowCheck = nil
myPlate:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT") --Prevent nameplate being in random location on screen when first shown
end
function core:OnShow()
local myPlate = core.CreatedPlates[self]
if(not core.CheckFilter(self, myPlate)) then return end
core.ColorizeAndScale(self, myPlate)
core:CheckRaidIcon(self)
self.mindHarvest.allowCheck = true
end
function core:CreatePlate(frame)
local mindHarvest = CreateFrame("Frame", nil, self.ParentFrame)
mindHarvest:SetSize(18, 18)
mindHarvest.barFrame, mindHarvest.nameFrame = frame:GetChildren()
mindHarvest.healthBar = mindHarvest.barFrame:GetChildren()
mindHarvest.threat, _, mindHarvest.highlight, _, mindHarvest.bossIcon, mindHarvest.raidIcon = mindHarvest.barFrame:GetRegions()
mindHarvest.name = mindHarvest.nameFrame:GetRegions()
if not mindHarvest.raidIcon and frame.icon then
mindHarvest.raidIcon = frame.icon
end
if(self.viewPort) then
mindHarvest:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT")
end
mindHarvest:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT")
mindHarvest:SetFrameStrata("BACKGROUND")
mindHarvest:SetFrameLevel(0)
mindHarvest:SetScale(0.7) -- update
mindHarvest.iconf = CreateFrame("Frame", nil, mindHarvest)
mindHarvest.iconf:SetSize(18, 18)
mindHarvest.iconf:SetPoint("BOTTOMLEFT", mindHarvest, "TOPLEFT", 0, 20)
mindHarvest.icon = mindHarvest.iconf:CreateTexture(nil, 'OVERLAY')
mindHarvest.icon:SetTexCoord(.1, .9, .2, .8)
mindHarvest.icon:SetTexture("Interface\\icons\\spell_warlock_harvestoflife")
mindHarvest.icon:SetAllPoints(mindHarvest.iconf)
mindHarvest.status = mindHarvest.iconf:CreateFontString(nil, 'OVERLAY')
mindHarvest.status:SetPoint("CENTER", mindHarvest.iconf, "CENTER", 1, -1)
mindHarvest.status:SetJustifyH("LEFT")
mindHarvest.status:SetFont(STANDARD_TEXT_FONT, 16, "THICKOUTLINE")
mindHarvest.status:SetText("TEST")
mindHarvest:Show()
frame.mindHarvest = mindHarvest
frame:HookScript("OnShow", core.OnShow)
frame:HookScript("OnHide", core.OnHide)
self.CreatedPlates[frame] = mindHarvest
end
function core:SetAlpha(plate)
if self:GetAlpha() < 1 then
plate:SetAlpha(0.7)
else
plate:SetAlpha(1)
end
end
function core:OnUpdate(elapsed)
local count = WorldFrame:GetNumChildren()
if(count ~= numChildren) then
numChildren = count
core:ScanFrames(WorldFrame:GetChildren())
end
core.PlateParent:Hide()
for blizzPlate, plate in pairs(core.CreatedPlates) do
if(blizzPlate:IsShown()) then
if(not self.viewPort) then
plate:SetPoint("CENTER", WorldFrame, "BOTTOMLEFT", blizzPlate:GetCenter())
end
core.SetAlpha(blizzPlate, plate)
else
plate:Hide()
end
end
core.PlateParent:Show()
if(self.mindharvest and self.mindharvest > 0.2) then
for blizzPlate, plate in pairs(core.CreatedPlates) do
if(blizzPlate:IsShown() and plate:IsShown()) then
core.SetUnitInfo(blizzPlate, plate)
core.ColorizeAndScale(blizzPlate, plate)
end
end
self.mindharvest = 0
else
self.mindharvest = (self.mindharvest or 0) + elapsed
end
end
function core:RoundColors(r, g, b)
return floor(r*100+.5)/100, floor(g*100+.5)/100, floor(b*100+.5)/100
end
function core:GetReaction(frame)
local r, g, b = core:RoundColors(frame.mindHarvest.healthBar:GetStatusBarColor())
for class, _ in pairs(RAID_CLASS_COLORS) do
local bb = b
if class == 'MONK' then
bb = bb - 0.01
end
if RAID_CLASS_COLORS[class].r == r and RAID_CLASS_COLORS[class].g == g and RAID_CLASS_COLORS[class].b == bb then
return class
end
end
if (r + b + b) == 1.59 then
return 'TAPPED_NPC'
elseif g + b == 0 then
return 'HOSTILE_NPC'
elseif r + b == 0 then
return 'FRIENDLY_NPC'
elseif r + g > 1.95 then
return 'NEUTRAL_NPC'
elseif r + g == 0 then
return 'FRIENDLY_PLAYER'
else
return 'HOSTILE_PLAYER'
end
end
function core:ColorizeAndScale(myPlate)
self.mindHarvest.unitType = core:GetReaction(self)
end
core:RegisterEvent("PLAYER_LOGIN")
function core:UPDATE_MOUSEOVER_UNIT()
WorldFrame.mindharvest = 0.1
end
function core:PLAYER_TARGET_CHANGED()
if(UnitExists("target")) then
self.targetName = UnitName("target")
WorldFrame.mindharvest = 0.1
core.NumTargetChecks = 0
else
self.targetName = nil
end
end
function core:INSTANCE_ENCOUNTER_ENGAGE_UNIT()
for i=1, MAX_BOSS_FRAMES do
local unit = format("boss%d", i)
if UnitExists(unit) then --and UnitClassification(unit) == "worldboss" then
core.ByBossName[UnitName(unit)] = UnitGUID(unit)
end
end
end
function core:ARENA_OPPONENT_UPDATE()
for i=1, 5 do
local unit = format("arena%d", i)
if UnitExists(unit) then --and UnitClassification(unit) == "worldboss" then
core.ByName[UnitName(unit)] = UnitGUID(unit)
end
end
end
local function MindHarvestAssist(destGUID,destName,destFlags,destRaidFlags)
if destGUID and not core.MindHarvest[destGUID] then
local name, raidIcon
if band(destFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) > 0 and destName then
local rawName = strsplit("-", destName) -- Strip server name from players
core.ByName[rawName] = destGUID
name = rawName
end
if flagtort[destRaidFlags] then
core.ByRaidIcon[flagtort[destRaidFlags]] = destGUID
raidIcon = flagtort[destRaidFlags]
end
if core.ByBossName[destName] and destName then
name = destName
end
core.MindHarvest[destGUID] = true
end
end
function core:COMBAT_LOG_EVENT_UNFILTERED(_, _, event, ...)
local _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName, _, auraType, stackCount = ...
if event == "SPELL_DAMAGE" and sourceGUID == UnitGUID("player") and spellID == 8092 then
MindHarvestAssist(destGUID,destName,destFlags,destRaidFlags)
end
if event == "SPELL_AURA_APPLIED" or
event == "SPELL_AURA_REFRESH" or
event == "SPELL_AURA_APPLIED_DOSE" or
event == "SPELL_AURA_REMOVED_DOSE" or
event == "SPELL_AURA_BROKEN" or
event == "SPELL_AURA_BROKEN_SPELL" or
event == "SPELL_AURA_REMOVED" then
local name, raidIcon
if band(destFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) > 0 and destName then
local rawName = strsplit("-", destName) -- Strip server name from players
core.ByName[rawName] = destGUID
end
if flagtort[destRaidFlags] then
core.ByRaidIcon[flagtort[destRaidFlags]] = destGUID
raidIcon = flagtort[destRaidFlags]
end
end
end
function core:PLAYER_LOGIN()
self.PlateParent = CreateFrame("Frame", nil, WorldFrame)
self.PlateParent:SetFrameStrata("BACKGROUND")
self.PlateParent:SetFrameLevel(0)
WorldFrame:HookScript('OnUpdate', core.OnUpdate)
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
self:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
self:RegisterEvent("ARENA_OPPONENT_UPDATE")
end
function core:CheckRaidIcon(frame)
if frame.mindHarvest.raidIcon:IsShown() then
local ux, uy = frame.mindHarvest.raidIcon:GetTexCoord()
frame.mindHarvest.raidIconType = core.RaidIconCoordinate[ux][uy]
else
frame.mindHarvest.raidIconType = nil;
end
end
function core:SearchNameplateByGUID(guid)
for frame, _ in pairs(core.CreatedPlates) do
if frame and frame:IsShown() and frame.mindHarvest.guid == guid then
return frame
end
end
end
function core:SearchNameplateByName(sourceName)
if not sourceName then return; end
local SearchFor = strsplit("-", sourceName)
for frame, myPlate in pairs(core.CreatedPlates) do
if frame and frame:IsShown() then
if ( myPlate.mindHarvest.nameText == SearchFor and RAID_CLASS_COLORS[frame.mindHarvest.unitType] ) then
return frame
elseif ( core.ByBossName[sourceName] and frame.mindHarvest.name:GetText() == sourceName ) then
return frame
end
end
end
end
function core:SearchNameplateByIconName(raidIcon)
for frame, _ in pairs(core.CreatedPlates) do
core:CheckRaidIcon(frame)
if frame and frame:IsShown() and frame.mindHarvest.raidIcon:IsShown() and (frame.mindHarvest.raidIconType == raidIcon) then
return frame
end
end
end
function core:SearchForFrame(guid, raidIcon, name)
local frame
if guid then frame = self:SearchNameplateByGUID(guid) end
if (not frame) and name then frame = self:SearchNameplateByName(name) end
if (not frame) and raidIcon then frame = self:SearchNameplateByIconName(raidIcon) end
end