调用方式
addon.Platform:GetAnnouncementRecipientGroupMembership(recipient, raidOnly)
可直接通过 addon 使用,无需依赖项。
作用
将确切的施法对象名称与当前有限的小队或团队名单进行匹配,然后通过单位标识观测其成员身份。名单数据缺失、含义不明确或正在变化时保持为不可用;绝不读取所选目标,也不在施法之间保留状态。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
recipient | string | 为这次施法记录的确切可读对象名称。 |
raidOnly | boolean | nil | 为 true 时只检查团队成员身份;为 false 或 nil 时检查小队或团队。 |
返回值
| 1 | boolean | nil | 观测到的成员身份;不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 结果为 nil 时的验证或可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local name = UnitName("target")
if type(name) ~= "string" then return nil end
local member = addon.Platform:GetAnnouncementRecipientGroupMembership(name, false)
if member == nil then return nil end
return member源码
Platform/announcement_recipient.lua,第 24 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.announcement_recipient.GetAnnouncementRecipientGroupMembership(self, recipient, raidOnly)
if not self:CanReadValue(recipient) or not self:CanReadValue(raidOnly) then return nil,'restricted-value' end
if type(recipient)~='string' or recipient=='' or #recipient>256 then return nil,'cast-recipient-unavailable' end
if raidOnly~=nil and type(raidOnly)~='boolean' then return nil,'invalid-group-query' end
local grouped,reason=self:GetGroupMembership(raidOnly)
if grouped~=true then return grouped,reason end
local raid,why=self:GetGroupMembership(true)
if raid==nil then return nil,why end
local exists,name,guid,normalized=UnitExists,UnitName,UnitGUID,GetNormalizedRealmName
local groupQuery=self.GetGroupMembership
local membership=self.GetUnitGroupMembership
if type(exists)~='function' or type(name)~='function' or type(guid)~='function' or type(membership)~='function' then return nil,'missing-api' end
local function read(unit)
local ok,present=pcall(exists,unit)
if not ok or not self:CanReadValue(present) or type(present)~='boolean' then return nil end
if not present then return false end
local named,first,realm=pcall(name,unit)
local identified,identity=pcall(guid,unit)
if not named or not identified or not self:CanReadValue(first) or not self:CanReadValue(realm) or not self:CanReadValue(identity) then return nil end
if canaccessvalue and not canaccessvalue(first) then return nil end
if canaccessvalue and not canaccessvalue(realm) then return nil end
if canaccessvalue and not canaccessvalue(identity) then return nil end
if type(first)~='string' or first=='' or #first>256 or type(identity)~='string' or identity=='' or #identity>256 then return nil end
if realm~=nil and type(realm)~='string' then return nil end
if realm==nil or realm=='' then
if type(normalized)=='function' then
local got,value=pcall(normalized)
if not got or not self:CanReadValue(value) then return nil end
if canaccessvalue and not canaccessvalue(value) then return nil end
if type(value)=='string' and value~='' and #value<=256 then realm=value end
end
end
return {first=first,full=type(realm)=='string' and realm~='' and first..'-'..realm or nil,guid=identity}
end
local function scan()
local rows,selected,count={},nil,0
for index=raid and 1 or 0,raid and 40 or 4 do
local unit=raid and 'raid'..index or index==0 and 'player' or 'party'..index
local record=read(unit)
if record==nil then return nil,'group-data-unavailable' end
rows[unit]=record
if record then
count=count+1
if recipient==record.first or recipient==record.full then
if selected then return nil,'cast-recipient-ambiguous' end
selected=unit
elseif not record.full and recipient:sub(1,#record.first+1)==record.first..'-' then
return nil,'cast-recipient-unavailable'
end
end
end
if count==0 then return nil,'group-data-unavailable' end
return rows,selected
end
local before,selected=scan()
if not before then return nil,selected end
local member,failure=false,nil
if selected then member,failure=membership(self,selected,raidOnly) end
-- Native calls and extension callbacks may reenter. Re-read the complete
-- bounded roster after membership/context reads, including negative results:
-- a stale false must not turn a NOT condition into permission to announce.
local currentGroup=self:GetGroupMembership(raidOnly)
local currentRaid=self:GetGroupMembership(true)
local after,matched=scan()
if exists~=UnitExists or name~=UnitName or guid~=UnitGUID or normalized~=GetNormalizedRealmName
or membership~=self.GetUnitGroupMembership or groupQuery~=self.GetGroupMembership
or currentGroup~=grouped or currentRaid~=raid or not after or matched~=selected then return nil,'group-data-unavailable' end
for unit,record in pairs(before) do
local fresh=after[unit]
if type(record)~=type(fresh) then return nil,'group-data-unavailable' end
if record and (fresh.guid~=record.guid or fresh.first~=record.first or fresh.full~=record.full) then return nil,'group-data-unavailable' end
end
return member,failure




