调用方式
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.
参数
| 名称 | 类型 | 作用 |
|---|---|---|
cache | table | nil | Evaluation-pass cache passed to getCached, or nil to read directly. |
unit | string | Unit token to read. |
mana | boolean | True for mana, false for health. |
percentage | boolean | True to return current as a percentage (0 to 100) of the maximum. |
deficit | boolean | True, when percentage is false, to return the maximum minus current. |
返回值
| 1 | number | nil | The requested reading, or nil when unavailable. |
|---|---|---|
| 2 | string | nil | Reason for nil from observation, or statistic-unavailable when the maximum is zero. |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
插件如何调用它
- 范围内的生命值 (evaluate)
local cur,why=statistic(c,unit,false,false,value.value<0) - 范围内的生命值百分比 (evaluate)
local cur,why=statistic(c,unit,false,true,false) - 范围内的生命值百分比计数 (evaluate)
local cur,why=statistic(c,unit,false,true,false) - 范围内的生命值计数 (evaluate)
local cur,why=statistic(c,unit,false,false,value.health<0) - 范围内的法力值 (evaluate)
local cur,why=statistic(c,unit,true,false,value.value<0) - 范围内的法力值百分比 (evaluate)
local cur,why=statistic(c,unit,true,true,false) - 范围内的法力值百分比计数 (evaluate)
local cur,why=statistic(c,unit,true,true,false) - 范围内的法力值计数 (evaluate)
local cur,why=statistic(c,unit,true,false,value.mana<0)
依赖项
observation→Conditions.spatial_stats.observation
源码
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




