Справочник › Справочник функций › Conditions

Conditions.weapon.enchantObservation

зависимость

Как вызывать

Conditions.weapon.enchantObservation(value, cache)

Запишите зависимость Conditions.weapon.enchantObservation и вызывайте её по этому имени. Вызов через пространство имён не передаёт self: используйте вызов через двоеточие или передайте объект сами.

Что делает

Reads whether the main hand, or the off hand when value.offhand is set, has a temporary weapon enchant for the weapon conditions, with its expiration and charges. Uses the cached GetWeaponEnchantInfo or the platform's composed reader.

Аргументы

ИмяТипЧто делает
valuetableCondition settings; a truthy offhand field selects the off hand.
cachetable | nilEvaluation-pass cache passed to getCached, or nil to read directly.

Возвращает

1boolean | nilTrue when enchanted, false when not, or nil when it cannot be read.
2number | nilTime until the enchant expires, as the API reports it; only when enchanted.
3number | nilCharges remaining, as the API reports them; only when enchanted.
4string | nilReason for nil: missing-api, api-error, restricted-value or invalid-weapon-observation.

Издания

Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.

  • Недоступно в этом издании (причина — во всплывающей подсказке)
  • Только пока включены запасные реализации Blizzard для устаревших функций
Игровой APIClassic EraTBC AnniversaryClassic ProgressionForeverRetail
C_PaperDollInfo.GetTemporaryEnchantmentInfoClassic EraTBC AnniversaryClassic ProgressionForeverRetail
GetWeaponEnchantInfoClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Секретные значения (Retail и Forever)

В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте nil недоступным значением, а не ложью.

Как его вызывает аддон

Исходный код

Conditions/weapon.lua, строка 60. В игре только для чтения; «Дублировать» создаёт редактируемую копию.

Conditions.weapon.enchantObservation(value, cache)
    local reader=GetWeaponEnchantInfo
    if C_PaperDollInfo and C_PaperDollInfo.GetTemporaryEnchantmentInfo then reader=addon.Platform.ComposedWeaponEnchantInfo end
    if type(reader)~="function" then return nil,nil,nil,"missing-api" end
    -- The protected cached API returns both hands' original tuple unchanged.
    ---@diagnostic disable-next-line: unbalanced-assignments
    local ok, main, mainExpires, mainCharges, _, off, offExpires, offCharges = pcall(addon.getCached, cache, reader)
    if not ok then return nil,nil,nil,"api-error" end
    local enchanted, expires, charges=main,mainExpires,mainCharges
    if value.offhand then enchanted,expires,charges=off,offExpires,offCharges end
    if not addon.Platform:CanReadValue(enchanted) then return nil,nil,nil,"restricted-value" end
    if enchanted==nil or enchanted==false or enchanted==0 then return false end
    if enchanted~=true and enchanted~=1 then return nil,nil,nil,"invalid-weapon-observation" end
    return true,expires,charges

Назад: Справочник функций