呼叫方式
addon:GetClassGroupCount(cache, class, raid)
可直接透過 addon 使用,不需要相依項目。
作用
統計目前固定名單中符合的職業代碼。先讀取隊伍成員身分;在要求時,團隊成員身分會選擇 raid1 到 raid40,而不另外讀取玩家資訊。單人與隊伍路徑會先讀取 player,組隊時再讀取 party1 到 party4。完整且已知的名單會傳回計數(包括零);任何所需資訊無法使用時傳回 nil 及原因。完整的觀測共用評估輪次快取;玩家職業不會跨輪次保留。已封存的原始回呼會另外保留其原有的載入時職業。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
self | RMAddon | Rotation Master 插件實例(使用冒號呼叫時隱含傳入)。 |
cache | table | nil | 評估輪次快取;為 nil 時重新觀測。 |
class | string | 要統計的非空職業檔名代碼;不套用職業代碼白名單。 |
raid | boolean | nil | 為 true 時,在已知團隊成員身分為 true 時允許使用團隊名單;為 false 或 nil 時使用單人或隊伍名單。 |
傳回值
| 1 | number | nil | 符合職業的完整計數(包括零);無法使用時為 nil。 |
|---|---|---|
| 2 | string | nil | 計數為 nil 時的驗證、政策或所需資訊的可用性原因。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
它不會直接讀取任何遊戲 API。
機密值(正式版與永久)
在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。
插件如何呼叫它
- 隊伍中的職業 (evaluate)
local count,reason=addon:GetClassGroupCount(cache,value.class,value.raid)
原始碼
Core/class_group_conditions.lua,第 23 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Core.class_group_conditions.GetClassGroupCount(self, cache, class, raid)
local platform=self.Platform
if not platform:CanReadValue(class) or not platform:CanReadValue(raid) then return nil,'restricted-value' end
if type(class)~='string' or class=='' then return nil,'invalid-class-group-query' end
if raid~=nil and type(raid)~='boolean' then return nil,'invalid-class-group-query' end
local grouped,reason=self.Functions.cache.getCached(cache,platform.GetGroupMembership,platform,false)
if grouped==nil then return nil,reason end
local prefix,size='party',4
if grouped and raid then
local inRaid,why=self.Functions.cache.getCached(cache,platform.GetGroupMembership,platform,true)
if inRaid==nil then return nil,why end
if inRaid then prefix,size='raid',40 end
end
local count=0
if not grouped or prefix=='party' then
local player,why=self.Functions.cache.getCached(cache,platform.GetRosterClassObservation,platform,'player')
if player==nil then return nil,why end
if player==class then count=1 end
if not grouped then return count end
end
for index=1,size do
local observed,why=self.Functions.cache.getCached(cache,platform.GetRosterClassObservation,platform,prefix..tostring(index))
if observed==nil then return nil,why end
if observed==class then count=count+1 end
end
return count