参考 › 函数参考 › Conditions

Conditions.spatial_stats.statistic

依赖项

调用方式

Conditions.spatial_stats.statistic(cache, unit, mana, percentage, deficit)

记录依赖项 Conditions.spatial_stats.statistic,然后按该名称调用。带命名空间的调用不会传入 self:请使用冒号调用,或自行传入该对象。

作用

Reads one unit's health or mana for the PROXIMITY_* conditions as an absolute value, a percentage of the maximum, or the deficit below the maximum.

参数

名称类型作用
cachetable | nilEvaluation-pass cache passed to getCached, or nil to read directly.
unitstringUnit token to read.
manabooleanTrue for mana, false for health.
percentagebooleanTrue to return current as a percentage (0 to 100) of the maximum.
deficitbooleanTrue, when percentage is false, to return the maximum minus current.

返回值

1number | nilThe requested reading, or nil when unavailable.
2string | nilReason for nil from observation, or statistic-unavailable when the maximum is zero.

版本

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

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
UnitHealth经典旧世TBC 周年版经典进阶服永久服正式服
UnitHealthMax经典旧世TBC 周年版经典进阶服永久服正式服
UnitPower经典旧世TBC 周年版经典进阶服永久服正式服
UnitPowerMax经典旧世TBC 周年版经典进阶服永久服正式服

插件如何调用它

依赖项

源码

Conditions/spatial_stats.lua,第 81 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Conditions.spatial_stats.statistic(cache, unit, mana, percentage, deficit)
    local method=UnitHealth;if mana then method=UnitPower end
    local current,reason=observation(cache,method,unit,mana)
    if current==nil then return nil,reason end
    if percentage or deficit then
        local maximumMethod=UnitHealthMax;if mana then maximumMethod=UnitPowerMax end
        local maximum,why=observation(cache,maximumMethod,unit,mana)
        if maximum==nil then return nil,why end
        if percentage then
            if maximum==0 then return nil,"statistic-unavailable" end
            local percent=current/maximum*100
            if percent~=percent or percent==math.huge then return nil,"statistic-unavailable" end
            return percent
        end
        return maximum-current
    end
    return current

返回函数参考