呼叫方式
addon:GetConditionThreatCount(minimum, cache)
可直接透過 addon 使用,不需要相依項目。
作用
只統計已在觀測成員快照中、以 GUID 為鍵的單位。在使用已發布的威脅值觀測器之前,會先驗證目前代碼的身分;已知不存在或被重複使用的代碼會被排除,且不會新增替代者。完整的身分與威脅值觀測只共用所提供的評估快取,而成員身分會重新走訪。已知的非敵人或選擇性的 nil 威脅值不計入;所需資訊無法讀取、格式錯誤或失敗時,整個結果為無法使用。這不會列舉完整的名單、套用距離篩選或修改被追蹤的記錄。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
self | RMAddon | Rotation Master 插件實例(使用冒號呼叫時隱含傳入)。 |
minimum | number | 有限的最低原生威脅值狀態,保留帶正負號與小數的門檻。 |
cache | table | nil | 由呼叫端擁有的評估觀測快取;為 nil 時重新查詢。 |
傳回值
| 1 | number | nil | 完整的非負觀測計數(包括零);無法使用時為 nil。 |
|---|---|---|
| 2 | string | nil | 政策、快照、身分或威脅值觀測的可用性原因。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
它不會直接讀取任何遊戲 API。
機密值(正式版與永久)
在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。
插件如何呼叫它
- 威脅值計數 (evaluate)
local count,reason=addon:GetConditionThreatCount(value.threat-1,cache)
相依項目
finite→Core.threat_count_conditions.finitereadField→Core.threat_count_conditions.readField
原始碼
Core/threat_count_conditions.lua,第 50 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Core.threat_count_conditions.GetConditionThreatCount(self, minimum, cache)
local platform=self.Platform
local policy=platform:GetCombatDataPolicy()
if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
local valid,issue=finite(platform,minimum)
if not valid then return nil,issue end
if not platform:CanReadValue(cache) then return nil,'restricted-value' end
if cache~=nil and type(cache)~='table' then return nil,'invalid-threat-count-cache' end
if policy=='restricted' then return self:GetConditionNameplateThreatCount(minimum,cache) end
local snapshot,why=readField(platform,self,'unitsInRange')
if why then return nil,why end
if type(snapshot)~='table' then return nil,'unit-snapshot-unavailable' end
local count=0
for guid,entity in pairs(snapshot) do
if not platform:CanReadValue(guid) or not platform:CanReadValue(entity) then return nil,'restricted-value' end
if type(guid)~='string' or guid=='' or type(entity)~='table' then return nil,'invalid-unit-snapshot' end
local unit,reason=readField(platform,entity,'unit')
if reason then return nil,reason end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit-snapshot' end
-- The existing forecast identity observer is exactly existence + GUID;
-- it consumes no health, history, provider or clock facts.
local observeIdentity=platform.GetHealthForecastIdentityObservation
if type(observeIdentity)~='function' then return nil,'missing-api' end
local current,identityReason=addon.Functions.cache.getCached(cache,observeIdentity,platform,unit)
if not platform:CanReadValue(current) then return nil,'restricted-value' end
if current==nil then return nil,identityReason or 'unit-guid-unavailable' end
if current~=false then
if type(current)~='string' or current=='' then return nil,'invalid-unit-identity' end
-- A recycled token is excluded; its replacement is not new membership.
if current==guid then
local observeThreat=platform.GetUnitThreatObservation
if type(observeThreat)~='function' then return nil,'missing-api' end
local status,threatReason=addon.Functions.cache.getCached(cache,observeThreat,platform,unit)
if not platform:CanReadValue(status) then return nil,'restricted-value' end
if status==nil then return nil,threatReason or 'threat-data-unavailable' end
if status~=false then
local readable,problem=finite(platform,status)
if not readable then return nil,problem end
if status>=minimum then count=count+1 end
end
end
end
end
return count