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
+139
View File
@@ -0,0 +1,139 @@
// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
// `C_Spell.GetSpellLossOfControlCooldown(spellIdentifier)` ->
// startTime, duration
// `C_SpellBook.GetSpellBookItemLossOfControlCooldownInfo(slotIndex,
// spellBank)` -> SpellLossOfControlInfo | nil
// `C_SpellBook.GetSpellBookItemLossOfControlCooldownDuration(slotIndex,
// spellBank)` -> duration | nil
//
// The per-spell view of `C_LossOfControl`: the control-loss effect that
// stops THIS spell, shaped as a cooldown (`GetTime()`-epoch seconds) so an
// action button can draw the loss-of-control swipe over it.
// `LossOfControl::LockoutForSpell` decides which effects block which spells;
// this file only converts ticks and builds the Lua shapes.
//
// An effect whose end is known but whose start is not (a CC aura seen only
// in the aura array) is reported as starting now and lasting the remaining
// time — the same swipe a button would draw, just without the elapsed part.
#include "Lockout.h"
#include "Game.h"
#include "spell/Arg.h"
#include "spell/Cooldown.h"
#include "spell/Lookup.h"
#include "time/Clock.h"
#include <cstdint>
namespace LossOfControl::SpellCooldown {
namespace {
using Time::Clock::NowMs;
struct Lockout {
bool active;
uint32_t startMs;
uint32_t endMs;
};
Lockout ForSpell(int spellID) {
Lockout lock{false, 0, 0};
if (!LockoutForSpell(spellID, &lock.startMs, &lock.endMs))
return lock;
lock.active = true;
if (lock.startMs == 0)
lock.startMs = NowMs(); // end known, start not: swipe from now
return lock;
}
double StartSeconds(const Lockout &lock) {
return static_cast<double>(lock.startMs) * 0.001;
}
double DurationSeconds(const Lockout &lock) {
if (!lock.active)
return 0.0;
return static_cast<double>(Time::Clock::Elapsed(lock.startMs, lock.endMs)) *
0.001;
}
// True when the lockout outlasts the spell's own cooldown — the case where
// a button should draw the loss-of-control swipe instead of the normal one.
bool OutlastsNormalCooldown(int spellID, const Lockout &lock) {
if (!lock.active)
return false;
uint32_t cdStart = 0, cdDuration = 0;
bool enabled = false;
if (!Spell::Cooldown::Query(spellID, &cdStart, &cdDuration, &enabled) ||
cdDuration == 0)
return true;
const uint32_t now = NowMs();
return Time::Clock::Remaining(now, lock.endMs) >
Time::Clock::Remaining(now, cdStart + cdDuration);
}
int __fastcall Script_C_Spell_GetSpellLossOfControlCooldown(void *L) {
const int spellID = Spell::Arg::ResolveSpellID(L, 1);
if (Spell::Lookup::RecordForID(spellID) == nullptr)
return 0;
const Lockout lock = ForSpell(spellID);
Game::Lua::PushNumber(L, lock.active ? StartSeconds(lock) : 0.0);
Game::Lua::PushNumber(L, DurationSeconds(lock));
return 2;
}
int __fastcall Script_GetSpellBookItemLossOfControlCooldownInfo(void *L) {
const int spellID = Spell::Lookup::SpellbookItemArgsToID(L, 1, 2);
if (spellID <= 0)
return 0; // empty / out-of-range slot -> nil
const Lockout lock = ForSpell(spellID);
Game::Lua::NewTable(L);
Game::Lua::SetFieldNumber(L, "startTime",
lock.active ? StartSeconds(lock) : 0.0);
Game::Lua::SetFieldNumber(L, "duration", DurationSeconds(lock));
Game::Lua::SetFieldNumber(L, "modRate", 1.0);
Game::Lua::SetFieldBool(L, "isActive", lock.active);
Game::Lua::SetFieldBool(L, "shouldReplaceNormalCooldown",
OutlastsNormalCooldown(spellID, lock));
return 1;
}
int __fastcall Script_GetSpellBookItemLossOfControlCooldownDuration(void *L) {
const int spellID = Spell::Lookup::SpellbookItemArgsToID(L, 1, 2);
if (spellID <= 0)
return 0;
Game::Lua::PushNumber(L, DurationSeconds(ForSpell(spellID)));
return 1;
}
void RegisterLuaFunctions() {
Game::Lua::RegisterTableFunction(
"C_Spell", "GetSpellLossOfControlCooldown",
&Script_C_Spell_GetSpellLossOfControlCooldown);
Game::Lua::RegisterTableFunction(
"C_SpellBook", "GetSpellBookItemLossOfControlCooldownInfo",
&Script_GetSpellBookItemLossOfControlCooldownInfo);
Game::Lua::RegisterTableFunction(
"C_SpellBook", "GetSpellBookItemLossOfControlCooldownDuration",
&Script_GetSpellBookItemLossOfControlCooldownDuration);
}
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
} // namespace
} // namespace LossOfControl::SpellCooldown