Référence › Référence des fonctions › Platform

Platform.unit_power.GetUnitPowerObservation

publique

Appel

addon.Platform:GetUnitPowerObservation(unit, resource, includeMaximum)

Disponible directement via addon ; aucune dépendance n'est nécessaire.

Ce qu'elle fait

Observe le mana explicite ou la ressource brute actuelle sur les clients lisibles pris en charge. Les identités de ressource sont choisies dans l'énumération PowerType en direct ; le mana explicite ne se rabat jamais sur la barre actuelle. Une absence connue renvoie exists=false ; les observations manquantes, en échec, restreintes ou mal formées renvoient nil avec un motif. En mode current, les quantités conservent le signe des ressources natives ; le mana explicite est non négatif. Ne demandez le maximum qu'en cas de besoin ; les consommateurs de pourcentage doivent exiger un maximum positif.

Arguments

NomTypeCe qu'elle fait
selfRMPlatformAdaptateur de plateforme Rotation Master (implicite avec un appel par deux-points).
unitstringIdentifiant d'unité exact dont la ressource doit être observée ; les unités joueur ou véhicule ne sont pas redirigées.
resourcestringmana sélectionne l'énumération Mana explicite en direct ; current lit et transmet l'identité UnitPowerType réelle, y compris Mana zéro.
includeMaximumboolean | niltrue observe aussi le maximum de la ressource sélectionnée ; false ou nil ne lit que la quantité actuelle.

Retours

1table | nilEnregistrement frais et lisible avec exists et, si l'unité est présente, powerType et une quantité actuelle finie. Le maximum demandé est fini et non négatif. Les quantités peuvent être fractionnaires ; en mode current, la valeur actuelle peut être signée.
2string | nilMotif de politique, de validation de la requête ou de disponibilité pour une observation de ressource nil.

Éditions

Les fonctions utilitaires intégrées sont enregistrées sur toutes les éditions. Ce qui diffère, c'est l'API du jeu qu'elles lisent ; quand l'une manque, la fonction utilitaire se rabat sur une alternative ou renvoie nil avec une raison.

  • Indisponible sur cette édition (la raison figure dans l'infobulle)
  • Uniquement tant que les solutions de repli de Blizzard pour les fonctions obsolètes sont actives
API du jeuClassic EraTBC AnniversaryClassic ProgressionForeverRetail
Enum.PowerTypeClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitExistsClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitPowerClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitPowerMaxClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitPowerTypeClassic EraTBC AnniversaryClassic ProgressionForeverRetail
canaccessvalueClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Valeurs secrètes (Retail et Forever)

Sur Retail et Forever, le jeu transmet aux addons des valeurs secrètes. Cette fonction utilitaire vérifie ce qu'elle lit (addon.Platform:CanReadValue) et renvoie nil avec une raison telle que restricted-value au lieu d'une valeur secrète qu'elle ne peut pas comparer. Traitez nil comme indisponible, pas comme false.

Exemple

local power = addon.Platform:GetUnitPowerObservation("player", "mana", true)
if not power or not power.exists or not power.maximum then return nil end
if power.maximum <= 0 then return nil end
return power.current / power.maximum < 0.3

Dépendances

Source

Platform/unit_power.lua, ligne 31. En lecture seule dans le jeu ; Dupliquer crée une copie modifiable.

Platform.unit_power.GetUnitPowerObservation(self, unit, resource, includeMaximum)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not self:CanReadValue(unit) or not self:CanReadValue(resource) or not self:CanReadValue(includeMaximum) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if resource~='mana' and resource~='current' then return nil,'invalid-power-query' end
    if includeMaximum~=nil and type(includeMaximum)~='boolean' then return nil,'invalid-power-query' end
    if type(UnitExists)~='function' then return nil,'missing-api' end
    local existsOk,exists=pcall(UnitExists,unit)
    if not existsOk then return nil,'api-error' end
    if not self:CanReadValue(exists) then return nil,'restricted-value' end
    if exists==nil then return nil,'unit-data-unavailable' end
    if type(exists)~='boolean' then return nil,'invalid-api-result' end
    if not exists then return {exists=false} end
    if not self:CanReadValue(Enum) then return nil,'restricted-value' end
    if type(Enum)~='table' then return nil,'power-type-unavailable' end
    local types=Enum.PowerType
    if not self:CanReadValue(types) then return nil,'restricted-value' end
    if type(types)~='table' then return nil,'power-type-unavailable' end
    local powerType
    if resource=='mana' then
        powerType=types.Mana
    else
        if type(UnitPowerType)~='function' then return nil,'missing-api' end
        local ok
        ok,powerType=pcall(UnitPowerType,unit)
        if not ok then return nil,'api-error' end
    end
    if not self:CanReadValue(powerType) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(powerType) then return nil,'restricted-value' end
    if powerType==nil then return nil,'power-type-unavailable' end
    if not finite(powerType) or powerType<0 or powerType%1~=0 then return nil,'invalid-api-result' end
    local known=false
    for _,id in pairs(types) do
        if self:CanReadValue(id) and type(id)=='number' and id==powerType then known=true;break end
    end
    if not known then return nil,'power-type-unavailable' end
    if type(UnitPower)~='function' then return nil,'missing-api' end
    local currentOk,current=pcall(UnitPower,unit,powerType)
    if not currentOk then return nil,'api-error' end
    if not self:CanReadValue(current) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(current) then return nil,'restricted-value' end
    if current==nil then return nil,'power-data-unavailable' end
    if not finite(current) or resource=='mana' and current<0 then return nil,'invalid-api-result' end
    local record={exists=true,powerType=powerType,current=current}
    if includeMaximum then
        if type(UnitPowerMax)~='function' then return nil,'missing-api' end
        local maximumOk,maximum=pcall(UnitPowerMax,unit,powerType)
        if not maximumOk then return nil,'api-error' end
        if not self:CanReadValue(maximum) then return nil,'restricted-value' end
        if canaccessvalue and not canaccessvalue(maximum) then return nil,'restricted-value' end
        if maximum==nil then return nil,'power-data-unavailable' end
        if not finite(maximum) or maximum<0 then return nil,'invalid-api-result' end
        record.maximum=maximum
    end
    return record

Retour à Référence des fonctions