Implement group and nameplate search

This commit is contained in:
PhatDave
2022-01-04 19:04:39 +01:00
parent 06b11f955c
commit 808d3ba96b
2 changed files with 162 additions and 22 deletions

View File

@@ -0,0 +1,11 @@
function()
if aura_env.state.pname then
output = ""
if aura_env.state.pclass then
output = aura_env.GetClassColor(aura_env.state.pclass) .. aura_env.state.pname .. "\124r"
else
output = aura_env.state.pname
end
return output
end
end

View File

@@ -12,12 +12,133 @@ local function PrintTable(table)
end end
end end
aura_env.GetClassColor = function(class)
if class == "Death Knight" then
return "\124cFFC41E3A"
elseif class == "Druid" then
return "\124cFFFF7C0A"
elseif class == "Hunter" then
return "\124cFFAAD372"
elseif class == "Mage" then
return "\124cFF3FC7EB"
elseif class == "Paladin" then
return "\124cFFF48CBA"
elseif class == "Priest" then
return "\124cFFFFFFFF"
elseif class == "Rogue" then
return "\124cFFFFF468"
elseif class == "Shaman" then
return "\124cFF0070DD"
elseif class == "Warlock" then
return "\124cFF8788EE"
elseif class == "Warrior" then
return "\124cFFC69B6D"
end
end
local Unit = {
New = function(self, unit)
o = {
["unit"] = unit,
}
setmetatable(o, self)
self.__index = self
return o
end,
GetAuras = function(self, auraFunc, name, type)
return nil
end,
}
local BasicUnit = Unit:New("player")
function BasicUnit:GetAuras(auraFunc, name)
local aura, _, _, _, _, duration, expirationTime, _, _, _, spellID = auraFunc(self.unit, name)
return {
[UnitName(self.unit)] = {
["duration"] = duration,
["expirationTime"] = expirationTime,
["spellID"] = spellID,
}
}
end
-- Maybe implement some sort of throttle to group unit?
local GroupUnit = Unit:New("group")
function GroupUnit:GetAuras(auraFunc, name)
local raidMem = GetNumRaidMembers()
local num = GetNumPartyMembers()
local unitPrefix = "party"
if raidMem > num then
unitPrefix = "raid"
num = raidMem
end
auras = {}
for i = 1, num do
local aura, _, _, _, _, duration, expirationTime, _, _, _, spellID = auraFunc(unitPrefix .. i, name)
if aura ~= nil then
auras[UnitName(unitPrefix .. i)] = {
["duration"] = duration,
["expirationTime"] = expirationTime,
["spellID"] = spellID,
["class"] = UnitClass(unitPrefix .. i) or "Paladin",
}
end
end
if unitPrefix == "party" then
local aura, _, _, _, _, duration, expirationTime, _, _, _, spellID = auraFunc("player", name)
if aura ~= nil then
auras[UnitName("player")] = {
["duration"] = duration,
["expirationTime"] = expirationTime,
["spellID"] = spellID,
["class"] = UnitClass(unitPrefix .. i) or "Paladin",
}
end
end
return auras
end
local NameplateUnit = Unit:New("nameplate")
function NameplateUnit:GetAuras(auraFunc, name)
local unitPrefix = "nameplate"
auras = {}
for i = 1, 40 do
local aura, _, _, _, _, duration, expirationTime, _, _, _, spellID = auraFunc(auraPrefix .. i, name)
if aura ~= nil then
auras[UnitName(unitPrefix .. i)] = {
["duration"] = duration,
["expirationTime"] = expirationTime,
["spellID"] = spellID,
}
end
end
return auras
end
local UnitFactory = {
New = function(self)
o = {}
setmetatable(o, self)
self.__index = self
return o
end,
CreateUnit = function(self, target)
target = string.lower(target)
if target == "player" or target == "target" or target == "focus" then
return BasicUnit:New(target)
elseif target == "group" then
return GroupUnit:New(target)
elseif target == "nameplate" then
return NameplateUnit:New(target)
end
end,
}
local unitFactory = UnitFactory:New()
local Aura = { local Aura = {
New = function(self, entry, index) New = function(self, entry, index)
o = { o = {
["name"] = entry.auraName, ["name"] = entry.auraName,
["type"] = entry.auraType, ["unit"] = entry.target,
["target"] = entry.target,
["hasCooldown"] = entry.hasCooldown, ["hasCooldown"] = entry.hasCooldown,
["index"] = index, ["index"] = index,
["GetAura"] = entry.GetAura, ["GetAura"] = entry.GetAura,
@@ -28,7 +149,10 @@ local Aura = {
end, end,
IsActive = function(self) IsActive = function(self)
return self.GetAura(self.target, self.name, self.type) ~= nil for k,v in pairs(self.unit:GetAuras(self.GetAura, self.name)) do
return true
end
return false
end, end,
IsOnCooldown = function(self) IsOnCooldown = function(self)
if not self.hasCooldown then if not self.hasCooldown then
@@ -38,22 +162,28 @@ local Aura = {
end, end,
AddAsAura = function(self, allstates) AddAsAura = function(self, allstates)
duration = select(6, self.GetAura(self.target, self.name, self.type)) local auras = self.unit:GetAuras(self.GetAura, self.name)
expirationTime = select(7, self.GetAura(self.target, self.name, self.type)) for k,v in pairs(auras) do
icon = self:GetAuraIcon() print(k, v)
allstates[self.name] = { duration = v.duration
changed = true, expirationTime = v.expirationTime
show = true, icon = self:GetAuraIcon(v.spellID)
resort = true, allstates[self.name .. k] = {
progressType = "timed", changed = true,
duration = duration, show = true,
expirationTime = expirationTime, resort = true,
index = self.index, progressType = "timed",
icon = icon, duration = duration,
IsOnCooldown = true, expirationTime = expirationTime,
IsActive = true, index = self.index,
IsBad = self.GetAura == UnitDebuff, icon = icon,
} pname = k,
pclass = v.class,
IsOnCooldown = true,
IsActive = true,
IsBad = self.GetAura == UnitDebuff,
}
end
end, end,
AddAsCooldown = function(self, allstates) AddAsCooldown = function(self, allstates)
if not self.hasCooldown then if not self.hasCooldown then
@@ -98,8 +228,7 @@ local Aura = {
GetSpellIcon = function(self) GetSpellIcon = function(self)
return select(3, GetSpellInfo(self.name)) return select(3, GetSpellInfo(self.name))
end, end,
GetAuraIcon = function(self) GetAuraIcon = function(self, spellID)
spellID = select(11, self.GetAura(self.target, self.name, self.type))
return select(3, GetSpellInfo(spellID)) return select(3, GetSpellInfo(spellID))
end, end,
} }
@@ -111,7 +240,7 @@ local Entry = {
local entryData = StrSplit(entry, ",") local entryData = StrSplit(entry, ",")
local name = self:ReadEntryData(entryData, 1) local name = self:ReadEntryData(entryData, 1)
local type = self:ReadEntryData(entryData, 2) or "Buff" local type = self:ReadEntryData(entryData, 2) or "Buff"
local target = self:ReadEntryData(entryData, 3) or "Player" local target = unitFactory:CreateUnit(self:ReadEntryData(entryData, 3) or "Player")
local cooldown = (self:ReadEntryData(entryData, 4) == "0") or false local cooldown = (self:ReadEntryData(entryData, 4) == "0") or false
cooldown = not cooldown cooldown = not cooldown
local GetAura = UnitBuff local GetAura = UnitBuff