레퍼런스 › 함수 레퍼런스 › Platform

Platform.unit_power.GetUnitPowerObservation

공개

호출 방법

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

addon을 통해 바로 쓸 수 있으며, 의존성이 필요 없습니다.

하는 일

지원되는 읽기 가능 클라이언트에서 명시적인 마나나 현재 원시 자원을 관찰합니다. 자원 식별은 실시간 PowerType 열거형에서 선택하며, 명시적인 마나는 현재 바로 대체되지 않습니다. 없는 것으로 알려지면 exists=false를 반환하고, 없거나 실패하거나 제한되거나 잘못된 관찰은 nil과 이유를 반환합니다. current 모드 수량은 부호 있는 기본 자원을 보존하며, 명시적인 마나는 음수가 아닙니다. 최댓값은 필요할 때만 요청하며, 비율을 쓰는 쪽은 양의 최댓값을 요구해야 합니다.

인수

이름유형하는 일
selfRMPlatformRotation Master 플랫폼 어댑터 (콜론 호출에서는 암묵적).
unitstring자원을 관찰할 정확한 유닛 토큰. 플레이어나 탈것 유닛을 다른 곳으로 돌리지 않습니다.
resourcestringmana는 명시적인 실시간 Mana 열거형을 선택하고, current는 Mana 0을 포함해 실제 UnitPowerType 식별을 읽어 전달합니다.
includeMaximumboolean | niltrue면 선택한 자원의 최댓값도 관찰하고, false나 nil이면 현재 수량만 읽습니다.

반환값

1table | nilexists와, 있으면 powerType과 유한한 현재 수량을 담은 새로 읽은 레코드. 요청한 최댓값은 유한하고 음수가 아닙니다. 수량은 소수일 수 있으며, current 모드의 현재 값은 부호가 있을 수 있습니다.
2string | nilnil인 자원 관찰에 대한 정책, 조회 검증 또는 사용 불가 이유.

버전

기본 제공 도우미는 모든 버전에 등록됩니다. 다른 점은 읽는 게임 API이며, API가 없으면 도우미는 대체 동작을 하거나 이유와 함께 nil을 반환합니다.

  • 해당 버전에서 사용할 수 없음 (이유는 툴팁에 표시)
  • Blizzard의 지원 중단 대체 함수가 켜져 있을 때만
게임 APIClassic 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

비공개 값 (Retail과 Forever)

Retail과 Forever에서는 게임이 애드온에 비공개 값을 넘깁니다. 이 도우미는 읽는 값을 확인하고(addon.Platform:CanReadValue), 비교할 수 없는 비공개 값 대신 restricted-value 같은 이유와 함께 nil을 반환합니다. nil은 거짓이 아니라 사용할 수 없음으로 취급하세요.

예시

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

의존성

소스

Platform/unit_power.lua, 31번째 줄. 게임에서는 읽기 전용이며, 복제하면 편집 가능한 사본이 생깁니다.

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

함수 레퍼런스(으)로 돌아가기