mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-10 07:30:01 +00:00
classicapi migration
This commit is contained in:
+6
-334
@@ -6,16 +6,6 @@ pfUI:RegisterModule("nampower", function ()
|
||||
-- Only load if Nampower is available
|
||||
if not GetNampowerVersion then return end
|
||||
|
||||
-- Safe wrapper for GetSpellNameAndRankForId (may not be available)
|
||||
local function SafeGetSpellNameAndRank(spellId)
|
||||
if not GetSpellNameAndRankForId then return nil, nil end
|
||||
local success, name, rank = pcall(GetSpellNameAndRankForId, spellId)
|
||||
if success then
|
||||
return name, rank
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
local rawborder, border = GetBorderSize()
|
||||
|
||||
-- Spell Queue Indicator
|
||||
@@ -67,13 +57,7 @@ pfUI:RegisterModule("nampower", function ()
|
||||
local spellId = arg2
|
||||
|
||||
if eventCode == NORMAL_QUEUED or eventCode == NON_GCD_QUEUED or eventCode == ON_SWING_QUEUED then
|
||||
-- Get spell texture from GetSpellRec (Nampower)
|
||||
local texture
|
||||
if GetSpellRec then
|
||||
local rec = GetSpellRec(spellId)
|
||||
texture = rec and rec.spellIconID and GetSpellIconTexture(rec.spellIconID) or nil
|
||||
end
|
||||
|
||||
local texture = C_Spell.GetSpellTexture(spellId)
|
||||
if texture then
|
||||
pfUI.spellqueue.icon:SetTexture(texture)
|
||||
pfUI.spellqueue:Show()
|
||||
@@ -86,78 +70,9 @@ pfUI:RegisterModule("nampower", function ()
|
||||
|
||||
-- NOTE: Buff tracking removed - was dead code (data collected but never used for display)
|
||||
|
||||
-- Direct Aura Access API using GetUnitField
|
||||
-- Much faster than tooltip scanning - reads aura arrays directly from unit fields
|
||||
if GetUnitField then
|
||||
pfUI.api.GetUnitAuras = function(unit)
|
||||
local auras = GetUnitField(unit, "aura")
|
||||
local auraLevels = GetUnitField(unit, "auraLevels")
|
||||
local auraStacks = GetUnitField(unit, "auraApplications")
|
||||
|
||||
if not auras then return nil end
|
||||
|
||||
local result = {}
|
||||
for i = 1, 48 do
|
||||
local spellId = auras[i]
|
||||
if spellId and spellId > 0 then
|
||||
local name, rank, texture
|
||||
if GetSpellRec then
|
||||
local rec = GetSpellRec(spellId)
|
||||
if rec then
|
||||
name = rec.name
|
||||
rank = rec.rank
|
||||
local iconID = rec.spellIconID
|
||||
texture = iconID and GetSpellIconTexture(iconID) or nil
|
||||
end
|
||||
|
||||
end
|
||||
if not name then
|
||||
name, rank = SafeGetSpellNameAndRank(spellId)
|
||||
end
|
||||
|
||||
result[i] = {
|
||||
spellId = spellId,
|
||||
name = name,
|
||||
rank = rank,
|
||||
texture = texture,
|
||||
level = auraLevels and auraLevels[i] or 0,
|
||||
stacks = auraStacks and auraStacks[i] or 1,
|
||||
isBuff = i <= 32, -- First 32 slots are buffs, rest are debuffs
|
||||
}
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Quick check if unit has specific aura by spellId
|
||||
pfUI.api.UnitHasAura = function(unit, spellId)
|
||||
local auras = GetUnitField(unit, "aura")
|
||||
if not auras then return false end
|
||||
for i = 1, 48 do
|
||||
if auras[i] == spellId then return true, i end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Get unit resistances directly
|
||||
pfUI.api.GetUnitResistances = function(unit)
|
||||
local res = GetUnitField(unit, "resistances")
|
||||
if not res then return nil end
|
||||
return {
|
||||
armor = res[1] or 0,
|
||||
holy = res[2] or 0,
|
||||
fire = res[3] or 0,
|
||||
nature = res[4] or 0,
|
||||
frost = res[5] or 0,
|
||||
shadow = res[6] or 0,
|
||||
arcane = res[7] or 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- Reactive Spell Indicator using IsSpellUsable
|
||||
-- Reactive Spell Indicator using C_Spell.IsSpellUsable
|
||||
-- Shows when reactive abilities like Overpower, Revenge, Execute are usable
|
||||
if IsSpellUsable and C.unitframes.reactive_indicator == "1" then
|
||||
if C.unitframes.reactive_indicator == "1" then
|
||||
local size = tonumber(C.unitframes.reactive_size) or 28
|
||||
local _, class = UnitClass("player")
|
||||
|
||||
@@ -216,8 +131,8 @@ pfUI:RegisterModule("nampower", function ()
|
||||
pfUI.reactive:SetScript("OnUpdate", function()
|
||||
local anyVisible = false
|
||||
for _, icon in ipairs(this.icons) do
|
||||
local usable = IsSpellUsable(icon.spellName)
|
||||
if usable == 1 then
|
||||
local usable = C_Spell.IsSpellUsable(icon.spellName)
|
||||
if usable then
|
||||
icon:Show()
|
||||
anyVisible = true
|
||||
else
|
||||
@@ -233,251 +148,8 @@ pfUI:RegisterModule("nampower", function ()
|
||||
end
|
||||
end
|
||||
|
||||
-- Enhanced Cooldown Tracking API using GetSpellIdCooldown
|
||||
if GetSpellIdCooldown then
|
||||
pfUI.api.GetPreciseCooldown = function(spellId)
|
||||
local cd = GetSpellIdCooldown(spellId)
|
||||
if not cd then return nil end
|
||||
return {
|
||||
onCooldown = (cd.isOnCooldown or 0) == 1,
|
||||
remaining = (cd.cooldownRemainingMs or 0) / 1000,
|
||||
remainingMs = cd.cooldownRemainingMs or 0,
|
||||
gcdRemaining = (cd.gcdCategoryRemainingMs or 0) / 1000,
|
||||
gcdRemainingMs = cd.gcdCategoryRemainingMs or 0,
|
||||
individualRemaining = (cd.individualRemainingMs or 0) / 1000,
|
||||
categoryRemaining = (cd.categoryRemainingMs or 0) / 1000,
|
||||
}
|
||||
end
|
||||
|
||||
-- Item cooldown helper
|
||||
pfUI.api.GetPreciseItemCooldown = function(itemId)
|
||||
if not GetItemIdCooldown then return nil end
|
||||
local cd = GetItemIdCooldown(itemId)
|
||||
if not cd then return nil end
|
||||
return {
|
||||
onCooldown = (cd.isOnCooldown or 0) == 1,
|
||||
remaining = (cd.cooldownRemainingMs or 0) / 1000,
|
||||
remainingMs = cd.cooldownRemainingMs or 0,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- UNIT_DIED event handling - placeholder for future use
|
||||
-- (Debuff/buff cleanup removed as tracking is now handled by libdebuff)
|
||||
|
||||
-- Trinket Management API
|
||||
if GetTrinkets then
|
||||
pfUI.api.GetEquippedTrinkets = function()
|
||||
local trinkets = GetTrinkets()
|
||||
if not trinkets then return {} end
|
||||
local equipped = {}
|
||||
for _, trinket in pairs(trinkets) do
|
||||
if trinket and trinket.bagIndex == nil then -- nil bagIndex = equipped
|
||||
table.insert(equipped, trinket)
|
||||
end
|
||||
end
|
||||
return equipped
|
||||
end
|
||||
|
||||
pfUI.api.GetTrinketCooldown = function(slot)
|
||||
if not GetTrinketCooldown then return nil end
|
||||
local cd = GetTrinketCooldown(slot)
|
||||
if cd == -1 or not cd then return nil end
|
||||
return {
|
||||
onCooldown = (cd.isOnCooldown or 0) == 1,
|
||||
remaining = (cd.cooldownRemainingMs or 0) / 1000,
|
||||
remainingMs = cd.cooldownRemainingMs or 0,
|
||||
}
|
||||
end
|
||||
|
||||
pfUI.api.UseTrinket = function(slot, target)
|
||||
if not UseTrinket then return false end
|
||||
return UseTrinket(slot, target) == 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Nampower Item Stats API (use distinct name to avoid conflicts)
|
||||
if GetItemStats then
|
||||
pfUI.api.GetNampowerItemStats = function(itemId)
|
||||
local success, stats = pcall(GetItemStats, itemId, true)
|
||||
if not success or not stats then return nil end
|
||||
return stats
|
||||
end
|
||||
|
||||
-- Quick item level lookup
|
||||
pfUI.api.GetNampowerItemLevel = function(itemId)
|
||||
if GetItemLevel then
|
||||
return GetItemLevel(itemId)
|
||||
end
|
||||
local success, stats = pcall(GetItemStats, itemId, true)
|
||||
if success and stats and stats.itemLevel then
|
||||
return stats.itemLevel
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Spell Modifiers API for damage/heal predictions
|
||||
if GetSpellModifiers then
|
||||
pfUI.api.GetSpellBonus = function(spellId, modType)
|
||||
-- modType: 0=DAMAGE, 1=DURATION, 6=RADIUS, 7=CRIT, 10=CAST_TIME, 14=COST, etc.
|
||||
local flat, percent, hasmod = GetSpellModifiers(spellId, modType or 0)
|
||||
return {
|
||||
flat = flat or 0,
|
||||
percent = percent or 0,
|
||||
hasModifier = hasmod and hasmod ~= 0,
|
||||
}
|
||||
end
|
||||
|
||||
-- Common spell modifier lookups
|
||||
pfUI.api.GetSpellDamageBonus = function(spellId)
|
||||
return pfUI.api.GetSpellBonus(spellId, 0) -- DAMAGE
|
||||
end
|
||||
|
||||
pfUI.api.GetSpellCritBonus = function(spellId)
|
||||
return pfUI.api.GetSpellBonus(spellId, 7) -- CRITICAL_CHANCE
|
||||
end
|
||||
|
||||
pfUI.api.GetSpellCostReduction = function(spellId)
|
||||
return pfUI.api.GetSpellBonus(spellId, 14) -- COST
|
||||
end
|
||||
end
|
||||
|
||||
-- Inventory/Bag API
|
||||
if GetBagItems then
|
||||
pfUI.api.GetAllBagItems = function()
|
||||
return GetBagItems()
|
||||
end
|
||||
|
||||
pfUI.api.FindItem = function(itemIdOrName)
|
||||
if FindPlayerItemSlot then
|
||||
local bag, slot = FindPlayerItemSlot(itemIdOrName)
|
||||
return bag, slot
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
pfUI.api.UseItem = function(itemIdOrName, target)
|
||||
if UseItemIdOrName then
|
||||
return UseItemIdOrName(itemIdOrName, target) == 1
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Equipment Inspection API
|
||||
if GetEquippedItems then
|
||||
pfUI.api.GetPlayerEquipment = function()
|
||||
return GetEquippedItems("player")
|
||||
end
|
||||
|
||||
pfUI.api.GetTargetEquipment = function()
|
||||
return GetEquippedItems("target")
|
||||
end
|
||||
|
||||
pfUI.api.GetEquippedItemInfo = function(unit, slot)
|
||||
if GetEquippedItem then
|
||||
return GetEquippedItem(unit, slot)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Spell Lookup Helpers
|
||||
if GetSpellIdForName then
|
||||
pfUI.api.GetMaxRankSpellId = function(spellName)
|
||||
return GetSpellIdForName(spellName)
|
||||
end
|
||||
end
|
||||
|
||||
if GetSpellSlotTypeIdForName then
|
||||
pfUI.api.GetSpellSlotInfo = function(spellName)
|
||||
local slot, bookType, spellId = GetSpellSlotTypeIdForName(spellName)
|
||||
return {
|
||||
slot = slot,
|
||||
bookType = bookType,
|
||||
spellId = spellId,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- Queue Script API for advanced macro functionality
|
||||
if QueueScript then
|
||||
pfUI.api.QueueLuaScript = function(script, priority)
|
||||
QueueScript(script, priority or 1)
|
||||
end
|
||||
end
|
||||
|
||||
if QueueSpellByName then
|
||||
pfUI.api.QueueSpell = function(spellName)
|
||||
QueueSpellByName(spellName)
|
||||
end
|
||||
end
|
||||
|
||||
-- Channel optimization
|
||||
if ChannelStopCastingNextTick then
|
||||
pfUI.api.StopChannelNextTick = function()
|
||||
ChannelStopCastingNextTick()
|
||||
end
|
||||
end
|
||||
|
||||
-- Spell Database Access via GetSpellRec
|
||||
if GetSpellRec then
|
||||
pfUI.api.GetSpellRecord = function(spellId)
|
||||
local success, rec = pcall(GetSpellRec, spellId)
|
||||
if not success or not rec then return nil end
|
||||
return {
|
||||
spellId = spellId,
|
||||
name = rec.name or "",
|
||||
rank = rec.rank or "",
|
||||
description = rec.description or "",
|
||||
manaCost = rec.manaCost or 0,
|
||||
baseLevel = rec.baseLevel or 0,
|
||||
spellLevel = rec.spellLevel or 0,
|
||||
maxLevel = rec.maxLevel or 0,
|
||||
maxTargetLevel = rec.maxTargetLevel or 0,
|
||||
maxTargets = rec.maxTargets or 0,
|
||||
durationIndex = rec.durationIndex or 0,
|
||||
powerType = rec.powerType or 0,
|
||||
rangeIndex = rec.rangeIndex or 0,
|
||||
speed = rec.speed or 0,
|
||||
schoolMask = rec.schoolMask or 0,
|
||||
runeCostID = rec.runeCostID or 0,
|
||||
spellMissileID = rec.spellMissileID or 0,
|
||||
iconID = rec.iconID or 0,
|
||||
activeIconID = rec.activeIconID or 0,
|
||||
nameSubtext = rec.nameSubtext or "",
|
||||
castingTimeIndex = rec.castingTimeIndex or 0,
|
||||
categoryRecoveryTime = rec.categoryRecoveryTime or 0,
|
||||
recoveryTime = rec.recoveryTime or 0,
|
||||
startRecoveryCategory = rec.startRecoveryCategory or 0,
|
||||
startRecoveryTime = rec.startRecoveryTime or 0,
|
||||
}
|
||||
end
|
||||
|
||||
-- Get spell school (fire, frost, nature, etc.)
|
||||
pfUI.api.GetSpellSchool = function(spellId)
|
||||
local success, rec = pcall(GetSpellRec, spellId)
|
||||
if not success or not rec or not rec.schoolMask then return nil end
|
||||
local schools = {
|
||||
[1] = "Physical",
|
||||
[2] = "Holy",
|
||||
[4] = "Fire",
|
||||
[8] = "Nature",
|
||||
[16] = "Frost",
|
||||
[32] = "Shadow",
|
||||
[64] = "Arcane",
|
||||
}
|
||||
return schools[rec.schoolMask] or "Unknown"
|
||||
end
|
||||
end
|
||||
|
||||
-- Disenchant All utility
|
||||
-- /disenchantall slash command (DisenchantAll is Nampower-provided)
|
||||
if DisenchantAll then
|
||||
pfUI.api.DisenchantAllItems = function()
|
||||
DisenchantAll()
|
||||
end
|
||||
|
||||
SLASH_PFDISENCHANTALL1 = "/disenchantall"
|
||||
SLASH_PFDISENCHANTALL2 = "/dea"
|
||||
SlashCmdList["PFDISENCHANTALL"] = function()
|
||||
|
||||
Reference in New Issue
Block a user