Chiamala come
addon.Platform:GetUnitHealthObservation(unit, includeMaximum)
Disponibile direttamente tramite addon; non serve alcuna dipendenza.
Cosa fa
Osserva la salute attuale leggibile e, facoltativamente, la salute massima sui client supportati. Un'unità leggibile ma assente restituisce exists=false. Osservazioni mancanti, fallite, soggette a restrizioni o malformate restituiscono nil con un motivo; non stabiliscono un'unità assente né un valore di salute.
Argomenti
| Nome | Tipo | Cosa fa |
|---|---|---|
self | RMPlatform | Adattatore di piattaforma di Rotation Master (implicito nelle chiamate con due punti). |
unit | string | Identificativo dell'unità di cui osservare la salute attuale. |
includeMaximum | boolean | nil | True osserva anche la salute massima; false o nil legge solo la salute attuale. |
Valori restituiti
| 1 | table | nil | Record appena letto e leggibile con exists e, se presente, la salute attuale. La salute massima è inclusa solo se richiesta. |
|---|---|---|
| 2 | string | nil | Motivo di policy, di convalida o di indisponibilità quando l'osservazione della salute è nil. |
Edizioni
Le funzioni di supporto integrate sono registrate su ogni edizione. Ciò che cambia è l'API di gioco che leggono; dove ne manca una, la funzione di supporto ripiega su un'alternativa o restituisce nil con un motivo.
- Non disponibile su quell'edizione (il motivo è nel suggerimento)
- Solo mentre sono attivi i ripieghi di Blizzard per le API deprecate
| API di gioco | |||||
|---|---|---|---|---|---|
UnitExists | |||||
UnitHealth | |||||
UnitHealthMax | |||||
canaccessvalue | |||||
issecretvalue |
Valori segreti (Retail e Forever)
Su Retail e Forever il gioco fornisce agli addon valori segreti. Questa funzione di supporto controlla ciò che legge (addon.Platform:CanReadValue) e restituisce nil con un motivo come restricted-value invece di un valore segreto che non può confrontare. Considera nil come non disponibile, non come false.
Esempio
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.2Dipendenze
finite→Platform.unit_health.finite
Sorgente
Platform/unit_health.lua, riga 28. Nel gioco è in sola lettura; Duplica crea una copia modificabile.
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




