参考 › 函数参考 › Platform

Platform.zone_pvp.GetZonePVPObservation

公共

调用方式

addon.Platform:GetZonePVPObservation()

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

作用

使用一次受保护的无参数点号调用,观测区域 PvP 分类的第一个结果。优先使用可调用的 C_PvP.GetZonePVPInfo,仅当现代 API 不可调用时才使用全局辅助函数。成功返回 nil 或没有返回值时,会产生一个已知的空记录;缺失、失败、受限或格式错误的观测保持为不可用。可读的空字符串和未来字符串保留其确切含义,未使用的返回字段不决定可用性。在现代 API 返回结果或失败后,绝不切换后端。

参数

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

返回值

1table | nil成功的观测记录,pvpType 为字符串或 nil;记录为 nil 表示不可用。
2string | nil记录为 nil 时的客户端策略、能力、调用或观测可用性原因。

版本

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

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

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

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

示例

local zone = addon.Platform:GetZonePVPObservation()
if not zone then return nil end
return zone.pvpType == "sanctuary"

源码

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

Platform.zone_pvp.GetZonePVPObservation(self)
    local family=self:GetClientFamily()
    if family~='retail' and family~='forever' and family~='era' and family~='tbc' and family~='progression' then return nil,'unsupported-policy' end
    local namespace=C_PvP
    if not self:CanReadValue(namespace) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(namespace) then return nil,'restricted-value' end
    local api
    if type(namespace)=='table' then api=namespace.GetZonePVPInfo end
    if not self:CanReadValue(api) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(api) then return nil,'restricted-value' end
    if type(api)~='function' then
        api=GetZonePVPInfo
        if not self:CanReadValue(api) then return nil,'restricted-value' end
        if canaccessvalue and not canaccessvalue(api) then return nil,'restricted-value' end
        if type(api)~='function' then return nil,'missing-api' end
    end
    local ok,pvpType=pcall(api)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(pvpType) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(pvpType) then return nil,'restricted-value' end
    if pvpType==nil then return {} end
    if type(pvpType)~='string' then return nil,'invalid-api-result' end
    return {pvpType=pvpType}

返回函数参考