Riferimento › Riferimento delle funzioni › Platform

Platform.unit_power.GetUnitPowerObservation

pubblica

Chiamala come

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

Disponibile direttamente tramite addon; non serve alcuna dipendenza.

Cosa fa

Osserva il mana esplicito o la risorsa grezza attuale sui client leggibili supportati. Seleziona le identità delle risorse dall'enum PowerType attuale; il mana esplicito non ripiega mai sulla barra attuale. Un'assenza accertata restituisce exists=false; osservazioni mancanti, fallite, soggette a restrizioni o malformate restituiscono nil con un motivo. Le quantità in modalità current preservano le risorse native con segno; il mana esplicito è non negativo. Richiedi il massimo solo se necessario; chi usa le percentuali deve richiedere un massimo positivo.

Argomenti

NomeTipoCosa fa
selfRMPlatformAdattatore di piattaforma di Rotation Master (implicito nelle chiamate con due punti).
unitstringIdentificativo esatto dell'unità di cui osservare la risorsa; non reindirizza le unità del giocatore o dei veicoli.
resourcestringmana seleziona esplicitamente l'enum Mana attuale; current legge e inoltra l'identità effettiva di UnitPowerType, incluso Mana zero.
includeMaximumboolean | nilTrue osserva anche il massimo della risorsa selezionata; false o nil legge solo la quantità attuale.

Valori restituiti

1table | nilRecord appena letto e leggibile con exists e, se presente, powerType e una quantità attuale finita. Il massimo richiesto è finito e non negativo. Le quantità possono essere frazionarie; in modalità current la quantità attuale può avere segno.
2string | nilMotivo di policy, di convalida della query o di indisponibilità quando l'osservazione della risorsa è 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 giocoClassic 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

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 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

Dipendenze

Sorgente

Platform/unit_power.lua, riga 31. Nel gioco è in sola lettura; Duplica crea una copia modificabile.

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

Torna a Riferimento delle funzioni