参考 › 函数参考 › Core

Core.point_conditions.GetConditionPointResource

公共

调用方式

addon:GetConditionPointResource(unit, cache)

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

作用

使用实时的职业到资源映射和 ComboPoints 后备,解析所选单位的点数资源选择器。已知不存在时返回 false;所需的身份或选择器数据不可用时返回 nil 及原因。在评估轮次内共享完整的身份观测。只有成功的玩家职业观测会保留在当前的长期缓存中,并与原生 UnitClass 身份绑定;存在性在每个轮次都会刷新。这只选择资源,不读取其当前值或最大值。

参数

名称类型作用
selfRMAddonRotation Master 插件实例(使用冒号调用时隐含传入)。
unitstring确切的所选单位标识;只有玩家职业可以使用成功的长期缓存。
cachetable | nil评估轮次缓存;为 nil 时直接观测身份。资源映射在每次调用时实时解析。

返回值

1number | boolean | nil显式的非负整数能量选择器;已知单位不存在时为 false,所需数据不可用时为 nil。
2string | nil选择器为 nil 时的策略、查询验证或身份/选择器可用性原因。

版本

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

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

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

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

示例

local power, reason = addon:GetConditionPointResource("player", cache)
if power == nil then return nil, reason end
if power == false then return false end
return UnitPower("player", power) >= 4

依赖项

源码

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

Core.point_conditions.GetConditionPointResource(self, unit, cache)
    local platform=self.Platform
    if platform:GetCombatDataPolicy()~='probe' then return nil,'unsupported-policy' end
    if not platform:CanReadValue(unit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    local record,reason=addon.Functions.cache.getCached(cache,pointIdentity,self,unit,playerClassCacheKey)
    if not record then return nil,reason end
    if not record.exists then return false end
    local points=self.points
    if not platform:CanReadValue(points) then return nil,'restricted-value' end
    if type(points)~='table' then return nil,'invalid-point-resource-map' end
    local ok,selected=pcall(function() return points[record.class] end)
    if not ok then return nil,'api-error' end
    if not platform:CanReadValue(selected) then return nil,'restricted-value' end
    if selected==nil or selected==false then
        local enum=Enum
        if not platform:CanReadValue(enum) then return nil,'restricted-value' end
        if type(enum)~='table' then return nil,'point-resource-unavailable' end
        local typesOK,types=pcall(function() return enum.PowerType end)
        if not typesOK then return nil,'api-error' end
        if not platform:CanReadValue(types) then return nil,'restricted-value' end
        if type(types)~='table' then return nil,'point-resource-unavailable' end
        local fallbackOK,fallback=pcall(function() return types.ComboPoints end)
        if not fallbackOK then return nil,'api-error' end
        selected=fallback
        if not platform:CanReadValue(selected) then return nil,'restricted-value' end
    end
    if selected==nil then return nil,'point-resource-unavailable' end
    if type(selected)~='number' or selected~=selected or selected<0 or selected==math.huge or selected%1~=0 then return nil,'invalid-point-resource' end
    return selected

返回函数参考