参考 › 函数参考 › Platform

Platform.points.GetUnitPointFragmentObservation

公共

调用方式

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

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

作用

观测客户端以碎片形式报告的点数资源(熊猫人之谜的爆燃灰烬)。current 严格使用 UnitPower(unit,powerType,true),maximum 严格使用 UnitPowerMax(unit,powerType,true);结果除以暴雪的 MAX_POWER_PER_EMBER(10),因此 35 个碎片即为 3.5。仅限探测策略。缺失、失败、受限或格式错误的数据保持不可用;绝不回退到整单位查询。不会添加缓存。

参数

名称类型作用
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 embers = Enum.PowerType.BurningEmbers
if not embers then return nil end
local current = addon.Platform:GetUnitPointFragmentObservation("player", embers, "current")
if current == nil then return nil end
return current >= 3.5

依赖项

源码

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

Platform.points.GetUnitPointFragmentObservation(self, unit, powerType, kind)
    if self:GetCombatDataPolicy()~='probe' 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
    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,true)
    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/pointFragmentsPerWhole

返回函数参考