mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
feat(unit): UnitCreatedBySpell + consolidate the unit-token resolver
Add `UnitCreatedBySpell(unit)` — the spell that summoned a unit (a totem's totem-drop spell, a pet/guardian's summon spell), read from the unit's UNIT_CREATED_BY_SPELL descriptor field (byte +0x230). It is the same field the engine's unit-title builder consults to pick the Pet/Minion/Guardian/ Creation title, and it is broadcast, so it resolves for any unit in range. This is the summoning spell, distinct from the (server-only) spell a totem casts. Also add a single `Game::ResolveUnitToken(token)` helper that wraps the engine token->CGUnit* resolver, and route unit/Pet.cpp through it plus the Game::Read<T> field accessors — removing the hand-rolled ResolveUnitToken_t typedef and raw reinterpret_casts from this module. The name was already referenced in Offsets.h and CLAUDE.md but had never been implemented.
This commit is contained in:
+21
@@ -621,6 +621,7 @@ build instructions.
|
||||
- [`UnitIsPet(unit)`](#unitispetunit)
|
||||
- [`UnitIsOtherPlayersPet(unit)`](#unitisotherplayerspetunit)
|
||||
- [`UnitOwnerGUID(unit)`](#unitownerguidunit)
|
||||
- [`UnitCreatedBySpell(unit)`](#unitcreatedbyspellunit)
|
||||
- [`UnitStandState(unit)`](#unitstandstateunit)
|
||||
- [`UnitInRange(unit)`](#unitinrangeunit)
|
||||
- [`UnitDistanceSquared(unit)`](#unitdistancesquaredunit)
|
||||
@@ -14876,6 +14877,26 @@ if owner == UnitGUID("player") then ... end -- is it my minion?
|
||||
Reads the same owner field the pet predicates use (`CharmedBy`, else
|
||||
`CreatedBy` in the unit's `m_objectFields`).
|
||||
|
||||
### `UnitCreatedBySpell(unit)`
|
||||
|
||||
Returns the spell ID that summoned `unit`: the totem-drop spell for a totem,
|
||||
or the summon spell for a pet or guardian. Returns `nil` for an unresolved
|
||||
unit, and for a unit that no spell summoned (players and world creatures).
|
||||
|
||||
This is the summoning spell, not a spell that the unit casts later. The spell
|
||||
that a totem casts stays on the server and never reaches the client. The
|
||||
client receives this value for every summoned unit, so it works for any unit
|
||||
in range, not only your own summons. Use `GetSpellInfo` to get a readable
|
||||
name.
|
||||
|
||||
A ClassicAPI extension, not a stock WoW global.
|
||||
|
||||
```lua
|
||||
UnitCreatedBySpell("pet") -- your pet's summon spell id
|
||||
local id = UnitCreatedBySpell("target") -- target a totem → its totem spell id
|
||||
if id then print(GetSpellInfo(id)) end -- prints the name, like "Searing Totem"
|
||||
```
|
||||
|
||||
### `UnitStandState(unit)`
|
||||
|
||||
Returns the unit's standstate as an integer, matching the modern
|
||||
|
||||
Reference in New Issue
Block a user