参考 › 函数参考 › Platform

Platform.points.GetUnitPointPowerObservation

公共

调用方式

addon.Platform:GetUnitPointPowerObservation(unit, powerType, kind)

可直接通过 addon 使用,无需依赖项。

作用

使用确切的双参数 UnitPower 或 UnitPowerMax 查询,读取一个显式选择的点数资源数量。选择器为必需;不会推断主要资源或重新映射角色。保留有限的带符号、小数和零数量,不进行截断。缺失、失败、受限或非有限的数据保持为不可用。当前值和最大值是分开的观测,因此调用方可以共享当前值快照,同时按需延迟请求最大值。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
unitstring要请求其所选资源数量的确切单位标识。
powerTypenumber显式、可读、有限的非负整数能量选择器,包括零。
kindstring只能是 current(对应 UnitPower)或 maximum(对应 UnitPowerMax);不会添加其他原生查询。

返回值

1number | nil有限的原生资源数量,保留其符号和小数部分;不可用时为 nil。
2string | nil数量为 nil 时的策略、查询验证或可用性原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
UnitPower经典旧世TBC 周年版经典进阶服永久服正式服
UnitPowerMax经典旧世TBC 周年版经典进阶服永久服正式服
canaccessvalue经典旧世TBC 周年版经典进阶服永久服正式服

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

示例

local holyPower = addon.Platform:GetUnitPointPowerObservation("player", Enum.PowerType.HolyPower, "current")
if holyPower == nil then return nil end
return holyPower >= 3

依赖项

源码

Platform/points.lua,第 189 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Platform.points.GetUnitPointPowerObservation(self, unit, powerType, kind)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and (policy~='restricted' or not self:IsNeverSecretPointPower(powerType)) then return nil,'unsupported-policy' end
    if not self:CanReadValue(unit) or not self:CanReadValue(powerType) or not self:CanReadValue(kind) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if type(powerType)~='number' or powerType~=powerType or powerType<0 or powerType==math.huge or powerType%1~=0 then return nil,'invalid-point-power-query' end
    if kind~='current' and kind~='maximum' then return nil,'invalid-point-power-query' end
    if powerType==pointFragmentType then return self:GetUnitPointFragmentObservation(unit,powerType,kind) end
    local api
    if kind=='current' then api=UnitPower else api=UnitPowerMax end
    if type(api)~='function' then return nil,'missing-api' end
    local ok,result=pcall(api,unit,powerType)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(result) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(result) then return nil,'restricted-value' end
    if result==nil then return nil,'point-power-unavailable' end
    if type(result)~='number' or result~=result or result==math.huge or result==-math.huge then return nil,'invalid-api-result' end
    return result

返回函数参考