参考 › 函数参考 › Platform

Platform.loss_of_control.GetLossOfControlEvent

公共

调用方式

addon.Platform:GetLossOfControlEvent(index, kind)

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

作用

按原生索引和所请求的主题种类,读取一条有文档的活跃失控记录行。type 查询只需要可读的控制类型字符串;school 查询只需要可读的有限非负整数法术类型掩码。可选的计时以有限的 timeRemaining 或逐字段的显式原因返回,因此不相关的主题不需要可用的计时器。缺失的行是不可用的快照观测。不会使用显示字段、推断的截止时间、持续时间总和、最大值或原生别名回退。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
indexnumber在 RM 256 行扫描预算内、从 1 开始的原生整数活跃行索引。
kindstring只能是 type 或 school;选择所需的主题字段,而不要求另一个。

返回值

1table | nil规范化的所请求主题,包含有限的 timeRemaining 或 timeRemainingReason;所需的行或主题不可用时为 nil。
2string | nil记录为 nil 时的策略、查询、能力或所需行/主题的可用性原因。

版本

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

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

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

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

示例

local count = addon.Platform:GetLossOfControlCount()
if count == nil then return nil end
if count == 0 then return false end
local row = addon.Platform:GetLossOfControlEvent(1, "type")
if not row then return nil end
return row.locType == "STUN"

源码

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

Platform.loss_of_control.GetLossOfControlEvent(self, index, kind)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not self:CanReadValue(index) or not self:CanReadValue(kind) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(index) then return nil,'restricted-value' end
    if type(index)~='number' or index~=index or index==math.huge or index==-math.huge or index<1 or index%1~=0 then return nil,'invalid-loss-of-control-query' end
    if kind~='type' and kind~='school' then return nil,'invalid-loss-of-control-query' end
    if index>256 then return nil,'loss-of-control-budget-exceeded' end
    local namespace=C_LossOfControl
    if not self:CanReadValue(namespace) then return nil,'restricted-value' end
    if type(namespace)~='table' then return nil,'missing-api' end
    local methodOk,method=pcall(function() return namespace.GetActiveLossOfControlData end)
    if not methodOk then return nil,'api-error' end
    if not self:CanReadValue(method) then return nil,'restricted-value' end
    if type(method)~='function' then return nil,'missing-api' end
    local ok,event=pcall(method,index)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(event) then return nil,'restricted-value' end
    if event==nil then return nil,'loss-of-control-event-unavailable' end
    if type(event)~='table' then return nil,'invalid-api-result' end
    local subjectOk,subject=pcall(function() return event[kind=='type' and 'locType' or 'lockoutSchool'] end)
    if not subjectOk then return nil,'api-error' end
    if not self:CanReadValue(subject) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(subject) then return nil,'restricted-value' end
    if subject==nil then return nil,'loss-of-control-subject-unavailable' end
    local record={}
    if kind=='type' then
        if type(subject)~='string' then return nil,'invalid-api-result' end
        record.locType=subject
    else
        if type(subject)~='number' or subject~=subject or subject==math.huge or subject==-math.huge or subject<0 or subject%1~=0 then return nil,'invalid-api-result' end
        record.lockoutSchool=subject
    end
    local timeOk,remaining=pcall(function() return event.timeRemaining end)
    if not timeOk then record.timeRemainingReason='api-error'
    elseif not self:CanReadValue(remaining) then record.timeRemainingReason='restricted-value'
    elseif canaccessvalue and not canaccessvalue(remaining) then record.timeRemainingReason='restricted-value'
    elseif remaining==nil then record.timeRemainingReason='loss-of-control-time-unavailable'
    elseif type(remaining)~='number' or remaining~=remaining or remaining==math.huge or remaining==-math.huge then record.timeRemainingReason='invalid-api-result'
    else record.timeRemaining=remaining end
    return record

返回函数参考