classicapi migration

This commit is contained in:
Brues
2026-05-29 22:56:12 -05:00
parent 07377ad92e
commit 841399a0c7
5 changed files with 20 additions and 476 deletions
+3 -12
View File
@@ -309,18 +309,9 @@ local lastSpellId = nil -- spellId cached from SPELL_START_SELF (Nampower)
libcast:SetScript("OnEvent", function()
-- Fill database with player casts
if event == "SPELLCAST_START" then
-- Get icon from Nampower using spellId cached from SPELL_START_SELF
icon = nil
if lastSpellId and GetSpellRecField and GetSpellIconTexture then
local iconId = GetSpellRecField(lastSpellId, "spellIconID")
if iconId then
icon = GetSpellIconTexture(iconId)
if icon and not string.find(icon, "\\") then
icon = "Interface\\Icons\\" .. icon
end
end
end
-- fallback to L["spells"] / lastcasttex if Nampower didn't provide icon
-- Get icon via spellId cached from SPELL_START_SELF
icon = lastSpellId and C_Spell.GetSpellTexture(lastSpellId) or nil
-- fallback to L["spells"] / lastcasttex if no icon resolved
if not icon then
icon = L["spells"][arg1] and L["spells"][arg1].icon and string.format("%s%s", "Interface\\Icons\\", L["spells"][arg1].icon) or lastcasttex
end
+8 -48
View File
@@ -371,24 +371,8 @@ function libdebuff:GetSpellIcon(spellId)
if iconCache[spellId] then
return iconCache[spellId]
end
local texture = nil
if GetSpellRecField and GetSpellIconTexture then
local spellIconId = GetSpellRecField(spellId, "spellIconID")
if spellIconId and type(spellIconId) == "number" and spellIconId > 0 then
texture = GetSpellIconTexture(spellIconId)
-- GetSpellIconTexture may return short name, needs full path for SetTexture
if texture and not string.find(texture, "\\") then
texture = "Interface\\Icons\\" .. texture
end
end
end
if not texture then
texture = "Interface\\Icons\\INV_Misc_QuestionMark"
end
local texture = C_Spell.GetSpellTexture(spellId) or "Interface\\Icons\\INV_Misc_QuestionMark"
iconCache[spellId] = texture
return texture
end
@@ -1250,34 +1234,16 @@ if hasNampower then
local isChannel = spellType == 1 and (not arg6 or arg6 == 0)
if not casterGuid or not spellId then return end
-- Get spell name via Nampower
local spellName = nil
if GetSpellRec then
local rec = GetSpellRec(spellId)
spellName = rec and rec.name or nil
end
local spellName = C_Spell.GetSpellName(spellId)
local icon = libdebuff:GetSpellIcon(spellId)
-- Use item icon for item-triggered casts
if itemId and itemId > 0 and GetItemStatsField and GetItemIconTexture then
local displayInfoId = GetItemStatsField(itemId, "displayInfoID")
if displayInfoId then
local itemIcon = GetItemIconTexture(displayInfoId)
if itemIcon then
-- GetItemIconTexture returns short name (e.g. "INV_Gizmo_08"), needs full path
if not string.find(itemIcon, "\\") then
itemIcon = "Interface\\Icons\\" .. itemIcon
end
icon = itemIcon
end
end
-- Store in persistent item icon cache (survives SPELL_GO clearing libdebuff_casts)
if itemId and itemId > 0 then
icon = C_Item.GetItemIconByID(itemId) or icon
pfUI.libdebuff_item_icons[casterGuid] = {
icon = icon,
name = GetItemStatsField and GetItemStatsField(itemId, "displayName") or nil
name = GetItemInfo(itemId),
}
else
pfUI.libdebuff_item_icons[casterGuid] = nil
@@ -1467,15 +1433,9 @@ if hasNampower then
local targetGuid = arg4
if success ~= 1 or not spellId then return end
-- Get spell name
local spellName = nil
if GetSpellRec then
local rec = GetSpellRec(spellId)
spellName = rec and rec.name or nil
end
local spellName = C_Spell.GetSpellName(spellId)
-- Store pending cast info for libpredict (heal prediction target tracking)
-- This allows libpredict to resolve the correct target for Nampower queued casts,
-- where CastSpellByName hook fires while current_cast is set and spell_queue
+6 -334
View File
@@ -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()
+2 -79
View File
@@ -174,69 +174,6 @@ pfUI:RegisterModule("superwow", function ()
end
end
-- Autoloot Control API
if SetAutoloot then
pfUI.api.SetAutoloot = function(enabled)
SetAutoloot(enabled and 1 or 0)
end
pfUI.api.GetAutoloot = function()
return SetAutoloot() == 1
end
pfUI.api.ToggleAutoloot = function()
local current = SetAutoloot()
SetAutoloot(current == 1 and 0 or 1)
return SetAutoloot() == 1
end
end
-- GetPlayerBuffID wrapper
if GetPlayerBuffID then
pfUI.api.GetPlayerBuffSpellId = function(buffIndex)
return GetPlayerBuffID(buffIndex)
end
end
-- CombatLogAdd wrapper for logging
if CombatLogAdd then
pfUI.api.LogToCombatLog = function(text, raw)
CombatLogAdd(text, raw and 1 or nil)
end
end
-- Local Raid Markers (marks only visible to self)
if SetRaidTarget then
local origSetRaidTarget = SetRaidTarget
pfUI.api.SetLocalRaidTarget = function(unit, index)
origSetRaidTarget(unit, index, "local")
end
end
-- Weapon Enchant Info on other players
if GetWeaponEnchantInfo then
local origGetWeaponEnchantInfo = GetWeaponEnchantInfo
pfUI.api.GetUnitWeaponEnchants = function(unit)
if unit and unit ~= "player" then
local mhName, ohName = GetWeaponEnchantInfo(unit)
return {
mainHand = mhName,
offHand = ohName,
}
else
local hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges = origGetWeaponEnchantInfo()
return {
mainHand = hasMainHandEnchant and true or false,
mainHandExpiration = mainHandExpiration,
mainHandCharges = mainHandCharges,
offHand = hasOffHandEnchant and true or false,
offHandExpiration = offHandExpiration,
offHandCharges = offHandCharges,
}
end
end
end
-- Enhance libcast with SuperWoW data for NPCs and other players
-- Player casts use SPELLCAST_* events for proper pushback handling
local supercast = CreateFrame("Frame")
@@ -295,22 +232,8 @@ pfUI:RegisterModule("superwow", function ()
local spell_id = arg4
local timer = arg5
-- get spell info from spell id
local spell, icon, _
if GetSpellRec then
local rec = GetSpellRec(spell_id)
if rec then
spell = rec.name
local iconID = rec.spellIconID
icon = iconID and GetSpellIconTexture(iconID) or nil
end
elseif SpellInfo and SpellInfo(spell_id) then
spell, _, icon = SpellInfo(spell_id)
end
-- set fallback values
spell = spell or UNKNOWN
icon = icon or "Interface\\Icons\\INV_Misc_QuestionMark"
local spell = C_Spell.GetSpellName(spell_id) or UNKNOWN
local icon = C_Spell.GetSpellTexture(spell_id) or "Interface\\Icons\\INV_Misc_QuestionMark"
-- skip on buff procs during cast
if event_type == "CAST" then
+1 -3
View File
@@ -318,9 +318,7 @@ pfUI:RegisterModule("swingtimer", function ()
local _, _, id = string.find(l, "item:(%d+)")
id = tonumber(id)
if not id then return false end
local s = GetItemStats and GetItemStats(id)
if not s then return false end
return OH_WEAPON_TYPES[s.inventoryType] == true
return OH_WEAPON_TYPES[C_Item.GetItemInventoryTypeByID(id)] == true
end
local function UpdateWeaponSpeeds()