Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 67 additions & 18 deletions Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ local GetSpellBookItemName = GetSpellBookItemName
local GetNumTalentTabs = GetNumTalentTabs
local GetNumTalents = GetNumTalents
local GetTalentInfo = GetTalentInfo
local GetTalentRowSelectionInfo = GetTalentRowSelectionInfo -- 5.0+ only, nil before
local GetNumSpellTabs = GetNumSpellTabs
local IsSpellKnown = IsSpellKnown

Expand Down Expand Up @@ -785,28 +786,76 @@ function DataToColor:InitSpellBookQueue()
end
end

-- MoP 5.0 replaced the tab/tier/column/rank trees with six tiers of a single pick
-- each and deleted GetNumTalentTabs/GetNumTalents with them. GetTalentInfo survives
-- with a different signature, so it is not a usable probe - GetTalentRowSelectionInfo
-- is, and it reports which talent of a tier is taken.
local MOP_TALENT_TIERS = 6 -- MAX_TALENT_TIERS is nil until Blizzard_TalentUI loads
local MOP_TALENT_COLUMNS = 3
local MOP_TALENT_TAB = 1 -- 5.0 has no tabs, but the wire format still carries one
local MOP_TALENT_RANK = 1 -- one pick per tier, so a taken talent is always rank 1

-- Collected before anything is pushed so the batch can be headed by its count.
-- Reused across calls; only ever read back up to the count of the current batch.
local talentHashes = {}

function DataToColor:InitTalentQueue()
-- MoP 5.0 replaced the tab/tier/column/rank talent trees with six tiers of a single
-- pick each, and deleted GetNumTalentTabs/GetNumTalents with them (GetTalentInfo
-- survives but with a different signature, so it is not a usable probe). Without
-- them there is nothing to enumerate in this shape; bail rather than raise, which is
-- what took out InitUpdateQueues on a 5.4.8 client and left every later queue
-- uninitialised. The C# TalentReader already copes with an empty queue - TalentDB
-- loads talent.json through LoadJsonSafe, and legacy clients ship none.
if not GetNumTalentTabs or not GetNumTalents then
return
end
-- The C# TalentReader copes with an empty batch - TalentDB loads talent.json
-- through LoadJsonSafe, and some clients ship none. Bailing rather than raising
-- matters here: an error took out InitUpdateQueues on 5.4.8 and left every
-- later queue uninitialised.
local count = 0

for tab = 1, GetNumTalentTabs(false, false) do
for i = 1, GetNumTalents(tab) do
local _, _, tier, column, currentRank = GetTalentInfo(tab, i)
if currentRank > 0 then
-- 1-3 + 1-11 + 1-4 + 1-5
local hash = tab * 1000000 + tier * 10000 + column * 10 + currentRank
DataToColor.talentQueue:push(hash)
--DataToColor:Print("talentQueue tab: ", tab, " | tier: ", tier, " | column: ", column, " | rank: ", currentRank, " | hash: ", hash)
if GetNumTalentTabs and GetNumTalents then
for tab = 1, GetNumTalentTabs(false, false) do
for i = 1, GetNumTalents(tab) do
local _, _, tier, column, currentRank = GetTalentInfo(tab, i)
if currentRank > 0 then
count = count + 1
-- 1-3 + 1-11 + 1-4 + 1-5
talentHashes[count] = tab * 1000000 + tier * 10000 + column * 10 + currentRank
--DataToColor:Print("talentQueue tab: ", tab, " | tier: ", tier, " | column: ", column, " | rank: ", currentRank)
end
end
end
elseif GetTalentRowSelectionInfo then
-- GetTalentInfo(index) over the flat grid answers
-- name, texture, tier, column, selected, available
-- with tier and column already 1-based, which is what the hash wants.
--
-- Taking them from here rather than from GetTalentRowSelectionInfo, whose
-- second return is the talent's INDEX and not its column: on a level 90 with
-- every tier taken it reports 1, 4, 8, 10, 13, 18. Using those as columns put
-- 13 into the hash, which decoded as column 3 and rendered the wrong talent,
-- while 4, 8, 10 and 18 matched no talent at all - and tier 1 looked correct
-- only because index 1 happens to equal column 1.
--
-- tonumber guards the pair, so a client answering a different shape yields no
-- talents instead of raising: raising here aborts InitUpdateQueues and leaves
-- every later queue dead.
for index = 1, MOP_TALENT_TIERS * MOP_TALENT_COLUMNS do
local _, _, tier, column, selected = GetTalentInfo(index)

tier = tonumber(tier)
column = tonumber(column)

if selected and tier and column then
count = count + 1
talentHashes[count] = MOP_TALENT_TAB * 1000000 + tier * 10000 + column * 10 + MOP_TALENT_RANK
--DataToColor:Print("talentQueue tier: ", tier, " | column: ", column)
end
end
end

-- Batch header, the same convention the spellbook and binding queues use. The
-- bot replaces its talent set on receiving it instead of merging into what it
-- already had: a respec picks different talents, and the hashes of the old ones
-- are never sent again, so nothing else would ever retire them. Sent even when
-- the count is zero - unlearning every talent has to clear the set too.
DataToColor.talentQueue:push(QUEUE_COUNT_MARKER + count)

