参考 › 函数参考 › Platform

Platform.player_flags.GetPlayerFlagObservation

公共

调用方式

addon.Platform:GetPlayerFlagObservation(kind)

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

作用

观测一个独立的无参数玩家标记:stealthed 使用 IsStealthed,control 使用 HasFullControl,outdoors 使用 IsOutdoors。可读的 true 和 false 保留其含义。所需数据缺失、失败、为 nil、受限或格式错误时返回 nil 及原因。不会添加存在性、副本或技能可用性的推断。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
kindstringstealthed、control 或 outdoors 之一;不会调用其他判断。

返回值

1boolean | nil可读的所选标记;所需数据不可用时为 nil。
2string | nil玩家标记为 nil 时的策略、查询验证或可用性原因。

版本

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

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

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

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

示例

local stealthed = addon.Platform:GetPlayerFlagObservation("stealthed")
local outdoors = addon.Platform:GetPlayerFlagObservation("outdoors")
if stealthed == nil or outdoors == nil then return nil end
return outdoors and not stealthed

源码

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

Platform.player_flags.GetPlayerFlagObservation(self, kind)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not self:CanReadValue(kind) then return nil,'restricted-value' end
    if kind~='stealthed' and kind~='control' and kind~='outdoors' then return nil,'invalid-player-flag-query' end
    local api
    if kind=='stealthed' then api=IsStealthed
    elseif kind=='control' then api=HasFullControl
    else api=IsOutdoors end
    if type(api)~='function' then return nil,'missing-api' end
    local ok,result=pcall(api)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(result) then return nil,'restricted-value' end
    if result==nil then return nil,'player-flag-unavailable' end
    if type(result)~='boolean' then return nil,'invalid-api-result' end
    return result

返回函数参考