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

Platform.unit_power.GetUnitPowerObservation

pública

Chame como

addon.Platform:GetUnitPowerObservation(unit, resource, includeMaximum)

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

O que faz

Observa a mana explícita ou o recurso de poder bruto atual em clientes legíveis suportados. Seleciona as identidades de recurso a partir do enum PowerType ao vivo; a mana explícita nunca recorre à barra atual. Ausência conhecida retorna exists=false; observações ausentes, com falha, restritas ou malformadas retornam nil com um motivo. As quantidades do modo current preservam recursos nativos com sinal; a mana explícita é não negativa. Solicita o máximo apenas quando necessário; quem usa porcentagens deve exigir um máximo positivo.

Argumentos

NomeTipoO que faz
selfRMPlatformAdaptador de plataforma do Rotation Master (implícito nas chamadas com dois-pontos).
unitstringToken de unidade exato cujo recurso deve ser observado; isso não redireciona unidades do jogador ou de veículo.
resourcestringmana seleciona o enum Mana explícito ao vivo; current lê e repassa a identidade real de UnitPowerType, incluindo Mana zero.
includeMaximumboolean | nilTrue também observa o máximo do recurso selecionado; false ou nil leem apenas a quantidade atual.

Retornos

1table | nilRegistro novo e legível com exists e, quando presente, powerType e uma quantidade atual finita. O máximo solicitado é finito e não negativo. As quantidades podem ser fracionárias; no modo current, a quantidade atual pode ter sinal.
2string | nilMotivo de política, validação da consulta ou disponibilidade para uma observação de recurso 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 jogoClassic EraTBC AnniversaryClassic ProgressionForeverRetail
Enum.PowerTypeClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitExistsClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitPowerClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitPowerMaxClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitPowerTypeClassic EraTBC AnniversaryClassic ProgressionForeverRetail
canaccessvalueClassic 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 power = addon.Platform:GetUnitPowerObservation("player", "mana", true)
if not power or not power.exists or not power.maximum then return nil end
if power.maximum <= 0 then return nil end
return power.current / power.maximum < 0.3

Dependências

Código-fonte

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

Platform.unit_power.GetUnitPowerObservation(self, unit, resource, includeMaximum)
    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(resource) or not self:CanReadValue(includeMaximum) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if resource~='mana' and resource~='current' then return nil,'invalid-power-query' end
    if includeMaximum~=nil and type(includeMaximum)~='boolean' then return nil,'invalid-power-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 {exists=false} end
    if not self:CanReadValue(Enum) then return nil,'restricted-value' end
    if type(Enum)~='table' then return nil,'power-type-unavailable' end
    local types=Enum.PowerType
    if not self:CanReadValue(types) then return nil,'restricted-value' end
    if type(types)~='table' then return nil,'power-type-unavailable' end
    local powerType
    if resource=='mana' then
        powerType=types.Mana
    else
        if type(UnitPowerType)~='function' then return nil,'missing-api' end
        local ok
        ok,powerType=pcall(UnitPowerType,unit)
        if not ok then return nil,'api-error' end
    end
    if not self:CanReadValue(powerType) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(powerType) then return nil,'restricted-value' end
    if powerType==nil then return nil,'power-type-unavailable' end
    if not finite(powerType) or powerType<0 or powerType%1~=0 then return nil,'invalid-api-result' end
    local known=false
    for _,id in pairs(types) do
        if self:CanReadValue(id) and type(id)=='number' and id==powerType then known=true;break end
    end
    if not known then return nil,'power-type-unavailable' end
    if type(UnitPower)~='function' then return nil,'missing-api' end
    local currentOk,current=pcall(UnitPower,unit,powerType)
    if not currentOk then return nil,'api-error' end
    if not self:CanReadValue(current) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(current) then return nil,'restricted-value' end
    if current==nil then return nil,'power-data-unavailable' end
    if not finite(current) or resource=='mana' and current<0 then return nil,'invalid-api-result' end
    local record={exists=true,powerType=powerType,current=current}
    if includeMaximum then
        if type(UnitPowerMax)~='function' then return nil,'missing-api' end
        local maximumOk,maximum=pcall(UnitPowerMax,unit,powerType)
        if not maximumOk then return nil,'api-error' end
        if not self:CanReadValue(maximum) then return nil,'restricted-value' end
        if canaccessvalue and not canaccessvalue(maximum) then return nil,'restricted-value' end
        if maximum==nil then return nil,'power-data-unavailable' end
        if not finite(maximum) or maximum<0 then return nil,'invalid-api-result' end
        record.maximum=maximum
    end
    return record

Voltar para Referência de funções