參考資料 › 函式參考 › 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)

返回函式參考