Files
NampowerSettings/helper.lua
T
2026-01-11 12:29:50 -08:00

364 lines
9.4 KiB
Lua

if not Nampower then
return
end
if not Nampower:HasMinimumVersion(2, 14, 0) then
return
end
local function GetSpellMod(num)
local modifierTypes = {
[0] = "DAMAGE",
[1] = "DURATION",
[2] = "THREAT",
[3] = "ATTACK_POWER",
[4] = "CHARGES",
[5] = "RANGE",
[6] = "RADIUS",
[7] = "CRITICAL_CHANCE",
[8] = "ALL_EFFECTS",
[9] = "NOT_LOSE_CASTING_TIME",
[10] = "CASTING_TIME",
[11] = "COOLDOWN",
[12] = "SPEED",
[14] = "COST",
[15] = "CRIT_DAMAGE_BONUS",
[16] = "RESIST_MISS_CHANCE",
[17] = "JUMP_TARGETS",
[18] = "CHANCE_OF_SUCCESS",
[19] = "ACTIVATION_TIME",
[20] = "EFFECT_PAST_FIRST",
[21] = "CASTING_TIME_OLD",
[22] = "DOT",
[23] = "HASTE",
[24] = "SPELL_BONUS_DAMAGE",
[27] = "MULTIPLE_VALUE",
[28] = "RESIST_DISPEL_CHANCE"
}
return modifierTypes[num] or "UNKNOWN"
end
function PrintTable(tbl, indent)
indent = indent or 0
local prefix = string.rep(" ", indent)
for k, v in pairs(tbl) do
if type(v) == "table" then
print(prefix .. tostring(k) .. ":")
PrintTable(v, indent + 1)
else
print(prefix .. tostring(k) .. ": " .. tostring(v))
end
end
end
if CombatLogAdd then
function PrintTableToCombatLog(tbl, indent)
indent = indent or 0
local prefix = string.rep(" ", indent)
for k, v in pairs(tbl) do
if type(v) == "table" then
CombatLogAdd(prefix .. tostring(k) .. ":")
PrintTableToCombatLog(v, indent + 1)
else
CombatLogAdd(prefix .. tostring(k) .. ": " .. tostring(v))
end
end
end
function LogUnitData(unit)
local data = GetUnitData(unit)
if data then
PrintTableToCombatLog(data)
else
print("No unit data available")
end
end
function LogSpellData(spellId)
local data = GetSpellRec(spellId)
if data then
PrintTableToCombatLog(data)
else
print("No spell data available")
end
end
end
function PrintBuffs(unit)
for i = 1, 32 do
local texture, stacks, spellId = UnitBuff(unit, i)
if not texture then
break
end
print(tostring(i) .. " " .. tostring(spellId))
end
end
function PrintUnitData(unit)
local data = GetUnitData(unit)
if data then
PrintTable(data)
else
print("No unit data available")
end
end
function PrintSpellMods(spellId)
for i = 0, 28 do
local flatMod, percentMod, ret = GetSpellModifiers(spellId, i)
if ret > 0 then
print(GetSpellMod(i) .. " (" .. tostring(i) .. "): flat:" .. tostring(flatMod) .. " percent:" .. tostring(percentMod))
end
end
end
function PrintSpellData(spellId)
local data = GetSpellRec(spellId)
if data then
PrintTable(data)
else
print("No spell data available")
end
end
if not Nampower:HasMinimumVersion(2, 16, 0) then
return
end
function PrintItemLocation(itemNameOrId)
local bagIndex, slot = FindPlayerItemSlot(itemNameOrId)
print(tostring(bagIndex) .. " " .. tostring(slot))
end
function PrintEquippedItems()
local target = "player"
if UnitExists("target") then
target = "target"
end
local data = GetEquippedItems(target)
PrintTable(data)
end
function LogEquippedItems()
local target = "player"
if UnitExists("target") then
target = "target"
end
local data = GetEquippedItems(target)
PrintTableToCombatLog(data)
end
function PrintBagItems()
local data = GetBagItems()
PrintTable(data)
end
function LogBagItems()
local data = GetBagItems()
PrintTableToCombatLog(data)
end
function TestBagItems(bagIndex)
local items = GetBagItems(bagIndex)
local numItemsChecked = 0
for slot, itemData in pairs(items) do
local itemLink = GetContainerItemLink(bagIndex, slot)
if not itemLink then
print(tostring(bagIndex) .. " " .. tostring(slot))
PrintTable(itemData)
end
local _, _, itemId = strfind(itemLink, "(%d+):")
numItemsChecked = numItemsChecked + 1
if (tostring(itemData.itemId) ~= itemId) then
print("Item mismatch at " .. tostring(bagIndex) .. " " .. tostring(slot) .. " " .. tostring(itemData.itemId) .. " " .. tostring(itemId))
print(itemLink)
end
end
print("checked " .. tostring(numItemsChecked) .. " items")
end
function TestAllBagItems()
local data = GetBagItems()
local numItemsChecked = 0
for bagIndex, items in pairs(data) do
for slot, itemData in pairs(items) do
local itemLink = GetContainerItemLink(bagIndex, slot)
if not itemLink then
print(tostring(bagIndex) .. " " .. tostring(slot))
PrintTable(itemData)
end
local _, _, itemId = strfind(itemLink, "(%d+):")
numItemsChecked = numItemsChecked + 1
if (tostring(itemData.itemId) ~= itemId) then
print("Item mismatch at " .. tostring(bagIndex) .. " " .. tostring(slot) .. " " .. tostring(itemData.itemId) .. " " .. tostring(itemId))
print(itemLink)
end
end
end
print("checked " .. tostring(numItemsChecked) .. " items")
end
function TestTrinkets()
local data = GetTrinkets()
for index, trinketData in pairs(data) do
local bagIndex = trinketData.bagIndex
local slot = trinketData.slotIndex
local itemLink
if bagIndex then
itemLink = GetContainerItemLink(bagIndex, slot)
else
itemLink = GetInventoryItemLink("player", slot)
end
local _, _, itemId = strfind(itemLink, "(%d+):")
if (tostring(trinketData.itemId) ~= itemId) then
print("Trinket mismatch at " .. tostring(bagIndex) .. " " .. tostring(slot) .. " " .. tostring(itemData.itemId) .. " " .. tostring(itemId))
print(itemLink)
end
end
end
if not Nampower:HasMinimumVersion(2, 17, 0) then
return
end
function PrintCastInfo()
local data = GetCastInfo()
if data then
PrintTable(data)
end
end
function PrintSpellCooldown(spellId)
local data = GetSpellIdCooldown(spellId)
if data then
PrintTable(data)
end
end
function PrintItemCooldown(itemId)
local data = GetItemIdCooldown(itemId)
if data then
PrintTable(data)
end
end
function PrintTrinketCooldown(trinketId)
local data = GetTrinketCooldown(trinketId)
if data then
PrintTable(data)
end
end
function PrintTrinkets()
local data = GetTrinkets(1)
if data then
PrintTable(data)
end
end
if not Nampower:HasMinimumVersion(2, 24, 0) then
return
end
-- Auto Attack Event Constants
local HITINFO_NORMALSWING = 0
local HITINFO_UNK0 = 1
local HITINFO_AFFECTS_VICTIM = 2
local HITINFO_LEFTSWING = 4
local HITINFO_UNK3 = 8
local HITINFO_MISS = 16
local HITINFO_ABSORB = 32
local HITINFO_RESIST = 64
local HITINFO_CRITICALHIT = 128
local HITINFO_UNK8 = 256
local HITINFO_UNK9 = 8192
local HITINFO_GLANCING = 16384
local HITINFO_CRUSHING = 32768
local HITINFO_NOACTION = 65536
local HITINFO_SWINGNOHITSOUND = 524288
local VICTIMSTATE_UNAFFECTED = 0
local VICTIMSTATE_NORMAL = 1
local VICTIMSTATE_DODGE = 2
local VICTIMSTATE_PARRY = 3
local VICTIMSTATE_INTERRUPT = 4
local VICTIMSTATE_BLOCKS = 5
local VICTIMSTATE_EVADES = 6
local VICTIMSTATE_IS_IMMUNE = 7
local VICTIMSTATE_DEFLECTS = 8
local victimStateNames = {
[0] = "Unaffected",
[1] = "Normal",
[2] = "Dodged",
[3] = "Parried",
[4] = "Interrupted",
[5] = "Blocked",
[6] = "Evaded",
[7] = "Immune",
[8] = "Deflected"
}
function GetHitType(hitInfo)
local isCrit = bit.band(hitInfo, HITINFO_CRITICALHIT) ~= 0
local isGlancing = bit.band(hitInfo, HITINFO_GLANCING) ~= 0
local isCrushing = bit.band(hitInfo, HITINFO_CRUSHING) ~= 0
local isMiss = bit.band(hitInfo, HITINFO_MISS) ~= 0
local isOffHand = bit.band(hitInfo, HITINFO_LEFTSWING) ~= 0
local hitType = "Normal"
if isMiss then
hitType = "Miss"
elseif isCrit then
hitType = "Critical"
elseif isGlancing then
hitType = "Glancing"
elseif isCrushing then
hitType = "Crushing"
end
if isOffHand then
hitType = hitType .. " (Off-hand)"
end
return hitType
end
function GetVictimStateName(victimState)
return victimStateNames[victimState] or "Unknown"
end
local function onAutoAttack(attackerGuid, targetGuid, totalDamage, hitInfo, victimState, subDamageCount, blockedAmount, totalAbsorb, totalResist)
local hitType = GetHitType(hitInfo)
local victimStateName = GetVictimStateName(victimState)
print(string.format(
"Auto Attack: %s -> %s | %d damage (%s) | State: %s | SubDmg: %d | Absorbed: %d | Resisted: %d | Blocked: %d",
attackerGuid, targetGuid, totalDamage, hitType, victimStateName,
subDamageCount, totalAbsorb, totalResist, blockedAmount
))
end
-- helpful event hooks for debugging
--Nampower:RegisterEvent("UNIT_CASTEVENT", function(casterGuid, targetGuid, event, spellID, castDuration)
-- if(casterGuid=="0x00000000001CD43C") then
-- print("CASTEVENT: " .. tostring(casterGuid) .. " -> " .. tostring(targetGuid) .. " event: " .. tostring(event) .. " spellID: " .. tostring(spellID) .. " castDuration: " .. tostring(castDuration))
-- end
--end)
--Nampower:RegisterEvent("AURA_CAST_ON_OTHER", function(spellId, caster, target, effect, effectname)
-- local unitName = target and UnitName(target) or ""
-- print("AURA_CAST_ON_OTHER: " .. tostring(spellId) .. " " .. tostring(GetSpellRecField(spellId, "name")) .. " by " .. tostring(UnitName(caster)) .. " on " .. unitName .. " effect: " .. tostring(effect) .. " effectname: " .. tostring(effectname))
--end)
--
--Nampower:RegisterEvent("AURA_CAST_ON_SELF", function(spellId, caster, target, effect, effectname)
-- local unitName = target and UnitName(target) or ""
-- print("AURA_CAST_ON_SELF: " .. tostring(spellId) .. " " .. tostring(GetSpellRecField(spellId, "name")) .. " by " .. tostring(UnitName(caster)) .. " on " .. unitName .. " effect: " .. tostring(effect) .. " effectname: " .. tostring(effectname))
--end)
--
--Nampower:RegisterEvent("AUTO_ATTACK_SELF", onAutoAttack)
--Nampower:RegisterEvent("AUTO_ATTACK_OTHER", onAutoAttack)