呼叫方式
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.
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
value | table | Condition settings; a truthy offhand field selects the off hand. |
cache | table | nil | Evaluation-pass cache passed to getCached, or nil to read directly. |
傳回值
| 1 | number | boolean | nil | Swing speed in seconds, false when there is no off-hand weapon, or nil when unavailable. |
|---|---|---|
| 2 | string | nil | Reason for nil: missing-api, api-error, restricted-value or invalid-weapon-observation. |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
- 該版本無法使用(原因請見提示)
- 僅在暴雪的棄用相容層開啟時
| 遊戲 API | |||||
|---|---|---|---|---|---|
UnitAttackSpeed | |||||
UnitRangedDamage |
插件如何呼叫它
- 武器攻擊間隔 (evaluate)
local speed,reason=swingSpeed(value,cache) - 武器攻擊間隔剩餘時間 (evaluate)
local speed,reason=swingSpeed(value,cache)
相依項目
Functions.cache.getCached→Functions.cache.getCachedFunctions.presentation.compareString→Functions.presentation.compareStringFunctions.presentation.nullable→Functions.presentation.nullableFunctions.values.compare→Functions.values.compareFunctions.values.isin→Functions.values.isinnumericObservation→Conditions.weapon.numericObservation
原始碼
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)




