参考 › 函数参考 › Platform

Platform.spells.GetSpellCharges

公共

调用方式

addon.Platform:GetSpellCharges(spell)

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

作用

读取规范化的充能记录:currentCharges、maxCharges、cooldownStartTime、cooldownDuration、chargeModRate 和 isActive。不受支持的法术或受限的客户端数据会返回 nil 及原因。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器。点号引用需要将 addon.Platform 作为第一个参数;冒号调用会隐含提供它。
spellnumber | string要读取其充能的法术 ID 或客户端可识别的法术名称。

返回值

1table | nil可读的充能记录;不可用时为 nil。
2string | nil记录为 nil 时的可用性或验证原因。

版本

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

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

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

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

示例

local charges = addon.Platform:GetSpellCharges(value.spell)
if not charges then return nil end
-- spend a charge rather than waste recharge time
return charges.currentCharges == charges.maxCharges

依赖项

源码

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

Platform.spells.GetSpellCharges(self, spell)
    local valid,reason=identifier(spell)
    if not valid then return nil,reason end
    local ok,record,built
    if C_Spell and type(C_Spell.GetSpellCharges)=="function" then
        ok,record=pcall(C_Spell.GetSpellCharges,spell)
    elseif type(GetSpellCharges)=="function" then
        local current,maximum,start,duration,rate
        ok,current,maximum,start,duration,rate=pcall(GetSpellCharges,spell)
        if not ok then return nil,"api-error" end
        record={currentCharges=current,maxCharges=maximum,cooldownStartTime=start,cooldownDuration=duration,chargeModRate=rate};built=true
    else return nil,"missing-api" end
    if not ok then return nil,"api-error" end
    if not self:CanReadValue(record) then return nil,"restricted-value" end
    if record==nil then return nil,"spell-charges-unavailable" end
    local charges,why=own(record,chargeFields,built)
    if not charges then return nil,why end
    if next(charges)==nil then return nil,"spell-charges-unavailable" end
    local current,maximum,start,duration=charges.currentCharges,charges.maxCharges,charges.cooldownStartTime,charges.cooldownDuration
    if current==nil or maximum==nil or start==nil or duration==nil or current<0 or current%1~=0
        or maximum<1 or maximum%1~=0 or current>maximum or start<0 or duration<0
        or charges.chargeModRate and charges.chargeModRate<=0 then return nil,"invalid-api-result" end
    local active=current<maximum and start>0 and duration>0
    if charges.isActive==nil then charges.isActive=active
    elseif charges.isActive and not active then return nil,"invalid-api-result" end
    charges.chargeModRate=charges.chargeModRate or 1
    return charges

返回函数参考