Referenz › Funktionsreferenz › Platform

Platform.unit_power.GetUnitPowerObservation

öffentlich

Aufruf als

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

Direkt über addon verfügbar; keine Abhängigkeit nötig.

Was sie bewirkt

Explizit Mana oder die aktuelle rohe Ressource auf unterstützten lesbaren Clients beobachten. Ressourcenidentitäten werden aus dem Live-Enum PowerType gewählt; explizites Mana fällt nie auf die aktuelle Leiste zurück. Bekannte Abwesenheit ergibt exists=false; fehlende, fehlgeschlagene, eingeschränkte oder fehlerhafte Beobachtungen ergeben nil mit einem Grund. Mengen im Modus current behalten vorzeichenbehaftete native Ressourcen bei; explizites Mana ist nichtnegativ. Das Maximum nur bei Bedarf anfragen; prozentuale Verbraucher müssen ein positives Maximum verlangen.

Argumente

NameTypWas sie bewirkt
selfRMPlatformPlattformadapter von Rotation Master (bei Doppelpunktaufrufen implizit).
unitstringExakte Einheitenkennung, deren Ressource beobachtet werden soll; Spieler- oder Fahrzeugeinheiten werden nicht umgeleitet.
resourcestringmana wählt das explizite Live-Enum Mana; current liest die tatsächliche UnitPowerType-Identität und reicht sie weiter, einschließlich Mana mit dem Wert null.
includeMaximumboolean | nilTrue beobachtet auch das Maximum der ausgewählten Ressource; false oder nil liest nur die aktuelle Menge.

Rückgabewerte

1table | nilFrisch gelesener lesbarer Datensatz mit exists und, falls vorhanden, powerType und endlicher aktueller Menge. Ein angefragtes Maximum ist endlich und nichtnegativ. Mengen können gebrochen sein; im Modus current kann die aktuelle Menge ein Vorzeichen haben.
2string | nilGrund aus Richtlinie, Abfragevalidierung oder Verfügbarkeit für eine nil-Ressourcenbeobachtung.

Editionen

Integrierte Hilfsfunktionen werden auf jeder Edition registriert. Unterschiedlich ist die Spiel-API, die sie lesen; fehlt eine, weicht die Hilfsfunktion aus oder gibt nil mit einem Grund zurück.

  • Auf dieser Edition nicht verfügbar (den Grund nennt der Tooltip)
  • Nur, solange Blizzards Ersatz für veraltete Funktionen aktiv ist
Spiel-APIClassic 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

Geheime Werte (Retail und Forever)

Auf Retail und Forever übergibt das Spiel Addons geheime Werte. Diese Hilfsfunktion prüft, was sie liest (addon.Platform:CanReadValue), und gibt statt eines geheimen Werts, den sie nicht vergleichen kann, nil mit einem Grund wie restricted-value zurück. Behandeln Sie nil als nicht verfügbar, nicht als false.

Beispiel

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

Abhängigkeiten

Quelle

Platform/unit_power.lua, Zeile 31. Im Spiel schreibgeschützt; Duplizieren erstellt eine bearbeitbare Kopie.

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

Zurück zu Funktionsreferenz