for i = 1, count do
DataToColor.talentQueue:push(talentHashes[i])
end
end

Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Legacy Cataclysm 4.3.0)
## Version: 1.11.3
## Version: 1.11.4
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, cTimerBackport
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor_Classic.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Classic)
## Version: 1.11.3
## Version: 1.11.4
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor_TBC.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Classic TBC)
## Version: 1.11.3
## Version: 1.11.4
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Classic Wrath)
## Version: 1.11.3
## Version: 1.11.4
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
134 changes: 110 additions & 24 deletions Core/Database/TalentDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ private static T[] LoadJsonSafe<T>(ILogger<TalentDB> logger, string path)
/// </summary>
public TalentTreeElement[][] GetTalentTreesForClass(UnitClass @class)
{
// 5.0 and later: talents belong to the class, not to one of its tabs, and
// form a single six-tier grid. TalentTab still exists on those clients but
// its ids are the specialisations and no talent row references them, so
// the per-tab path below would hand back three empty trees.
TalentTreeElement[] classTalents = GetClassTalents(@class);
if (classTalents.Length > 0)
return [classTalents];

int classMask = (int)Math.Pow(2, (int)@class - 1);

// Get tab IDs for this class, ordered by OrderIndex (0, 1, 2)
Expand All @@ -86,49 +94,127 @@ public TalentTreeElement[][] GetTalentTreesForClass(UnitClass @class)
return result;
}

public bool Update(ref Talent talent, UnitClass @class, out int spellId)
// The 5.0 grid: six tiers of three picks, and it is dense - every class has
// all 18. That is what lets the result be filled by slot instead of sorted.
private const int MopTalentTiers = 6;
private const int MopTalentColumns = 3;

/// <summary>
/// 5.0 and later rows, ordered tier then column. Empty on earlier clients.
/// UnitClass shares the numbering of the client's ClassID.
/// </summary>
private TalentTreeElement[] GetClassTalents(UnitClass @class)
{
int classMask = (int)Math.Pow(2, (int)@class - 1);
int classId = (int)@class;

int tabId = -1;
int tabIndex = talent.TabNum - 1;
for (int i = 0; i < talentTabs.Length; i++)
int count = 0;
for (int i = 0; i < talentTreeElements.Length; i++)
{
var tab = talentTabs[i];
if (tab.ClassMask == classMask &&
tab.OrderIndex == tabIndex)
{
tabId = tab.Id;
break;
}
if (talentTreeElements[i].ClassID == classId)
count++;
}

if (count == 0)
return [];

// Only the returned array is allocated: no LINQ iterators, no sort
// comparer, no intermediate buffer.
TalentTreeElement[] result = new TalentTreeElement[count];
bool dense = count == MopTalentTiers * MopTalentColumns;

int next = 0;
for (int i = 0; i < talentTreeElements.Length; i++)
{
ref readonly TalentTreeElement e = ref talentTreeElements[i];
if (e.ClassID != classId)
continue;

// A tier/column pair addresses its own slot, so the result comes out
// ordered without sorting. Data that does not fit the grid keeps
// source order rather than landing out of bounds.
int slot = dense ? (e.TierID * MopTalentColumns) + e.ColumnIndex : next;
if ((uint)slot >= (uint)count)
slot = next;

result[slot] = e;
next++;
}

return result;
}

public bool Update(ref Talent talent, UnitClass @class, out int spellId)
{
spellId = 1;
if (tabId == -1) return false;

int tierIndex = talent.TierNum - 1;
int columnIndex = talent.ColumnNum - 1;
int rankIndex = talent.CurrentRank - 1;

int index = -1;
int index = IndexOfClassTalent(@class, tierIndex, columnIndex);
if (index == -1)
index = IndexOfTabTalent(@class, talent.TabNum - 1, tierIndex, columnIndex);

if (index == -1)
return false;

int[] spellIds = talentTreeElements[index].SpellIds;
if (rankIndex < 0 || rankIndex >= spellIds.Length)
return false;

spellId = spellIds[rankIndex];
if (spellDB.Spells.TryGetValue(spellId, out Spell spell))
{
talent.Name = spell.Name;
return true;
}

return false;
}

// 5.0+ layout: the tab the addon reports carries no meaning, the class does.
private int IndexOfClassTalent(UnitClass @class, int tierIndex, int columnIndex)
{
for (int i = 0; i < talentTreeElements.Length; i++)
{
var treeElement = talentTreeElements[i];
if (treeElement.TabID == tabId &&
treeElement.TierID == tierIndex &&
treeElement.ColumnIndex == columnIndex)
TalentTreeElement e = talentTreeElements[i];
if (e.ClassID == (int)@class &&
e.TierID == tierIndex &&
e.ColumnIndex == columnIndex)
return i;
}

return -1;
}

private int IndexOfTabTalent(UnitClass @class, int tabIndex, int tierIndex, int columnIndex)
{
int classMask = (int)Math.Pow(2, (int)@class - 1);

int tabId = -1;
for (int i = 0; i < talentTabs.Length; i++)
{
TalentTab tab = talentTabs[i];
if (tab.ClassMask == classMask &&
tab.OrderIndex == tabIndex)
{
index = i;
tabId = tab.Id;
break;
}
}

spellId = talentTreeElements[index].SpellIds[rankIndex];
if (spellDB.Spells.TryGetValue(spellId, out Spell spell))
if (tabId == -1)
return -1;

for (int i = 0; i < talentTreeElements.Length; i++)
{
talent.Name = spell.Name;
return true;
TalentTreeElement e = talentTreeElements[i];
if (e.TabID == tabId &&
e.TierID == tierIndex &&
e.ColumnIndex == columnIndex)
return i;
}

return false;
return -1;
}
}
Loading
Loading