diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index ac9fd8e7e..9397480c0 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 315 +local dversion = 316 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) @@ -71,9 +71,95 @@ function DF.IsTBCWow() return false end -function DF.UnitGroupRolesAssigned (unitId) +local roleBySpecTextureName = { + DruidBalance = "DAMAGER", + DruidFeralCombat = "DAMAGER", + DruidRestoration = "HEALER", + + HunterBeastMaster = "DAMAGER", + HunterMarksmanship = "DAMAGER", + HunterSurvival = "DAMAGER", + + MageArcane = "DAMAGER", + MageFrost = "DAMAGER", + MageFire = "DAMAGER", + + PaladinCombat = "DAMAGER", + PaladinHoly = "HEALER", + PaladinProtection = "TANK", + + PriestHoly = "HEALER", + PriestDiscipline = "HEALER", + PriestShadow = "DAMAGER", + + RogueAssassination = "DAMAGER", + RogueCombat = "DAMAGER", + RogueSubtlety = "DAMAGER", + + ShamanElementalCombat = "DAMAGER", + ShamanEnhancement = "DAMAGER", + ShamanRestoration = "HEALER", + + WarlockCurses = "DAMAGER", + WarlockDestruction = "DAMAGER", + WarlockSummoning = "DAMAGER", + + WarriorArm = "DAMAGER", + WarriorArms = "DAMAGER", + WarriorFury = "DAMAGER", + WarriorProtection = "TANK", +} + +--classic, tbc and wotlk role guesser based on the weights of each talent tree +function DF:GetRoleByClassicTalentTree() + if (not DF.IsTimewalkWoW()) then + return "NONE" + end + + --amount of tabs existing + local numTabs = GetNumTalentTabs() or 3 + + --store the background textures for each tab + local pointsPerSpec = {} + + for i = 1, (MAX_TALENT_TABS or 3) do + if (i <= numTabs) then + --tab information + local name, iconTexture, pointsSpent, fileName = GetTalentTabInfo(i) + if (name) then + tinsert (pointsPerSpec, {name, pointsSpent, fileName}) + end + end + end + + local MIN_SPECS = 4 + + --put the spec with more talent point to the top + table.sort(pointsPerSpec, function (t1, t2) return t1[2] > t2[2] end) + + --get the spec with more points spent + local spec = pointsPerSpec[1] + if (spec and spec [2] >= MIN_SPECS) then + local specName = spec[1] + local spentPoints = spec[2] + local specTexture = spec[3] + + local role = roleBySpecTextureName[specTexture] + return role or "NONE" + end +end + +function DF.UnitGroupRolesAssigned(unitId) if (not DF.IsTimewalkWoW()) then --Was function exist check. TBC has function, returns NONE. -Flamanis 5/16/2022 - return UnitGroupRolesAssigned (unitId) + local role = UnitGroupRolesAssigned(unitId) + + if (role == "NONE" and UnitIsUnit(unitId, "player")) then + local specializationIndex = GetSpecialization() + local id, name, description, icon, role, primaryStat = GetSpecializationInfo(specializationIndex) + return role + end + + return role else --attempt to guess the role by the player spec local classLoc, className = UnitClass(unitId) @@ -92,7 +178,8 @@ function DF.UnitGroupRolesAssigned (unitId) end end - return "NONE" + local role = DF:GetRoleByClassicTalentTree() + return role end end