呼叫方式
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}




