Appel
addon.Platform:GetUnitCastObservation(unit, kind)
Disponible directement via addon ; aucune dépendance n'est nécessaire.
Ce qu'elle fait
Observe une incantation ou une canalisation d'unité sur les clients en politique de sondage ou restreinte. Une unité connue comme absente ou un résultat inactif lisible renvoie active=false. Les enregistrements actifs contiennent name, ou nameReason lorsque le nom est secret (l'unité incante tout de même), ainsi que les champs remainingSeconds, durationSeconds, interruptible et spellID, disponibles indépendamment, avec remainingReason, durationReason, interruptibleReason ou spellReason lorsqu'un champ facultatif est indisponible. Les observations de présence manquantes, en échec ou restreintes renvoient nil avec un motif.
Arguments
| Nom | Type | Ce qu'elle fait |
|---|---|---|
self | RMPlatform | Adaptateur de plateforme Rotation Master (implicite avec un appel par deux-points). |
unit | string | Identifiant de l'unité dont l'incantation ou la canalisation en cours doit être observée. |
kind | string | Type d'observation : cast ou channel. Ils utilisent des positions différentes dans le tuple natif d'interruptibilité. |
Retours
| 1 | table | nil | Enregistrement frais et lisible avec active, puis name ou nameReason, remainingSeconds, durationSeconds, interruptible et spellID. Le temps restant et la durée sont en secondes ; le temps restant est ramené à zéro au minimum. Un champ facultatif indisponible a son propre motif ; il n'invalide pas un enregistrement actif. |
|---|---|---|
| 2 | string | nil | Motif de disponibilité ou de validation de la requête lorsque l'observation entière est indisponible. |
É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 jeu | |||||
|---|---|---|---|---|---|
UnitCastingInfo | |||||
UnitChannelInfo | |||||
UnitExists |
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 cast = addon.Platform:GetUnitCastObservation("target", "cast")
if not cast then return nil end
if not cast.active then return false end
if cast.interruptible == nil or cast.remainingSeconds == nil then return nil end
return cast.interruptible and cast.remainingSeconds > 0.5Dépendances
durationSeconds→Platform.casting.durationSecondsinterruptibility→Platform.casting.interruptibilityremainingSeconds→Platform.casting.remainingSecondsspellIdentity→Platform.casting.spellIdentity
Source
Platform/casting.lua, ligne 82. En lecture seule dans le jeu ; Dupliquer crée une copie modifiable.
Platform.casting.GetUnitCastObservation(self, unit, kind)
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(kind) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if kind~='cast' and kind~='channel' then return nil,'invalid-cast-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 {active=false} end
local fn
if kind=='cast' then fn=UnitCastingInfo else fn=UnitChannelInfo end
if type(fn)~='function' then return nil,'missing-api' end
-- Capture into an owned tuple table without comparing native values. The
-- channel flag is slot7; casting includes castID and uses slot8 instead,
-- so the spell ID is slot9 for a cast and slot8 for a channel.
local ok,tuple=pcall(function() return {fn(unit)} end)
if not ok then return nil,'api-error' end
local name=tuple[1]
local record
if not self:CanReadValue(name) then
-- Retail and Forever make cast fields secret for a unit other than the
-- player or pet unless the spell is flagged never secret
-- (SecretWhenUnitSpellCastRestricted). A secret is a value, never nil:
-- the unit is casting, and only the name is hidden.
record={active=true,nameReason='restricted-value'}
else
if name==nil then return {active=false} end
if type(name)~='string' or name=='' then return nil,'invalid-api-result' end
record={active=true,name=name}
end
record.remainingSeconds,record.remainingReason=remainingSeconds(tuple[5])
record.durationSeconds,record.durationReason=durationSeconds(tuple[4],tuple[5])
record.interruptible,record.interruptibleReason=interruptibility(tuple[kind=='cast' and 8 or 7])
record.spellID,record.spellReason=spellIdentity(tuple[kind=='cast' and 9 or 8])
return record




