feat(spellbook): add the skill-line, cast-count, and loss-of-control surface

Nine C_SpellBook functions, two C_Spell functions, and one event, all
backed by engine data the stock Lua surface never exposed:

- LEARNED_SPELL_IN_SKILL_LINE(spellID, skillLineIndex, isGuildPerkSpell),
  fired from the learn-spell hook under the engine's own
  LEARNED_SPELL_IN_TAB gate (notified AND appended to the book). The
  learn/unlearn co-hooks move from spell/Info.cpp to spell/Learn.cpp.
- GetNumSpellBookSkillLines / GetSpellBookSkillLineInfo /
  GetSpellBookItemSkillLineIndex / GetSkillLineIndexByID, reading the
  engine's tab array ({skillLineID, numSpells} entries at 0x00B71160).
  The info table calls the engine's own Script_GetSpellTabInfo for the
  name and icon.
- C_Spell.GetSpellCastCount / GetSpellBookItemCastCount: the minimum
  over reagent slots of floor(carried / required), where carried is
  equipped + bags 0..4. GetActionCount / IsConsumableAction are
  item-only in this client, so the count is computed, not mirrored.
- C_Spell.GetSpellLossOfControlCooldown /
  GetSpellBookItemLossOfControlCooldownInfo / ...Duration: the
  C_LossOfControl effect that blocks a given spell, shaped as a
  cooldown. Silence and pacify gate on Spell.dbc PreventionType
  (+0x294, verified against six known spells).
- IsClassTalentSpellBookItem: Talent.dbc rank spells plus trained
  higher ranks via SkillLineAbility's next-rank link (+0x20, verified
  on Mortal Strike). Talent::SpellSet now owns the talent spell set
  that GetCurrentLevelSpells already used.
- ContainsAnyDisenchantSpell: any known spell with effect 99.

Shared helpers added along the way: Spell::Lookup::SpellBankArgToBookType
and SpellbookItemArgsToID, Spell::Cooldown::Query, and
LossOfControl::LockoutForSpell.
This commit is contained in:
Brues
2026-09-09 00:10:52 -05:00
parent 8ca415e9a0
commit 14fa610bc8
18 changed files with 1227 additions and 140 deletions
+55
View File
@@ -43,6 +43,7 @@
#include "aura/Source.h"
#include "dbc/Lookup.h"
#include "event/Custom.h"
#include "lossofcontrol/Lockout.h"
#include "net/PacketDispatch.h"
#include "net/PacketReader.h"
#include "spell/CrowdControl.h"
@@ -52,6 +53,7 @@
#include "unit/Identity.h"
#include <cstdint>
#include <cstring>
namespace LossOfControl {
@@ -214,6 +216,31 @@ int BuildList(LocEntry *out, int maxOut) {
return n;
}
// Which spells a control-loss effect blocks — the server's cast gates
// (`Spell::CheckCast`) restated: a school lockout gates by the spell's school
// (`Unit::IsSpellSchoolLocked`); stun / fear / confuse / charm / possess gate
// every cast (UNIT_STAT_STUNNED / FLEEING / CONFUSED, or control handed to
// another unit); silence and pacify gate by the spell's PreventionType
// (UNIT_FLAG_SILENCED ↔ SPELL_PREVENTION_TYPE_SILENCE, UNIT_FLAG_PACIFIED ↔
// _PACIFY). Root and disarm stop no cast.
bool Blocks(const LocEntry &e, int schoolIdx, int preventionType) {
const char *t = e.locType;
if (std::strcmp(t, "SCHOOL_INTERRUPT") == 0)
return (e.schoolMask & (1 << schoolIdx)) != 0;
if (std::strcmp(t, "STUN") == 0 || std::strcmp(t, "FEAR") == 0 ||
std::strcmp(t, "CONFUSE") == 0 || std::strcmp(t, "CHARM") == 0 ||
std::strcmp(t, "POSSESS") == 0)
return true;
const bool both = std::strcmp(t, "PACIFYSILENCE") == 0;
if ((both || std::strcmp(t, "SILENCE") == 0) &&
preventionType == Offsets::SPELL_PREVENTION_TYPE_SILENCE)
return true;
if ((both || std::strcmp(t, "PACIFY") == 0) &&
preventionType == Offsets::SPELL_PREVENTION_TYPE_PACIFY)
return true;
return false;
}
// ---- LOSS_OF_CONTROL_ADDED / _UPDATE events (WorldTick poll-and-diff) ------
//
// Effect *expiry* (a school lockout timing out, a CC aura falling off) has no
@@ -334,6 +361,34 @@ int __fastcall Script_GetActiveLossOfControlData(void *L) {
} // namespace
bool LockoutForSpell(int spellID, uint32_t *startMs, uint32_t *endMs) {
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
if (rec == nullptr)
return false;
const int school = SpellSchoolIndex(rec);
const int prevention =
Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_PREVENTION_TYPE);
LocEntry entries[32];
const int n = BuildList(entries, 32);
const uint32_t now = NowMs();
bool found = false;
for (int i = 0; i < n; ++i) {
const LocEntry &e = entries[i];
if (e.endMs == 0 || Reached(now, e.endMs))
continue; // timing unknown, or already over
if (!Blocks(e, school, prevention))
continue;
if (!found || Time::Clock::Remaining(now, e.endMs) >
Time::Clock::Remaining(now, *endMs)) {
*startMs = e.startMs;
*endMs = e.endMs;
found = true;
}
}
return found;
}
static void RegisterLuaFunctions() {
Game::Lua::RegisterTableFunction(
"C_LossOfControl", "GetActiveLossOfControlDataCount",