参考 › 函数参考 › Conditions

Conditions.weapon.swingSpeed

依赖项

调用方式

Conditions.weapon.swingSpeed(value, cache)

记录依赖项 Conditions.weapon.swingSpeed,然后按该名称调用。带命名空间的调用不会传入 self:请使用冒号调用,或自行传入该对象。

作用

Reads the player's main-hand, or off-hand when value.offhand is set, attack speed from the cached UnitAttackSpeed for the swing timer conditions. An off-hand check with no off-hand speed returns false.

参数

名称类型作用
valuetableCondition settings; a truthy offhand field selects the off hand.
cachetable | nilEvaluation-pass cache passed to getCached, or nil to read directly.

返回值

1number | boolean | nilSwing speed in seconds, false when there is no off-hand weapon, or nil when unavailable.
2string | nilReason for nil: missing-api, api-error, restricted-value or invalid-weapon-observation.

版本

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

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

插件如何调用它

依赖项

源码

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

Conditions.weapon.swingSpeed(value, cache)
    -- Ranged: the Auto Shot or wand interval (UnitRangedDamage), false with no
    -- ranged attack; the melee hands read UnitAttackSpeed.
    if value.ranged then
        local speed,reason=Functions.cache.getCached(cache,addon.Platform.GetRangedSwingSpeed,addon.Platform)
        if speed==nil then return nil,reason end
        return speed
    end
    if type(UnitAttackSpeed)~="function" then return nil,"missing-api" end
    -- pcall forwards the mainhand and offhand speeds from the observation.
    ---@diagnostic disable-next-line: unbalanced-assignments
    local ok,main,off=pcall(addon.getCached,cache,UnitAttackSpeed,"player")
    if not ok then return nil,"api-error" end
    local speed=main
    if value.offhand then
        speed=off
        -- No off-hand weapon: the API returns no off-hand speed. That is a
        -- reading (nothing to swing), so off-hand checks are false.
        if speed==nil then return false end
    end
    return numericObservation(speed)

返回函数参考