Referência › Referência de funções › Platform

Platform.casting.GetUnitCastObservation

pública

Chame como

addon.Platform:GetUnitCastObservation(unit, kind)

Disponível diretamente por meio de addon; nenhuma dependência é necessária.

O que faz

Observa uma unidade lançando ou canalizando em clientes com política de sondagem ou restrita. Uma unidade sabidamente ausente ou um resultado inativo legível retorna active=false. Registros ativos contêm name, ou nameReason quando o nome é secreto (a unidade continua lançando), e os campos remainingSeconds, durationSeconds, interruptible e spellID, disponíveis de forma independente, com remainingReason, durationReason, interruptibleReason ou spellReason quando um campo opcional está indisponível. Observações de presença ausentes, com falha ou restritas retornam nil com um motivo.

Argumentos

NomeTipoO que faz
selfRMPlatformAdaptador de plataforma do Rotation Master (implícito nas chamadas com dois-pontos).
unitstringToken de unidade cujo lançamento ou canalização atual deve ser observado.
kindstringTipo de observação: cast ou channel. Eles usam posições diferentes na tupla nativa de interrompibilidade.

Retornos

1table | nilRegistro novo e legível com active e, em seguida, name ou nameReason, remainingSeconds, durationSeconds, interruptible e spellID. O tempo restante e a duração estão em segundos; o tempo restante é limitado a zero. Um campo opcional indisponível tem seu próprio motivo; ele não invalida um registro ativo.
2string | nilMotivo de disponibilidade ou de validação da consulta quando a observação inteira está indisponível.

Edições

As funções auxiliares integradas são registradas em todas as edições. O que muda é a API do jogo que elas leem; quando uma está ausente, a função auxiliar recorre a uma alternativa ou retorna nil com um motivo.

  • Indisponível nessa edição (o motivo está na dica)
  • Só enquanto as alternativas da Blizzard para APIs obsoletas estiverem ativas
API do jogoClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitCastingInfoClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitChannelInfoClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitExistsClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Valores secretos (Retail e Forever)

No Retail e no Forever, o jogo entrega valores secretos aos addons. Esta função auxiliar verifica o que lê (addon.Platform:CanReadValue) e retorna nil com um motivo como restricted-value em vez de um valor secreto que não consegue comparar. Trate nil como indisponível, não como false.

Exemplo

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

Dependências

Código-fonte

Platform/casting.lua, linha 82. Somente leitura no jogo; Duplicar cria uma cópia editável.

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

Voltar para Referência de funções