调用方式
addon.Platform:GetMobInfo2Observation(unit, kind, school, cache)
可直接通过 addon 使用,无需依赖项。
作用
在探测或受限策略客户端上读取可选的 MobInfo2 历史观测。只缓存确切的所选单位存在性;UnitName 的第一个结果、UnitLevel 的第一个结果以及三参数的 MI2_GetMobData(name,level,unit) 点号调用每次都会重新获取。已知不存在的单位,以及成功返回的未记录的 nil 或省略的历史,与不可用的原生/提供者信息保持区分。保留可读的 runner 标量真值、法术类型符号以及缺少 Hits 时默认为一。正的抗性比例必须有限;完全免疫会使用有限的 Hits,而部分免疫只需要其负值的法术类型观测。绝不推断原生抗性或借用旧记录。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 所选的非空单位标识,在原生/提供者调用中保持不变。 |
kind | string | 封闭的种类:runner、resist 或 immune。 |
school | string | nil | 用于 resist/immune 的非空历史法术类型键;runner 不使用。 |
cache | table | nil | 仅为评估轮次的存在性缓存;名称、等级和提供者历史保持实时。 |
返回值
| 1 | table | nil | 记录为 exists=false;已知没有历史时为 recorded=false;或者为 runner、ratio 或 immune,并带有 hits/hitsReason。nil 表示所需观测不可用。 |
|---|---|---|
| 2 | string | nil | 策略、能力或所需观测的可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
UnitLevel | |||||
UnitName | |||||
canaccessvalue |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
插件如何调用它
- 免疫 (evaluate)
local observation,reason=addon.Platform:GetMobInfo2Observation(value.unit,"immune",value.school,cache) - 有抗性 (evaluate)
local observation,reason=addon.Platform:GetMobInfo2Observation(value.unit,"resist",value.school,cache) - 逃跑者 (evaluate)
local observation,reason=addon.Platform:GetMobInfo2Observation(value.unit,"runner",nil,cache)
依赖项
finite→Platform.mobinfo2.finitehitCount→Platform.mobinfo2.hitCountpresence→Platform.mobinfo2.presencereadField→Platform.mobinfo2.readField
源码
Platform/mobinfo2.lua,第 79 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.mobinfo2.GetMobInfo2Observation(self, unit, kind, school, cache)
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) or not self:CanReadValue(cache) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if kind~='runner' and kind~='resist' and kind~='immune' then return nil,'invalid-mobinfo2-kind' end
if cache~=nil and type(cache)~='table' then return nil,'invalid-mobinfo2-cache' end
if kind~='runner' then
if not self:CanReadValue(school) then return nil,'restricted-value' end
if type(school)~='string' or school=='' then return nil,'invalid-mobinfo2-school' end
end
local exists,reason=addon.Functions.cache.getCached(cache,presence,self,unit)
if exists==nil then return nil,reason end
if not exists then return {exists=false} end
local query,queryReason=readField(self,_G,'MI2_GetMobData')
if queryReason then return nil,queryReason end
if type(query)~='function' then return nil,'missing-api' end
if type(UnitName)~='function' then return nil,'missing-api' end
local nameOk,name=pcall(UnitName,unit)
if not nameOk then return nil,'api-error' end
if not self:CanReadValue(name) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(name) then return nil,'restricted-value' end
if name==nil then return nil,'unit-name-unavailable' end
if type(name)~='string' or name=='' then return nil,'invalid-api-result' end
if type(UnitLevel)~='function' then return nil,'missing-api' end
local levelOk,level=pcall(UnitLevel,unit)
if not levelOk then return nil,'api-error' end
if not self:CanReadValue(level) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(level) then return nil,'restricted-value' end
local valid,why=finite(self,level)
if not valid then return nil,why end
local ok,data=pcall(query,name,level,unit)
if not ok then return nil,'mobinfo2-provider-error' end
if not self:CanReadValue(data) then return nil,'restricted-value' end
-- A successful nil lookup means unrecorded data in the publisher API.
if data==nil then return {exists=true,recorded=false} end
if type(data)~='table' then return nil,'invalid-mobinfo2-data' end
if kind=='runner' then
local action,actionReason=readField(self,data,'lowHpAction')
if actionReason then return nil,actionReason end
local actionType=type(action)
if actionType=='number' then
valid,why=finite(self,action)
if not valid then return nil,why end
elseif actionType~='nil' and actionType~='boolean' and actionType~='string' then
return nil,'invalid-mobinfo2-action'
end
-- Preserve readable scalar truthiness, including numeric zero and ''.
return {exists=true,recorded=true,runner=action and true or false}
end
local resists,resistsReason=readField(self,data,'resists')
if resistsReason then return nil,resistsReason end
if resists==nil then return {exists=true,recorded=false} end
local count,countReason=readField(self,resists,school)
if countReason then return nil,countReason end
if count==nil then return {exists=true,recorded=false} end
valid,why=finite(self,count)
if not valid then return nil,why end
if kind=='resist' then
if count<=0 then return {exists=true,recorded=false} end
local hits,hitsReason=hitCount(self,resists,school)
if hits==nil then return nil,hitsReason end
local ratio=count/hits
valid,why=finite(self,ratio)
if not valid then return nil,why end
return {exists=true,recorded=true,ratio=ratio}
end
if count>=0 then return {exists=true,recorded=false} end
local hits,hitsReason=hitCount(self,resists,school)
-- Partial immunity needs only the negative observation. Full immunity
-- separately requires this optional count, including meaningful zero.
return {exists=true,recorded=true,immune=true,hits=hits,hitsReason=hitsReason}




