Repository navigation
fix(Core): trainer rank chains skip ranks the player has outranked - #848
Conversation
Keeps the rank-chain skip and reshapes what it reports. FirstUnsettledRank replaces FirstRankAfterHighest and GetRankState. One public helper answers where a chain starts being interesting, so both callers ask the same question instead of the UI going through a second entry point that recomputed the skip point on every row - a full scan with a set probe per rank, per rank. RebuildTrainer now computes it once per group and reads each rank with the GetState it always used. A rank below the one already owned is not Known: the player does not hold that exact rank, the spellbook has no such entry, and the Known doc says it does. The page said "Known" anyway and counted it in that total. TrainableState.Superseded names the real case, gets its own Outranked badge and its own count, and leaves Known meaning what it claims. A state with no case in the razor switch renders as "Not in client", so the badge is required, not cosmetic. Collect skipping settled ranks also stops them reaching unknownIds. That is the right call - an id below the owned rank is not a spells.json gap - but it was silent, so it is written down now. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PbJSLQ8UTBTn1Dw69shnTf
|
Good catch on the underlying rule - "a rank below one you already own is not trainable" cannot be expressed in Pushed a commit that keeps the mechanism and reshapes what it reports. One helper instead of two entry points.
Left alone: the ascending-order assumption, which Verified in gameTested with a purpose-built profile rather than by reasoning about it. Result on a live client: with the chain unlearnt, 9128 reads Trainable; after learning 6673 it reads Known and 9128 flips to Outranked. That is the whole mechanism end to end - the skip point moves to index 1, the UI override fires, and The trick is the decoy id. On a Classic client every rank you own stays in the spellbook and answers Json/class/_/Warrior_trainer_rank_test.json{
// Trainer rank-chain test bed. Loads, stands still, and fills the Spell Book page's
// Class Trainer table with one row per state so the verdicts can be read off directly.
//
// WHY A DECOY ID
// Classic clients keep every rank in the spellbook, so a lower rank of a spell you own
// normally answers HasExact = true and reads Known on its own. The bug this exercises
// needs the opposite: an id inside the chain that the player can never hold. 9128 is
// exactly that - a "Battle Shout" row present in som, tbc, wrath, cata, mop and both
// legacy DBs, Level 1, never granted to a player. Sitting below real ranks it stands in
// for a rank the client dropped, with none of the setup.
//
// Before the rank-chain fix, 9128 reads Trainable forever: not in the book, level 1, so
// nothing gates it. HasTrainableSpell stays true, and the bot walks back to the trainer
// on every pass to learn something no trainer sells. After the fix it is Outranked the
// moment any later rank in the chain is known.
//
// EXPECTED TABLE, level 12 warrior who has just learned Battle Shout rank 1, on
// tbc/wrath. This is the run in the PR screenshot:
//
// 9128 Battle Shout Outranked <- the fix; said "Known" in the first draft of
// the PR and "Trainable" before it
// 6673 Battle Shout Known rank 1
// 5242 Battle Shout Trainable rank 2, level 12 reached and not yet bought
// 6192 Battle Shout Level 22 rank 3
// 11549 Battle Shout Level 32 rank 4
// 11550 Battle Shout Level 42 rank 5
// 11551 Battle Shout Level 52 rank 6
// 25289 Battle Shout Level 60 rank 7
// 999999 #999999 Not in client no such row in any spells.json
//
// Only the 9128 row changes with the fix. Every rank below the highest one owned is
// settled, so buying rank 2 moves the skip point up and 6673 stays Known either way -
// the decoy is the only entry whose verdict the chain logic decides.
//
// Turn on "Show all ranks" - the table hides everything but Trainable by default.
//
// CROSS-CLIENT: on cata/mop (4.3.4, 5.4.8, 4.4.x, 5.5.x) ranks were deleted, so 5242
// through 25289 have no spells.json row and the whole middle of the table reads
// "Not in client" while 6673 survives at a different level. That is the other half of
// the picture worth eyeballing, and it is why the chain is left un-trimmed here.
//
// The trainer goal is wired but starves: HasTrainableSpell is false once every real
// rank is Known or Level locked, which is the point - the bot should stop going.
// To make it go, uncomment SPELL_TEST_NEVER_KNOWN below.
"ClassName": "Warrior",
"KeyboardOnly": true,
// Nothing that could pull the character into combat or move it off the spot.
"Loot": false,
"Skin": false,
"TargetNeutral": false,
"NPCMaxLevels_Above": 0,
"NPCMaxLevels_Below": 0,
"IntVariables": {
// Short, so a trainer visit can be retried without waiting ten minutes.
"TRAIN_COOLDOWN_SEC": 30,
// Ascending rank chain with a decoy at the bottom and a dead id at the top.
"SPELL_TEST_BATTLE_SHOUT": [9128, 6673, 5242, 6192, 11549, 11550, 11551, 25289, 999999]
// Negative control: a chain that is nothing but the decoy, so no later rank can ever
// settle it. Stays Trainable, keeps HasTrainableSpell true, and sends the bot to the
// trainer on every pass - the hole the rank-chain fix cannot close, since an id with
// no known rank above it is indistinguishable from one that is genuinely trainable.
// Uncomment to watch the trainer goal fire and the addon answer TRAINER_NO_MATCH.
//,"SPELL_TEST_NEVER_KNOWN": [9128]
},
// Any real path will do - the character is not meant to walk it. Northshire is the
// smallest starting route in the repo.
"PathsFilenames": [
"1-8_Human_Northshire.json"
],
"Paths": [],
"Pull": {
"Sequence": []
},
"Combat": {
"Sequence": []
},
"NPC": {
"Sequence": [
{
"Name": "ClassTrainer",
//"TrainAll": true,
"Requirements": [
"HasTrainableSpell",
"Money > 100",
"SecondsSinceTrained > TRAIN_COOLDOWN_SEC"
],
"Cost": 6.1
}
]
}
}State at level 12 with rank 1 just learned - the run in the screenshot above, on tbc/wrath:
9128 is the only row the chain logic decides - every real rank answers for itself through Flip Show all ranks on to see them - the table hides everything but Trainable by default. Since measured, and it turned out to be the stronger case. Classic runs two rank mechanics side by side on one client: /run for i=1,400 do local nm,rk=GetSpellBookItemName(i,"spell") if nm=="Battle Shout" then local _,id=GetSpellBookItemInfo(i,"spell") print(i,nm,rk,id) end end
/run for i=1,400 do local nm,rk=GetSpellBookItemName(i,"spell") if nm=="Raptor Strike" then local _,id=GetSpellBookItemInfo(i,"spell") print(i,nm,rk,id) end endMana abilities keep every rank so they can be downranked. Rage and energy abilities cost the same at every rank, so downranking buys nothing and the client replaces the entry - the lower id leaves the spellbook entirely. So the decoy was standing in for something warriors and rogues do on their own, and this is a live bug against the profiles in this repo rather than id-drift insurance. On a level 32 warrior, The decoy still earns its place in the test profile: it reproduces this on classes that do keep their ranks, and covers the other half - ids that are wrong for the running client, whether deleted on Cata and MoP, carried over from another client version, or NPC-only rows no trainer sells. |

