mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Add C_LossOfControl.GetSchoolLockout
Serving the school-interrupt lockout through the generic list costs a caller two full BuildList passes -- GetActiveLossOfControlDataCount runs one and GetActiveLossOfControlData runs another -- plus a Lua table per entry, and BuildList classifies up to 16 debuff slots with RecordForID on each. All of that aura work is waste for a caller that only wants the lockout, and a macro conditional reading it every frame pays it every frame. The state behind it is g_schoolLock, seven pairs of ticks. Read it directly: no table, no debuff scan, one pass. Return a mask rather than a school. Each SMSG_SPELL_COOLDOWN batch locks one school, so being kicked on fire and then frost leaves two entries active, and a caller walking the list and stopping at the first SCHOOL_INTERRUPT drops the rest. filterMask narrows the scan, which is how a caller gets one school's own remaining time instead of the aggregate. Also document that the ADDED/UPDATE events diff which effects are active, so re-locking an already-locked school extends endMs without firing either one -- that expiry cannot be cached on the events.
This commit is contained in:
@@ -359,6 +359,56 @@ int __fastcall Script_GetActiveLossOfControlData(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_LossOfControl.GetSchoolLockout([filterMask])` -> lockedMask, seconds.
|
||||
//
|
||||
// The school-interrupt slice of the active list, served without building the
|
||||
// list: reads `g_schoolLock` directly, so it allocates no table and skips the
|
||||
// 16-slot aura scan every `GetActiveLossOfControlData` call pays for. Sized for
|
||||
// per-frame conditional evaluation, where that scan and a table per call are
|
||||
// the whole cost.
|
||||
//
|
||||
// `lockedMask` ORs *every* currently locked school (`1 << schoolIndex`, the
|
||||
// same shape as `lockoutSchool`). Two schools can be locked at once — each
|
||||
// SMSG_SPELL_COOLDOWN batch locks one — so a caller that stops at the first
|
||||
// SCHOOL_INTERRUPT entry silently drops the rest.
|
||||
//
|
||||
// `seconds` runs until every school in `lockedMask` is clear, i.e. the lockout
|
||||
// ending last. It is absent (nil) when nothing is locked.
|
||||
//
|
||||
// `filterMask` narrows the scan to those schools, so one school's own remaining
|
||||
// time is `GetSchoolLockout(1 << schoolIndex)`. Omitted or 0 means all schools.
|
||||
int __fastcall Script_GetSchoolLockout(void *L) {
|
||||
int filter = ~0; // every school
|
||||
if (Game::Lua::IsNumber(L, 1)) {
|
||||
const int arg = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
if (arg != 0)
|
||||
filter = arg;
|
||||
}
|
||||
|
||||
const uint32_t now = NowMs();
|
||||
int locked = 0;
|
||||
uint32_t longest = 0;
|
||||
for (int s = 0; s < Offsets::SPELL_SCHOOL_COUNT; ++s) {
|
||||
const int bit = 1 << s;
|
||||
if ((filter & bit) == 0)
|
||||
continue;
|
||||
const uint32_t endMs = g_schoolLock[s].endMs;
|
||||
if (endMs == 0 || Reached(now, endMs))
|
||||
continue;
|
||||
locked |= bit;
|
||||
// Compare durations, never raw ticks -- see `Time::Clock`.
|
||||
const uint32_t remain = Time::Clock::Remaining(now, endMs);
|
||||
if (remain > longest)
|
||||
longest = remain;
|
||||
}
|
||||
|
||||
Game::Lua::PushNumber(L, static_cast<double>(locked));
|
||||
if (locked == 0)
|
||||
return 1; // nothing locked -> no time to report
|
||||
Game::Lua::PushNumber(L, static_cast<double>(longest) * 0.001);
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool LockoutForSpell(int spellID, uint32_t *startMs, uint32_t *endMs) {
|
||||
@@ -396,6 +446,8 @@ static void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_LossOfControl",
|
||||
"GetActiveLossOfControlData",
|
||||
&Script_GetActiveLossOfControlData);
|
||||
Game::Lua::RegisterTableFunction("C_LossOfControl", "GetSchoolLockout",
|
||||
&Script_GetSchoolLockout);
|
||||
}
|
||||
|
||||
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
Reference in New Issue
Block a user