Referencia › Referencia de funciones › Platform

Platform.unit_stat.GetUnitStatObservation

pública

Llamar como

addon.Platform:GetUnitStatObservation(unit, stat)

Disponible directamente a través de addon; no hace falta ninguna dependencia.

Qué hace

Observa la estadística efectiva solo a partir del segundo retorno nativo. En clientes con política de sondeo o restringida consulta exactamente UnitExists(unit) y luego UnitStat(unit,stat) para el selector 1..5 o UnitArmor(unit) para el selector 6. Una ausencia conocida devuelve exists=false; los datos necesarios que faltan, fallan, están restringidos o no son finitos devuelven nil. Conserva los valores finitos con signo, fraccionarios y cero; ignora todos los campos de la tupla no usados. La ruta 1..6 es una política de selector de RM, no un límite del dominio de valores nativo.

Argumentos

NombreTipoQué hace
selfRMPlatformAdaptador de plataforma de Rotation Master (implícito en las llamadas con dos puntos).
unitstringToken de unidad seleccionado no vacío, sin cambios en las llamadas nativas.
statnumberSelector de estadística de RM entero 1..5, o 6 para la armadura efectiva.

Retornos

1table | nilRegistro con exists=false, o exists=true y un valor finito; nil si no está disponible.
2string | nilMotivo de disponibilidad de la consulta, la política o la observación.

Ediciones

Las funciones auxiliares integradas se registran en todas las ediciones. Lo que cambia es la API del juego que leen; donde falta alguna, la función auxiliar recurre a una alternativa o devuelve nil con un motivo.

  • No disponible en esa edición (el motivo aparece en la información emergente)
  • Solo mientras estén activas las alternativas de Blizzard para API obsoletas
API del juegoClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitArmorClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitExistsClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitStatClassic EraTBC AnniversaryClassic ProgressionForeverRetail
canaccessvalueClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Valores secretos (Retail y Forever)

En Retail y Forever, el juego entrega a los addons valores secretos. Esta función auxiliar comprueba lo que lee (addon.Platform:CanReadValue) y, en lugar de un secreto que no puede comparar, devuelve nil con un motivo como restricted-value. Trata nil como no disponible, no como falso.

Ejemplo

local armor = addon.Platform:GetUnitStatObservation("player", 6)
if not armor or not armor.exists then return nil end
return armor.value >= 10000

Dependencias

Código fuente

Platform/unit_stat.lua, línea 27. Solo lectura en el juego; Duplicar crea una copia editable.

Platform.unit_stat.GetUnitStatObservation(self, unit, stat)
    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(stat) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if not finite(stat) or stat%1~=0 or stat<1 or stat>6 then return nil,'invalid-stat-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
    local fn
    if stat==6 then fn=UnitArmor else fn=UnitStat end
    if type(fn)~='function' then return nil,'missing-api' end
    local ok,_,effective
    if stat==6 then ok,_,effective=pcall(fn,unit)
    else ok,_,effective=pcall(fn,unit,stat) end
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(effective) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(effective) then return nil,'restricted-value' end
    if effective==nil then return nil,'stat-data-unavailable' end
    if not finite(effective) then return nil,'invalid-api-result' end
    return {exists=true,value=effective}

Volver a Referencia de funciones