Files
amibis/Amibis/Amibis.lua
T
2026-10-28 18:02:02 +01:00

726 lines
26 KiB
Lua

local addonName, ns = ...
local Amibis = {}
ns.Amibis = Amibis
Amibis.version = "1.0.0"
local DEFAULT_AMIBIS_DB = {
selectedPhase = "ZA",
}
local DEFAULT_AMIBIS_CHAR_DB = {
frameX = nil,
frameY = nil,
framePoint = nil,
frameRelPoint = nil,
overrideSpec = nil,
}
local TOP_UPGRADES_COUNT = 3
-- Per-spec stat priorities. Each entry is { statKey, weight } in display order:
-- the panel shows every listed stat, and the weight drives upgrade scoring and
-- the completion ratio, so each spec is measured by what actually matters to it.
local SPEC_STAT_PROFILES = {
["PRIEST"] = {
["Discipline"] = { { "healing", 3 }, { "intellect", 2 }, { "mp5", 2 }, { "haste", 2 }, { "spirit", 1 }, { "crit", 1 } },
["Holy"] = { { "healing", 3 }, { "intellect", 2 }, { "mp5", 2 }, { "haste", 2 }, { "spirit", 1 }, { "crit", 1 } },
["Shadow"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "spirit", 1 }, { "mp5", 1 } },
},
["DRUID"] = {
["Balance"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "spirit", 1 }, { "mp5", 1 } },
["Feral Combat"] = { { "attackPower", 3 }, { "strength", 2 }, { "agility", 2 }, { "feralAttackPower", 2 }, { "hit", 2 }, { "expertise", 2 }, { "crit", 2 }, { "armorPen", 1 } },
["Restoration"] = { { "healing", 3 }, { "intellect", 2 }, { "spirit", 2 }, { "mp5", 2 }, { "haste", 2 }, { "crit", 1 } },
},
["PALADIN"] = {
["Holy"] = { { "healing", 3 }, { "intellect", 2 }, { "mp5", 2 }, { "haste", 2 }, { "spirit", 1 }, { "crit", 1 } },
["Protection"] = { { "stamina", 3 }, { "armor", 2 }, { "defense", 2 }, { "dodge", 2 }, { "parry", 2 }, { "spellDamage", 2 }, { "block", 1 }, { "hit", 1 } },
["Retribution"] = { { "strength", 3 }, { "attackPower", 2 }, { "crit", 2 }, { "hit", 2 }, { "expertise", 1 }, { "haste", 1 }, { "armorPen", 1 }, { "agility", 1 } },
},
["SHAMAN"] = {
["Elemental"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "mp5", 1 }, { "stamina", 1 } },
["Enhancement"] = { { "attackPower", 3 }, { "strength", 2 }, { "agility", 2 }, { "hit", 2 }, { "expertise", 2 }, { "crit", 2 }, { "haste", 1 }, { "armorPen", 1 } },
["Restoration"] = { { "healing", 3 }, { "intellect", 2 }, { "spirit", 2 }, { "mp5", 2 }, { "haste", 2 }, { "crit", 1 } },
},
["MAGE"] = {
["Arcane"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "spirit", 1 } },
["Fire"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "spirit", 1 } },
["Frost"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "spirit", 1 } },
},
["WARLOCK"] = {
["Affliction"] = { { "spellDamage", 3 }, { "hit", 2 }, { "haste", 2 }, { "crit", 1 }, { "intellect", 1 }, { "spirit", 1 }, { "stamina", 1 } },
["Demonology"] = { { "spellDamage", 3 }, { "hit", 2 }, { "haste", 2 }, { "crit", 1 }, { "intellect", 1 }, { "spirit", 1 }, { "stamina", 1 } },
["Destruction"] = { { "spellDamage", 3 }, { "hit", 2 }, { "crit", 2 }, { "haste", 2 }, { "intellect", 1 }, { "spirit", 1 } },
},
["WARRIOR"] = {
["Arms"] = { { "strength", 3 }, { "attackPower", 2 }, { "crit", 2 }, { "hit", 2 }, { "expertise", 1 }, { "armorPen", 1 }, { "haste", 1 }, { "stamina", 1 } },
["Fury"] = { { "strength", 3 }, { "attackPower", 2 }, { "crit", 2 }, { "hit", 2 }, { "expertise", 1 }, { "armorPen", 1 }, { "haste", 1 }, { "stamina", 1 } },
["Protection"] = { { "stamina", 3 }, { "armor", 2 }, { "defense", 2 }, { "dodge", 2 }, { "parry", 2 }, { "expertise", 1 }, { "block", 1 }, { "hit", 1 } },
},
["ROGUE"] = {
["Assassination"] = { { "agility", 3 }, { "attackPower", 2 }, { "hit", 2 }, { "expertise", 2 }, { "crit", 2 }, { "haste", 1 }, { "armorPen", 1 }, { "stamina", 1 } },
["Combat"] = { { "agility", 3 }, { "attackPower", 2 }, { "armorPen", 2 }, { "hit", 2 }, { "expertise", 2 }, { "crit", 2 }, { "haste", 1 }, { "stamina", 1 } },
["Subtlety"] = { { "agility", 3 }, { "attackPower", 2 }, { "crit", 2 }, { "hit", 2 }, { "haste", 1 }, { "stamina", 1 } },
},
["HUNTER"] = {
["Beast Mastery"] = { { "agility", 3 }, { "attackPower", 2 }, { "rangedAttackPower", 2 }, { "hit", 2 }, { "crit", 2 }, { "haste", 1 }, { "armorPen", 1 }, { "stamina", 1 } },
["Marksmanship"] = { { "agility", 3 }, { "attackPower", 2 }, { "rangedAttackPower", 2 }, { "hit", 2 }, { "crit", 2 }, { "haste", 1 }, { "armorPen", 1 }, { "stamina", 1 } },
["Survival"] = { { "agility", 3 }, { "attackPower", 2 }, { "rangedAttackPower", 2 }, { "hit", 2 }, { "crit", 2 }, { "haste", 1 }, { "armorPen", 1 }, { "stamina", 1 } },
},
}
local DEFAULT_STAT_PROFILE = { { "spellDamage", 3 }, { "crit", 2 }, { "haste", 2 }, { "hit", 2 }, { "intellect", 1 } }
local function GetStatProfile(class, spec)
local classProfiles = SPEC_STAT_PROFILES[class]
if classProfiles and classProfiles[spec] then
return classProfiles[spec]
end
return DEFAULT_STAT_PROFILE
end
function Amibis:GetStatKeysForSpec(class, spec)
local keys = {}
for _, entry in ipairs(GetStatProfile(class, spec)) do
table.insert(keys, entry[1])
end
return keys
end
function Amibis:GetStatWeightsForSpec(class, spec)
local weights = {}
for _, entry in ipairs(GetStatProfile(class, spec)) do
weights[entry[1]] = entry[2]
end
return weights
end
function Amibis:StatRatio(equippedStats, bisStats, class, spec)
if not equippedStats or not bisStats then return 0 end
local weightSum, sum = 0, 0
for _, entry in ipairs(GetStatProfile(class, spec)) do
local statKey, weight = entry[1], entry[2]
local bis = bisStats[statKey] or 0
if bis > 0 then
local current = equippedStats[statKey] or 0
local ratio = current / bis
if ratio > 1 then ratio = 1 end
sum = sum + ratio * weight
weightSum = weightSum + weight
end
end
if weightSum == 0 then return 0 end
return sum / weightSum
end
function Amibis:GetCompletionRatio(data)
if not data then return 0 end
if data.statsComplete and data.bisStats then
return self:StatRatio(data.equippedStats, data.bisStats, data.class, data.spec)
end
return (data.bisCount or 0) / math.max(1, data.totalSlots or 1)
end
local function InitializeDB()
if not AmibisDB then
AmibisDB = CopyTable(DEFAULT_AMIBIS_DB)
else
for k, v in pairs(DEFAULT_AMIBIS_DB) do
if AmibisDB[k] == nil then
AmibisDB[k] = v
end
end
end
if not AmibisCharDB then
AmibisCharDB = CopyTable(DEFAULT_AMIBIS_CHAR_DB)
else
for k, v in pairs(DEFAULT_AMIBIS_CHAR_DB) do
if AmibisCharDB[k] == nil then
AmibisCharDB[k] = v
end
end
end
end
function Amibis:GetPlayerClass()
return select(2, UnitClass("player"))
end
function Amibis:GetPlayerSpec()
local class = self:GetPlayerClass()
local specNames = {
["PRIEST"] = { "Discipline", "Holy", "Shadow" },
["MAGE"] = { "Arcane", "Fire", "Frost" },
["WARLOCK"] = { "Affliction", "Demonology", "Destruction" },
["DRUID"] = { "Balance", "Feral Combat", "Restoration" },
["PALADIN"] = { "Holy", "Protection", "Retribution" },
["SHAMAN"] = { "Elemental", "Enhancement", "Restoration" },
["WARRIOR"] = { "Arms", "Fury", "Protection" },
["ROGUE"] = { "Assassination", "Combat", "Subtlety" },
["HUNTER"] = { "Beast Mastery", "Marksmanship", "Survival" },
}
if not specNames[class] then
return nil
end
local maxPoints = 0
local specIndex = 1
for i = 1, 3 do
local r1, r2, r3, r4 = GetTalentTabInfo(i)
local points = tonumber(r1) or tonumber(r2) or tonumber(r3) or tonumber(r4) or 0
if points > maxPoints then
maxPoints = points
specIndex = i
end
end
return specNames[class][specIndex]
end
function Amibis:GetEquippedItems()
local items = {}
local slotMap = {
["Head"] = 1,
["Neck"] = 2,
["Shoulder"] = 3,
["Back"] = 15,
["Chest"] = 5,
["Wrist"] = 9,
["Hands"] = 10,
["Waist"] = 6,
["Legs"] = 7,
["Feet"] = 8,
["Finger0"] = 11,
["Finger1"] = 12,
["Trinket0"] = 13,
["Trinket1"] = 14,
["MainHand"] = 16,
["SecondaryHand"] = 17,
["Ranged"] = 18,
}
for slotName, slotID in pairs(slotMap) do
local link = GetInventoryItemLink("player", slotID)
if link then
local itemID = tonumber(link:match("item:(%d+)"))
local name = GetItemInfo(itemID) or "Unknown"
items[slotName] = {
itemID = itemID,
name = name,
link = link,
slotID = slotID,
}
else
items[slotName] = nil
end
end
return items
end
-- Trinket slots are interchangeable: match equipped trinkets to BIS trinkets
-- as a set instead of by slot index, so swapping Trinket0/Trinket1 still
-- counts as BIS. Returns a map of trinket slot name -> equipped item (or nil).
function Amibis:AssignTrinketEquipped(bisList, equipped)
local assigned = {}
local trinketBisSlots = {}
for _, s in ipairs({ "Trinket0", "Trinket1" }) do
if bisList and bisList[s] then
table.insert(trinketBisSlots, s)
end
end
local equippedTrinkets = {}
for _, s in ipairs({ "Trinket0", "Trinket1" }) do
if equipped and equipped[s] then
table.insert(equippedTrinkets, equipped[s])
end
end
local used = {}
-- Prefer exact itemID matches first.
for _, bisSlot in ipairs(trinketBisSlots) do
local bisItem = bisList[bisSlot]
for ei, eq in ipairs(equippedTrinkets) do
if not used[ei] and eq.itemID == bisItem.itemID then
assigned[bisSlot] = eq
used[ei] = true
break
end
end
end
-- Then fill remaining BIS slots with leftover equipped trinkets.
for _, bisSlot in ipairs(trinketBisSlots) do
if assigned[bisSlot] == nil then
for ei, eq in ipairs(equippedTrinkets) do
if not used[ei] then
assigned[bisSlot] = eq
used[ei] = true
break
end
end
end
end
return assigned
end
local STAT_MAP = {
["ITEM_MOD_HEALING_DONE_SHORT"] = "healing",
["ITEM_MOD_SPELL_HEALING_DONE_SHORT"] = "healing",
["ITEM_MOD_HEALING_DONE"] = "healing",
["ITEM_MOD_SPELL_HEALING_DONE"] = "healing",
["ITEM_MOD_DAMAGE_DONE_SHORT"] = "spellDamage",
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = "spellDamage",
["ITEM_MOD_DAMAGE_DONE"] = "spellDamage",
["ITEM_MOD_SPELL_DAMAGE_DONE"] = "spellDamage",
["ITEM_MOD_INTELLECT_SHORT"] = "intellect",
["ITEM_MOD_SPIRIT_SHORT"] = "spirit",
["ITEM_MOD_STAMINA_SHORT"] = "stamina",
["ITEM_MOD_MANA_REGENERATION_SHORT"] = "mp5",
["ITEM_MOD_MANA_REGENERATION"] = "mp5",
["ITEM_MOD_POWER_REGEN0_SHORT"] = "mp5",
-- TBC uses school-specific ratings (haste/crit melee, ranged, spell) as well
-- as the generic WotLK-era keys; items report whichever applies.
["ITEM_MOD_HASTE_RATING_SHORT"] = "haste",
["ITEM_MOD_HASTE_RATING"] = "haste",
["ITEM_MOD_HASTE_MELEE_RATING_SHORT"] = "haste",
["ITEM_MOD_HASTE_MELEE_RATING"] = "haste",
["ITEM_MOD_HASTE_RANGED_RATING_SHORT"] = "haste",
["ITEM_MOD_HASTE_RANGED_RATING"] = "haste",
["ITEM_MOD_HASTE_SPELL_RATING_SHORT"] = "haste",
["ITEM_MOD_HASTE_SPELL_RATING"] = "haste",
["ITEM_MOD_SPELL_HASTE_RATING_SHORT"] = "haste",
["ITEM_MOD_SPELL_HASTE_RATING"] = "haste",
["ITEM_MOD_CRIT_RATING_SHORT"] = "crit",
["ITEM_MOD_CRIT_RATING"] = "crit",
["ITEM_MOD_CRIT_MELEE_RATING_SHORT"] = "crit",
["ITEM_MOD_CRIT_MELEE_RATING"] = "crit",
["ITEM_MOD_CRIT_RANGED_RATING_SHORT"] = "crit",
["ITEM_MOD_CRIT_RANGED_RATING"] = "crit",
["ITEM_MOD_CRIT_SPELL_RATING_SHORT"] = "crit",
["ITEM_MOD_CRIT_SPELL_RATING"] = "crit",
["ITEM_MOD_SPELL_CRIT_RATING_SHORT"] = "crit",
["ITEM_MOD_SPELL_CRIT_RATING"] = "crit",
["ITEM_MOD_SPELL_POWER_SHORT"] = "spellPower",
["ITEM_MOD_SPELL_DMG_SHORT"] = "spellDamage",
["ITEM_MOD_HEALING_SHORT"] = "healing",
-- Physical stats (TBC uses per-school hit ratings; take the applicable one).
["ITEM_MOD_ATTACK_POWER_SHORT"] = "attackPower",
["ITEM_MOD_ATTACK_POWER"] = "attackPower",
["ITEM_MOD_RANGED_ATTACK_POWER_SHORT"] = "rangedAttackPower",
["ITEM_MOD_RANGED_ATTACK_POWER"] = "rangedAttackPower",
["ITEM_MOD_FERAL_ATTACK_POWER_SHORT"] = "feralAttackPower",
["ITEM_MOD_FERAL_ATTACK_POWER"] = "feralAttackPower",
["ITEM_MOD_STRENGTH_SHORT"] = "strength",
["ITEM_MOD_STRENGTH"] = "strength",
["ITEM_MOD_AGILITY_SHORT"] = "agility",
["ITEM_MOD_AGILITY"] = "agility",
["ITEM_MOD_HIT_RATING_SHORT"] = "hit",
["ITEM_MOD_HIT_RATING"] = "hit",
["ITEM_MOD_HIT_MELEE_RATING_SHORT"] = "hit",
["ITEM_MOD_HIT_MELEE_RATING"] = "hit",
["ITEM_MOD_HIT_RANGED_RATING_SHORT"] = "hit",
["ITEM_MOD_HIT_RANGED_RATING"] = "hit",
["ITEM_MOD_HIT_SPELL_RATING_SHORT"] = "hit",
["ITEM_MOD_HIT_SPELL_RATING"] = "hit",
["ITEM_MOD_EXPERTISE_RATING_SHORT"] = "expertise",
["ITEM_MOD_EXPERTISE_RATING"] = "expertise",
["ITEM_MOD_ARMOR_PENETRATION_RATING_SHORT"] = "armorPen",
["ITEM_MOD_ARMOR_PENETRATION_RATING"] = "armorPen",
["ITEM_MOD_DEFENSE_SKILL_RATING_SHORT"] = "defense",
["ITEM_MOD_DEFENSE_SKILL_RATING"] = "defense",
["ITEM_MOD_DODGE_RATING_SHORT"] = "dodge",
["ITEM_MOD_DODGE_RATING"] = "dodge",
["ITEM_MOD_PARRY_RATING_SHORT"] = "parry",
["ITEM_MOD_PARRY_RATING"] = "parry",
["ITEM_MOD_BLOCK_RATING_SHORT"] = "block",
["ITEM_MOD_BLOCK_RATING"] = "block",
["ITEM_MOD_BLOCK_VALUE_SHORT"] = "blockValue",
["ITEM_MOD_BLOCK_VALUE"] = "blockValue",
["ITEM_MOD_RESILIENCE_RATING_SHORT"] = "resilience",
["ITEM_MOD_RESILIENCE_RATING"] = "resilience",
-- Classic reports armor under RESISTANCE0_NAME; later clients use ITEM_MOD_ARMOR.
["RESISTANCE0_NAME"] = "armor",
["ITEM_MOD_ARMOR"] = "armor",
}
-- Stats that multiple WoW API keys map to (school-specific spell damage, hit,
-- haste, crit, etc.): only one alias is ever active, so take MAX instead of SUM.
local ALIAS_STATS = {
healing = true,
spellDamage = true,
mp5 = true,
haste = true,
crit = true,
hit = true,
}
function Amibis:ScanItemStats(itemID)
if not itemID then return nil end
local _, link = GetItemInfo(itemID)
if not link then
link = "item:" .. itemID .. ":0:0:0:0:0:0:0:0"
end
local stats = GetItemStats(link)
if not stats then return nil end
local result = {}
for wowKey, ourKey in pairs(STAT_MAP) do
local value = stats[wowKey]
if value then
if ALIAS_STATS[ourKey] then
local current = result[ourKey]
if not current or value > current then
result[ourKey] = value
end
else
result[ourKey] = (result[ourKey] or 0) + value
end
end
end
return result
end
function Amibis:AggregateStats(items)
local totals = {
healing = 0,
spellDamage = 0,
spellPower = 0,
intellect = 0,
spirit = 0,
stamina = 0,
mp5 = 0,
haste = 0,
crit = 0,
hit = 0,
attackPower = 0,
rangedAttackPower = 0,
feralAttackPower = 0,
strength = 0,
agility = 0,
expertise = 0,
armorPen = 0,
defense = 0,
dodge = 0,
parry = 0,
block = 0,
blockValue = 0,
armor = 0,
resilience = 0,
}
for slotName, item in pairs(items) do
if item and item.itemID then
local stats = self:ScanItemStats(item.itemID)
if stats then
for k, v in pairs(stats) do
totals[k] = (totals[k] or 0) + v
end
end
end
end
return totals
end
function Amibis:CompareGear()
local class = self:GetPlayerClass()
local spec = AmibisCharDB.overrideSpec or self:GetPlayerSpec()
local phase = ns.Data.BISLists:ResolvePhase(class, spec, AmibisDB.selectedPhase or "ZA")
local bisList = ns.Data.BISLists:GetBISList(class, spec, phase)
if not bisList then
return {
class = class,
spec = spec,
phase = phase,
hasBISList = false,
slots = {},
bisCount = 0,
totalSlots = 0,
topUpgrades = {},
}
end
local equipped = self:GetEquippedItems()
local slots = {}
local bisCount = 0
local totalSlots = 0
local allUpgrades = {}
local statProfile = GetStatProfile(class, spec)
local statWeights = self:GetStatWeightsForSpec(class, spec)
-- Trinket slots are interchangeable: a BIS trinket counts regardless of
-- whether it is equipped in Trinket0 or Trinket1.
local trinketAssigned = self:AssignTrinketEquipped(bisList, equipped)
for slotName, bisItem in pairs(bisList) do
totalSlots = totalSlots + 1
local isTrinket = (slotName == "Trinket0" or slotName == "Trinket1")
local equippedItem
if isTrinket then
equippedItem = trinketAssigned[slotName]
else
equippedItem = equipped[slotName]
end
local isBIS = false
if equippedItem and equippedItem.itemID == bisItem.itemID then
isBIS = true
bisCount = bisCount + 1
end
table.insert(slots, {
slotName = slotName,
equipped = equippedItem,
bis = bisItem,
isBIS = isBIS,
})
if not isBIS then
local statDiffs = {}
local score = 0
local equippedStats = (equippedItem and self:ScanItemStats(equippedItem.itemID)) or {}
local bisStats = self:ScanItemStats(bisItem.itemID) or {}
for _, entry in ipairs(statProfile) do
local statKey = entry[1]
local diff = (bisStats[statKey] or 0) - (equippedStats[statKey] or 0)
if diff > 0 then
statDiffs[statKey] = diff
score = score + diff * entry[2]
end
end
table.insert(allUpgrades, {
slot = slotName,
equipped = equippedItem,
bis = bisItem,
statDiffs = statDiffs,
statWeights = statWeights,
score = score,
})
end
end
table.sort(allUpgrades, function(a, b)
if a.score ~= b.score then
return a.score > b.score
end
return a.slot < b.slot
end)
local topUpgrades = {}
for i = 1, math.min(TOP_UPGRADES_COUNT, #allUpgrades) do
table.insert(topUpgrades, allUpgrades[i])
end
table.sort(slots, function(a, b)
if a.isBIS ~= b.isBIS then
return b.isBIS
end
return a.slotName < b.slotName
end)
local equippedStats = self:AggregateStats(equipped)
for slotName, bisItem in pairs(bisList) do
GetItemInfo(bisItem.itemID)
end
local bisItems = {}
for slotName, bisItem in pairs(bisList) do
bisItems[slotName] = { itemID = bisItem.itemID }
end
local bisStats = self:AggregateStats(bisItems)
local statsComplete = true
for slotName, bisItem in pairs(bisList) do
local _, link = GetItemInfo(bisItem.itemID)
if link then
local s = GetItemStats(link)
if not s or not next(s) then
statsComplete = false
break
end
else
statsComplete = false
break
end
end
local latestPhase = ns.Data.BISLists:GetLatestPhase(class, spec)
local latestCompletionRatio = 0
local latestStatsComplete = false
if latestPhase then
local latestList = ns.Data.BISLists:GetBISList(class, spec, latestPhase)
if latestList then
-- The bar always measures the latest phase, so it must not depend on
-- which phase is selected. Warm the cache for the latest list and the
-- equipped items, then use stats when available and fall back to slot
-- completion (still latest-phase based) while item data is loading.
local latestItems = {}
local latestItemsCached = true
for slotName, bisItem in pairs(latestList) do
latestItems[slotName] = { itemID = bisItem.itemID }
if not GetItemInfo(bisItem.itemID) then
latestItemsCached = false
end
end
local equippedCached = true
for _, item in pairs(equipped) do
if item and item.itemID and not GetItemInfo(item.itemID) then
equippedCached = false
break
end
end
if latestItemsCached and equippedCached then
local latestStats = bisStats
if latestPhase ~= phase then
latestStats = self:AggregateStats(latestItems)
end
latestCompletionRatio = self:StatRatio(equippedStats, latestStats, class, spec)
latestStatsComplete = true
else
local trinketAssigned = self:AssignTrinketEquipped(latestList, equipped)
local matched, total = 0, 0
for slotName, bisItem in pairs(latestList) do
total = total + 1
local equippedItem
if slotName == "Trinket0" or slotName == "Trinket1" then
equippedItem = trinketAssigned[slotName]
else
equippedItem = equipped[slotName]
end
if equippedItem and equippedItem.itemID == bisItem.itemID then
matched = matched + 1
end
end
latestCompletionRatio = total > 0 and (matched / total) or 0
end
end
end
return {
class = class,
spec = spec,
phase = phase,
hasBISList = true,
slots = slots,
bisCount = bisCount,
totalSlots = totalSlots,
topUpgrades = topUpgrades,
equippedStats = equippedStats,
bisStats = bisStats,
statsComplete = statsComplete,
latestPhase = latestPhase,
latestCompletionRatio = latestCompletionRatio,
latestStatsComplete = latestStatsComplete,
}
end
function Amibis:SaveFramePosition(frame)
local point, _, relPoint, x, y = frame:GetPoint()
AmibisCharDB.framePoint = point
AmibisCharDB.frameRelPoint = relPoint
AmibisCharDB.frameX = x
AmibisCharDB.frameY = y
end
function Amibis:LoadFramePosition(frame)
local point = AmibisCharDB.framePoint
local relPoint = AmibisCharDB.frameRelPoint
local x = AmibisCharDB.frameX
local y = AmibisCharDB.frameY
if point and x and y then
frame:ClearAllPoints()
frame:SetPoint(point, UIParent, relPoint or point, x, y)
else
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
end
end
function Amibis:InitializeUI()
if ns.UI and ns.UI.Initialize then
ns.UI.Initialize()
end
end
function Amibis:ToggleFrame()
if ns.UI and ns.UI.ToggleFrame then
ns.UI.ToggleFrame()
end
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
eventFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
eventFrame:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" then
local addon = ...
if addon == addonName then
InitializeDB()
end
elseif event == "PLAYER_LOGIN" then
Amibis:InitializeUI()
elseif event == "PLAYER_TALENT_UPDATE" or event == "PLAYER_EQUIPMENT_CHANGED" then
if ns.UI and ns.UI.RefreshUI then
ns.UI.RefreshUI()
end
end
end)
local function RefreshUI()
if ns.UI and ns.UI.RefreshUI then
ns.UI.RefreshUI()
end
end
-- Title-case each word so "/amibis spec beast mastery" -> "Beast Mastery".
local function NormalizeSpecName(value)
return (value:gsub("(%a)([%w']*)", function(first, rest)
return first:upper() .. rest:lower()
end))
end
SLASH_AMIBIS1 = "/amibis"
SlashCmdList["AMIBIS"] = function(msg)
-- Collapse whitespace so "spec clear" and "spec beast mastery" parse.
local cmd = (msg:trim():lower():gsub("%s+", " "))
if cmd == "" then
Amibis:ToggleFrame()
elseif cmd == "spec" then
print("Amibis: Usage: /amibis spec <SpecName> or /amibis spec clear")
elseif cmd == "spec clear" then
AmibisCharDB.overrideSpec = nil
print("Amibis: Spec override cleared. Using auto-detected spec.")
RefreshUI()
elseif cmd:find("^spec%s+") then
local spec = cmd:match("^spec%s+(.+)")
if spec and spec ~= "" then
spec = NormalizeSpecName(spec)
AmibisCharDB.overrideSpec = spec
print("Amibis: Spec override set to " .. spec .. ". Type /amibis spec clear to reset.")
RefreshUI()
end
else
Amibis:ToggleFrame()
end
end