参考 › 函数参考 › Core

Core.threat_count_conditions.GetConditionThreatCount

公共

调用方式

addon:GetConditionThreatCount(minimum, cache)

可直接通过 addon 使用,无需依赖项。

作用

只统计已在观测成员快照中、以 GUID 为键的单位。在使用已发布的仇恨观测器之前,会先验证当前标识的身份;已知不存在或被重复使用的标识会被排除,且不会添加替代者。完整的身份和仇恨观测只共享所提供的评估缓存,而成员身份会重新遍历。已知的非敌人或可选的 nil 仇恨不计入;所需信息无法读取、格式错误或失败时,整个结果为不可用。这不会枚举完整的名单、应用距离筛选或修改被追踪的记录。

参数

名称类型作用
selfRMAddonRotation Master 插件实例(使用冒号调用时隐含传入)。
minimumnumber有限的最低原生仇恨状态,保留带符号和小数的阈值。
cachetable | nil由调用方拥有的评估观测缓存;为 nil 时重新查询。

返回值

1number | nil完整的非负观测计数(包括零);不可用时为 nil。
2string | nil策略、快照、身份或仇恨观测的可用性原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

它不直接读取任何游戏 API。

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

插件如何调用它

  • 仇恨计数 (evaluate)
    local count,reason=addon:GetConditionThreatCount(value.threat-1,cache)

依赖项

源码

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

返回函数参考