Chame como
addon.Platform:GetUnitHealthObservation(unit, includeMaximum)
Disponível diretamente por meio de addon; nenhuma dependência é necessária.
O que faz
Observa a vida atual legível e, opcionalmente, a vida máxima em clientes suportados. Uma unidade ausente legível retorna exists=false. Observações ausentes, com falha, restritas ou malformadas retornam nil com um motivo; elas não estabelecem uma unidade ausente nem um valor de vida.
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 cuja vida atual deve ser observada. |
includeMaximum | boolean | nil | True também observa a vida máxima; false ou nil leem apenas a vida atual. |
Retornos
| 1 | table | nil | Registro novo e legível com exists e, quando presente, a vida atual. A vida máxima só é incluída quando solicitada. |
|---|---|---|
| 2 | string | nil | Motivo de política, validação ou disponibilidade para uma observação de vida 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 | |||||
UnitHealth | |||||
UnitHealthMax | |||||
canaccessvalue | |||||
issecretvalue |
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 health = addon.Platform:GetUnitHealthObservation("target", true)
if not health then return nil end
if not health.exists then return false end
if health.maximum == 0 then return nil end
return health.current / health.maximum < 0.2Dependências
finite→Platform.unit_health.finite
Código-fonte
Platform/unit_health.lua, linha 28. Somente leitura no jogo; Duplicar cria uma cópia editável.
Platform.unit_health.GetUnitHealthObservation(self, unit, 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(includeMaximum) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if includeMaximum~=nil and type(includeMaximum)~='boolean' then return nil,'invalid-health-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 type(UnitHealth)~='function' then return nil,'missing-api' end
local currentOk,current=pcall(UnitHealth,unit)
if not currentOk then return nil,'api-error' end
if not self:CanReadValue(current) then return nil,'restricted-value' end
-- Keep the native proof visible at the arithmetic boundary; the platform
-- guard above also covers older clients and the issecretvalue predicate.
if canaccessvalue and not canaccessvalue(current) then return nil,'restricted-value' end
if current==nil then return nil,'health-data-unavailable' end
if not finite(current) or current<0 then return nil,'invalid-api-result' end
local record={exists=true,current=current}
if includeMaximum then
if type(UnitHealthMax)~='function' then return nil,'missing-api' end
local maximumOk,maximum=pcall(UnitHealthMax,unit)
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,'health-data-unavailable' end
if not finite(maximum) or maximum<0 then return nil,'invalid-api-result' end
record.maximum=maximum
end
return record




