Chame como
addon.Platform:GetUnitLevelObservation(unit)
Disponível diretamente por meio de addon; nenhuma dependência é necessária.
O que faz
Observa um nível bruto e legível da unidade em clientes conhecidos. Uma unidade ausente legível retorna exists=false; unidades presentes exigem um UnitLevel inteiro positivo e finito. Níveis de chefe desconhecidos e observações ausentes, com falha, restritas ou malformadas retornam nil com um motivo. Não usa níveis efetivos nem escalonados.
Argumentos
| Nome | Tipo | O que faz |
|---|---|---|
self | RMPlatform | Adaptador de plataforma do Rotation Master (implícito nas chamadas com dois-pontos). |
unit | string | Token de unidade cujo nível bruto deve ser observado. |
Retornos
| 1 | table | nil | Registro novo e legível com exists e, quando presente, um nível inteiro positivo. |
|---|---|---|
| 2 | string | nil | Motivo de disponibilidade ou de validação da consulta para uma observação de nível nil. |
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 jogo | |||||
|---|---|---|---|---|---|
UnitExists | |||||
UnitLevel | |||||
canaccessvalue |
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 target = addon.Platform:GetUnitLevelObservation("target")
local player = addon.Platform:GetUnitLevelObservation("player")
if not target or not player or not player.exists then return nil end
return target.exists and target.level < player.levelDependências
finite→Platform.unit_level.finite
Código-fonte
Platform/unit_level.lua, linha 28. Somente leitura no jogo; Duplicar cria uma cópia editável.
Platform.unit_level.GetUnitLevelObservation(self, unit)
if not self:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if self:GetClientFamily()=='unknown' then return nil,'unsupported-client' 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 {exists=false} end
if type(UnitLevel)~='function' then return nil,'missing-api' end
local levelOk,level=pcall(UnitLevel,unit)
if not levelOk then return nil,'api-error' end
if not self:CanReadValue(level) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(level) then return nil,'restricted-value' end
if level==nil then return nil,'level-data-unavailable' end
if not finite(level) then return nil,'invalid-api-result' end
if level<0 then return nil,'level-data-unavailable' end
if level==0 or level%1~=0 then return nil,'invalid-api-result' end
return {exists=true,level=level}




