参考 › 函数参考 › Platform

Platform.spells.IsSpellReady

公共

调用方式

addon.Platform:IsSpellReady(spell, now)

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

作用

检查某个法术现在能否被推荐,允许剩余冷却时间随当前公共冷却一同结束的法术。在正式服和永久服中,战斗中的冷却时间是机密值,因此改为根据永不为机密的 isEnabled、isActive 和 isOnGCD 标志判断是否就绪。此函数只检查冷却是否就绪;不检查是否已学会、距离或资源是否足够。请传入来自 evalStart 或 GetTime() 的评估时间。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器。点号引用需要将 addon.Platform 作为第一个参数;冒号调用会隐含提供它。
spellnumber | string要检查其冷却的法术 ID 或客户端可识别的法术名称。
nownumber当前评估时间,单位为秒,取自 GetTime(),通常为 evalStart。

返回值

1boolean | nil在公共冷却结束时已就绪则为 true;因其自身冷却而无法推荐时为 false;客户端无法提供可读结果时为 nil。
2string | nil结果为 nil 时的可用性或验证原因。

版本

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

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

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

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

示例

local ready = addon.Platform:IsSpellReady(value.spell, evalStart)
if ready == nil then return nil end
return ready

依赖项

源码

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

Platform.spells.IsSpellReady(self, spell, now)
    if not self:CanReadValue(now) then return nil, "restricted-value" end
    if type(now)~="number" or now~=now or now==math.huge or now==-math.huge then
        return nil, "invalid-time"
    end
    local start,duration,enabled,reason,active,onGCD=cooldownValues(self,spell)
    if start==nil then
        if active==nil then return nil,reason end
        return flagReadiness(self,enabled,active,onGCD,now)
    end
    if not enabled then return false end
    local expires=start+duration
    if duration==0 or expires<=now then return true end

    if not gcdSpell then self:GetGlobalCooldown() end
    local gcdStart,gcdDuration,gcdEnabled,why,gcdActive=cooldownValues(self,gcdSpell)
    if gcdStart==nil then
        -- The GCD's times are hidden: one known not to be running cannot
        -- cover this spell's own, still running, cooldown.
        if gcdActive~=nil and (not gcdEnabled or not gcdActive) then return false end
        return nil,why
    end
    if not gcdEnabled or gcdDuration==0 then return false end
    -- modRate controls cooldown animation; API timestamps/duration already
    -- describe expiration in GetTime seconds, so do not divide them by it.
    local gcdExpires=gcdStart+gcdDuration
    return gcdExpires>now and expires<=gcdExpires+0.001

返回函数参考