Как вызывать
addon.Platform:GetUnitPowerObservation(unit, resource, includeMaximum)
Доступен напрямую через addon; зависимость не нужна.
Что делает
Наблюдать явно ману или текущий исходный ресурс на поддерживаемых читаемых клиентах. Идентичность ресурса выбирается из действующего перечисления PowerType; явная мана никогда не заменяется текущей полосой. Известное отсутствие возвращает exists=false; отсутствующие, неудачные, ограниченные или повреждённые наблюдения возвращают nil с причиной. Количества в режиме current сохраняют знак встроенных ресурсов; явная мана неотрицательна. Максимум запрашивается только при необходимости; потребители процентов должны требовать положительный максимум.
Аргументы
| Имя | Тип | Что делает |
|---|---|---|
self | RMPlatform | Адаптер платформы Rotation Master (неявно при вызове через двоеточие). |
unit | string | Точный токен юнита, ресурс которого наблюдается; юниты игрока или транспорта не перенаправляются. |
resource | string | mana выбирает явное действующее значение перечисления Mana; current читает и передаёт фактическую идентичность UnitPowerType, включая Mana, равную нулю. |
includeMaximum | boolean | nil | true также наблюдает максимум выбранного ресурса; false или nil читает только текущее количество. |
Возвращает
| 1 | table | nil | Свежая читаемая запись с exists и, если юнит есть, powerType и конечным текущим количеством. Запрошенный максимум конечен и неотрицателен. Количества могут быть дробными; в режиме current текущее значение может быть знаковым. |
|---|---|---|
| 2 | string | nil | Причина по политике, проверке запроса или недоступности для наблюдения ресурса nil. |
Издания
Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.
- Недоступно в этом издании (причина — во всплывающей подсказке)
- Только пока включены запасные реализации Blizzard для устаревших функций
Секретные значения (Retail и Forever)
В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте 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Зависимости
finite→Platform.unit_power.finite
Исходный код
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




