参考 › 函数参考 › Platform

Platform.rotation_owner.GetPlayerOwnerClassObservation

公共

调用方式

addon.Platform:GetPlayerOwnerClassObservation()

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

作用

为循环所有权读取一次全新的受保护 UnitClass 玩家观测。只使用第二个返回值中可读的非空职业文件名。不会添加存在性、等级、载具、客户端系列或战斗策略的读取,结果也不会跨调用保留。核心所有权仍会分别验证职业标识和角色键;被覆盖的上下文提供者保留其完整的原有路径。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。

返回值

1string | nil全新的可读职业文件名;不可用时为 nil。
2string | nil职业为 nil 时的能力或观测可用性原因。

版本

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

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

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

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

示例

local class = addon.Platform:GetPlayerOwnerClassObservation()
if class == nil then return nil end
return class == "DRUID"

源码

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

Platform.rotation_owner.GetPlayerOwnerClassObservation(self)
    if type(UnitClass)~='function' then return nil,'missing-api' end
    local ok,_,class=pcall(UnitClass,'player')
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(class) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(class) then return nil,'restricted-value' end
    if class==nil then return nil,'class-data-unavailable' end
    if type(class)~='string' or class=='' then return nil,'invalid-api-result' end
    return class

返回函数参考