Treats
SPELL_arrays as ordered rank chains: once a rank in the chain is known, every entry below it is settled and no longer offered for training. The Spell Book page reads the same skip point through the same helper, so the table cannot disagree with what the bot will do.Why lower ranks go missing
Classic has two rank mechanics, and both are live on the same client. Measured by dumping the spellbook, one macro per spell name:
115492973,14260,14261Mana abilities keep their ranks so they can be downranked. Rage and energy abilities gain nothing from downranking - the cost is identical at every rank - so the client replaces the entry instead, and the lower id is simply gone from the spellbook.
That is the bug, on stock clients, with the profiles this repo ships. Walking
Json/class/Warrior_1-10.json's"SPELL_BATTLE_SHOUT": [6673, 5242, 6192, 11549, 11550, 11551, 25289]on a level 32 warrior:11549is in the book, so it reads Known6673,5242,6192are not in the book, and their levels (1, 12, 22) are all met, soGetStatereads them TrainableHasTrainableSpelltherefore never clears,ClassTrainerfires on everyTRAIN_COOLDOWN_SEC, and the bot walks to a trainer that offers none of them - the addon answersTRAINER_NO_MATCHand the whole thing repeatsEvery warrior and rogue profile in the repo is exposed:
SPELL_BATTLE_SHOUT,SPELL_CHARGE,SPELL_REND,SPELL_THUNDER_CLAP,SPELL_OVERPOWER,SPELL_SUNDER_ARMORin the warrior profile alone. Hunter and caster chains are unaffected, because every owned rank still answersHasExactand already read Known.A single id cannot be judged on its own here:
6673not being in the spellbook is indistinguishable from a rank that was never trained. Only the chain says otherwise - it sits below a rank the character owns, so there is nothing left to learn there. The same reasoning covers ids that are wrong for the running client: ranks deleted on Cata and MoP, profiles carrying ids from another client version, or NPC-only rows such as9128Battle Shout that no trainer ever sells.Changes
TrainerSpells.FirstUnsettledRank- one helper, used byAny,Collectand the page, giving the index where a chain starts being interestingTrainableState.Superseded- a rank below one already owned, but not in the spellbook at this exact id. Distinct fromKnown, which means the player actually holds that rank; rendered as an "Outranked" badge with its own countCollectskips settled ranks outright, so they no longer reachunknownIdseither - an id below the owned rank is not aspells.jsongap worth reportingRelies on the ascending order
VAR_PREFIXalready documents, and answers 0 untilAllRanksReceived, the same conditionAnyandCollectalready refuse to answer before.Ranks cannot be skipped on the way up - the trainer gates rank N behind rank N-1, tooltip "Requires: Level 16, Raptor Strike (Rank 2)" - so a settled prefix is always a contiguous one, which is what makes a single skip index enough.
Verified
Level 12 warrior, live client: with the chain unlearnt
9128reads Trainable; after learning6673it reads Known and9128flips to Outranked. Test profile and screenshot in the comments.The trainer's own gating is visible with:
run at an open trainer - it prints each service as
available,unavailableorused, which is the samecategorythe addon buys on.Original report by @0x5d0: