mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
95 lines
3.3 KiB
C++
95 lines
3.3 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
|
// of the GNU Lesser 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 Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// `C_Spell.IsSelfBuff(spellID)` — true iff every active effect on the
|
|
// spell targets the caster and only the caster. Read directly from
|
|
// `Spell.dbc.EffectImplicitTargetA[3]` and `EffectImplicitTargetB[3]`
|
|
// — an effect is "self-only" when both targets are either
|
|
// `TARGET_NONE` (0) or `TARGET_SELF` (1). Effects with a zero
|
|
// `Effect` code are skipped (unused effect slots).
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "dbc/Lookup.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Spell::IsSelfBuff {
|
|
|
|
namespace {
|
|
|
|
// Spell.dbc per-effect arrays. Each is an int32[3] in the record.
|
|
// Field-index derivation against the known `EffectApplyAuraName` at
|
|
// field 91 / +0x16C — the implicit-target pair sits at field 82/85.
|
|
constexpr int OFF_SPELL_EFFECT = 0xF4; // SPELL_EFFECT_* code
|
|
constexpr int OFF_SPELL_EFFECT_TARGET_A = 0x148;
|
|
constexpr int OFF_SPELL_EFFECT_TARGET_B = 0x154;
|
|
constexpr int EFFECT_COUNT = 3;
|
|
|
|
// Vanilla 1.12 implicit-target codes (CMaNGOS `Targets` enum).
|
|
constexpr int TARGET_NONE = 0;
|
|
constexpr int TARGET_SELF = 1;
|
|
|
|
bool IsSelfOnlyTarget(int target) {
|
|
return target == TARGET_NONE || target == TARGET_SELF;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
static int __fastcall Script_IsSelfBuff(void *L) {
|
|
if (!Game::Lua::IsNumber(L, 1)) {
|
|
Game::Lua::PushBool(L, false);
|
|
return 1;
|
|
}
|
|
const int spellID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
|
if (spellID <= 0) {
|
|
Game::Lua::PushBool(L, false);
|
|
return 1;
|
|
}
|
|
const uint8_t *rec = DBC::Record(Offsets::VAR_SPELL_RECORDS,
|
|
Offsets::VAR_SPELL_RECORD_COUNT,
|
|
static_cast<uint32_t>(spellID));
|
|
if (rec == nullptr) {
|
|
Game::Lua::PushBool(L, false);
|
|
return 1;
|
|
}
|
|
|
|
bool sawEffect = false;
|
|
for (int i = 0; i < EFFECT_COUNT; ++i) {
|
|
const int effect = *reinterpret_cast<const int *>(
|
|
rec + OFF_SPELL_EFFECT + i * 4);
|
|
if (effect == 0)
|
|
continue;
|
|
sawEffect = true;
|
|
const int targetA = *reinterpret_cast<const int *>(
|
|
rec + OFF_SPELL_EFFECT_TARGET_A + i * 4);
|
|
const int targetB = *reinterpret_cast<const int *>(
|
|
rec + OFF_SPELL_EFFECT_TARGET_B + i * 4);
|
|
if (!IsSelfOnlyTarget(targetA) || !IsSelfOnlyTarget(targetB)) {
|
|
Game::Lua::PushBool(L, false);
|
|
return 1;
|
|
}
|
|
}
|
|
Game::Lua::PushBool(L, sawEffect);
|
|
return 1;
|
|
}
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterTableFunction("C_Spell", "IsSelfBuff",
|
|
&Script_IsSelfBuff);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace Spell::IsSelfBuff
|