호출 방법
addon.Platform:GetUnitHealthObservation(unit, includeMaximum)
addon을 통해 바로 쓸 수 있으며, 의존성이 필요 없습니다.
하는 일
지원되는 클라이언트에서 읽을 수 있는 현재 생명력과 선택적으로 최대 생명력을 관찰합니다. 없다고 읽힌 유닛은 exists=false를 반환합니다. 없거나 실패하거나 제한되거나 잘못된 관찰은 nil과 이유를 반환하며, 유닛이 없다거나 생명력 값이 무엇이라고 판단하지 않습니다.
인수
| 이름 | 유형 | 하는 일 |
|---|---|---|
self | RMPlatform | Rotation Master 플랫폼 어댑터 (콜론 호출에서는 암묵적). |
unit | string | 현재 생명력을 관찰할 유닛 토큰. |
includeMaximum | boolean | nil | true면 최대 생명력도 관찰하고, false나 nil이면 현재 생명력만 읽습니다. |
반환값
| 1 | table | nil | exists와, 있으면 현재 생명력을 담은 새로 읽은 레코드. 최대 생명력은 요청할 때만 포함됩니다. |
|---|---|---|
| 2 | string | nil | nil인 생명력 관찰에 대한 정책, 검증 또는 사용 불가 이유. |
버전
기본 제공 도우미는 모든 버전에 등록됩니다. 다른 점은 읽는 게임 API이며, API가 없으면 도우미는 대체 동작을 하거나 이유와 함께 nil을 반환합니다.
- 해당 버전에서 사용할 수 없음 (이유는 툴팁에 표시)
- Blizzard의 지원 중단 대체 함수가 켜져 있을 때만
비공개 값 (Retail과 Forever)
Retail과 Forever에서는 게임이 애드온에 비공개 값을 넘깁니다. 이 도우미는 읽는 값을 확인하고(addon.Platform:CanReadValue), 비교할 수 없는 비공개 값 대신 restricted-value 같은 이유와 함께 nil을 반환합니다. nil은 거짓이 아니라 사용할 수 없음으로 취급하세요.
예시
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.2의존성
finite→Platform.unit_health.finite
소스
Platform/unit_health.lua, 28번째 줄. 게임에서는 읽기 전용이며, 복제하면 편집 가능한 사본이 생깁니다.
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




