Llamar como
addon.Platform:GetUnitPowerObservation(unit, resource, includeMaximum)
Disponible directamente a través de addon; no hace falta ninguna dependencia.
Qué hace
Observa el maná explícito o el recurso de poder en bruto actual en clientes legibles compatibles. Selecciona las identidades de recurso a partir del enum PowerType en vivo; el maná explícito nunca recurre a la barra actual. Una ausencia conocida devuelve exists=false; las observaciones que faltan, fallan, están restringidas o mal formadas devuelven nil con un motivo. Las cantidades del modo current conservan los recursos nativos con signo; el maná explícito es no negativo. Solicita el máximo solo cuando hace falta; quienes usan porcentajes deben exigir un máximo positivo.
Argumentos
| Nombre | Tipo | Qué hace |
|---|---|---|
self | RMPlatform | Adaptador de plataforma de Rotation Master (implícito en las llamadas con dos puntos). |
unit | string | Token de unidad exacto cuyo recurso se debe observar; no redirige las unidades del jugador ni de vehículo. |
resource | string | mana selecciona el enum Mana explícito en vivo; current lee y transmite la identidad real de UnitPowerType, incluido Mana cero. |
includeMaximum | boolean | nil | True también observa el máximo del recurso seleccionado; false o nil solo leen la cantidad actual. |
Retornos
| 1 | table | nil | Registro nuevo y legible con exists y, si está presente, powerType y una cantidad actual finita. El máximo solicitado es finito y no negativo. Las cantidades pueden ser fraccionarias; en el modo current, la cantidad actual puede tener signo. |
|---|---|---|
| 2 | string | nil | Motivo de política, validación de la consulta o disponibilidad para una observación de recurso nil. |
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 juego | |||||
|---|---|---|---|---|---|
Enum.PowerType | |||||
UnitExists | |||||
UnitPower | |||||
UnitPowerMax | |||||
UnitPowerType | |||||
canaccessvalue |
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 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.3Dependencias
finite→Platform.unit_power.finite
Código fuente
Platform/unit_power.lua, línea 31. Solo lectura en el juego; Duplicar crea una copia editable.
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




