Skip to content

Commit

Permalink
On classic versions, attempt to guess the role by talent points
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Jun 3, 2022
1 parent f247c07 commit 30781c0
Showing 1 changed file with 91 additions and 4 deletions.
95 changes: 91 additions & 4 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


local dversion = 315
local dversion = 316
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary (major, minor)

Expand Down Expand Up @@ -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)
Expand All @@ -92,7 +178,8 @@ function DF.UnitGroupRolesAssigned (unitId)
end
end

return "NONE"
local role = DF:GetRoleByClassicTalentTree()
return role
end
end

Expand Down

0 comments on commit 30781c0

Please sign in to comment.