Llamar como
addon.Platform:GetUnitCastObservation(unit, kind)
Disponible directamente a través de addon; no hace falta ninguna dependencia.
Qué hace
Observa el lanzamiento o la canalización de una unidad en clientes con política de sondeo o restringida. Una unidad ausente conocida o un resultado inactivo legible devuelve active=false. Los registros activos contienen name, o nameReason cuando el nombre es secreto (la unidad sigue lanzando), y los campos remainingSeconds, durationSeconds, interruptible y spellID, disponibles de forma independiente, con remainingReason, durationReason, interruptibleReason o spellReason cuando un campo opcional no está disponible. Las observaciones de presencia que faltan, fallan o están restringidas devuelven nil con un motivo.
Argumentos
| Nombre | Tipo | Qué hace |
|---|---|---|
self | RMPlatform | Adaptador de plataforma de Rotation Master (implícito en las llamadas con dos puntos). |
unit | string | Token de unidad cuyo lanzamiento o canalización actual se debe observar. |
kind | string | Tipo de observación: cast o channel. Usan posiciones distintas en la tupla nativa de interrumpibilidad. |
Retornos
| 1 | table | nil | Registro nuevo y legible con active y luego name o nameReason, remainingSeconds, durationSeconds, interruptible y spellID. El tiempo restante y la duración están en segundos; el tiempo restante se limita a un mínimo de cero. Un campo opcional no disponible tiene su propio motivo; no invalida un registro activo. |
|---|---|---|
| 2 | string | nil | Motivo de disponibilidad o de validación de la consulta cuando toda la observación no está disponible. |
Ediciones
Las funciones auxiliares integradas se registran en todas las ediciones. Lo que cambia es la API del juego que leen; donde falta alguna, la función auxiliar recurre a una alternativa o devuelve nil con un motivo.
- No disponible en esa edición (el motivo aparece en la información emergente)
- Solo mientras estén activas las alternativas de Blizzard para API obsoletas
| API del juego | |||||
|---|---|---|---|---|---|
UnitCastingInfo | |||||
UnitChannelInfo | |||||
UnitExists |
Valores secretos (Retail y Forever)
En Retail y Forever, el juego entrega a los addons valores secretos. Esta función auxiliar comprueba lo que lee (addon.Platform:CanReadValue) y, en lugar de un secreto que no puede comparar, devuelve nil con un motivo como restricted-value. Trata nil como no disponible, no como falso.
Ejemplo
local cast = addon.Platform:GetUnitCastObservation("target", "cast")
if not cast then return nil end
if not cast.active then return false end
if cast.interruptible == nil or cast.remainingSeconds == nil then return nil end
return cast.interruptible and cast.remainingSeconds > 0.5Dependencias
durationSeconds→Platform.casting.durationSecondsinterruptibility→Platform.casting.interruptibilityremainingSeconds→Platform.casting.remainingSecondsspellIdentity→Platform.casting.spellIdentity
Código fuente
Platform/casting.lua, línea 82. Solo lectura en el juego; Duplicar crea una copia editable.
Platform.casting.GetUnitCastObservation(self, unit, kind)
local policy=self:GetCombatDataPolicy()
if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
if not self:CanReadValue(unit) or not self:CanReadValue(kind) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if kind~='cast' and kind~='channel' then return nil,'invalid-cast-query' end
if type(UnitExists)~='function' then return nil,'missing-api' end
local existsOk,exists=pcall(UnitExists,unit)
if not existsOk then return nil,'api-error' end
if not self:CanReadValue(exists) then return nil,'restricted-value' end
if exists==nil then return nil,'unit-data-unavailable' end
if type(exists)~='boolean' then return nil,'invalid-api-result' end
if not exists then return {active=false} end
local fn
if kind=='cast' then fn=UnitCastingInfo else fn=UnitChannelInfo end
if type(fn)~='function' then return nil,'missing-api' end
-- Capture into an owned tuple table without comparing native values. The
-- channel flag is slot7; casting includes castID and uses slot8 instead,
-- so the spell ID is slot9 for a cast and slot8 for a channel.
local ok,tuple=pcall(function() return {fn(unit)} end)
if not ok then return nil,'api-error' end
local name=tuple[1]
local record
if not self:CanReadValue(name) then
-- Retail and Forever make cast fields secret for a unit other than the
-- player or pet unless the spell is flagged never secret
-- (SecretWhenUnitSpellCastRestricted). A secret is a value, never nil:
-- the unit is casting, and only the name is hidden.
record={active=true,nameReason='restricted-value'}
else
if name==nil then return {active=false} end
if type(name)~='string' or name=='' then return nil,'invalid-api-result' end
record={active=true,name=name}
end
record.remainingSeconds,record.remainingReason=remainingSeconds(tuple[5])
record.durationSeconds,record.durationReason=durationSeconds(tuple[4],tuple[5])
record.interruptible,record.interruptibleReason=interruptibility(tuple[kind=='cast' and 8 or 7])
record.spellID,record.spellReason=spellIdentity(tuple[kind=='cast' and 9 or 8])
return record




