Как вызывать
addon.Platform:GetUnitCastObservation(unit, kind)
Доступен напрямую через addon; зависимость не нужна.
Что делает
Наблюдать произнесение или поддержание заклинания юнитом на клиентах с политикой проверки или ограничения. Известное отсутствие юнита или читаемый неактивный результат возвращает active=false. Активные записи содержат name либо nameReason, если имя секретно (юнит всё равно произносит заклинание), а также независимо доступные поля remainingSeconds, durationSeconds, interruptible и spellID с remainingReason, durationReason, interruptibleReason или spellReason, если необязательное поле недоступно. Отсутствующие, неудачные или ограниченные наблюдения присутствия возвращают nil с причиной.
Аргументы
| Имя | Тип | Что делает |
|---|---|---|
self | RMPlatform | Адаптер платформы Rotation Master (неявно при вызове через двоеточие). |
unit | string | Токен юнита, текущее применение или поддержание которого нужно наблюдать. |
kind | string | Вид наблюдения: cast или channel. У них разные позиции признака прерываемости во встроенном кортеже. |
Возвращает
| 1 | table | nil | Свежая читаемая запись с active, затем name или nameReason, remainingSeconds, durationSeconds, interruptible и spellID. Оставшееся время и длительность указаны в секундах; оставшееся время не опускается ниже нуля. Недоступное необязательное поле имеет собственную причину и не делает активную запись недействительной. |
|---|---|---|
| 2 | string | nil | Причина недоступности или ошибки проверки запроса, если всё наблюдение недоступно. |
Издания
Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.
- Недоступно в этом издании (причина — во всплывающей подсказке)
- Только пока включены запасные реализации Blizzard для устаревших функций
| Игровой API | |||||
|---|---|---|---|---|---|
UnitCastingInfo | |||||
UnitChannelInfo | |||||
UnitExists |
Секретные значения (Retail и Forever)
В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте nil недоступным значением, а не ложью.
Пример
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.5Зависимости
durationSeconds→Platform.casting.durationSecondsinterruptibility→Platform.casting.interruptibilityremainingSeconds→Platform.casting.remainingSecondsspellIdentity→Platform.casting.spellIdentity
Исходный код
Platform/casting.lua, строка 82. В игре только для чтения; «Дублировать» создаёт редактируемую копию.
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




