调用方式
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