Build the effective roles in a single pass

The list restarts whenever a higher priority is found, rather than collecting
every role and filtering afterwards.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-22 16:45:51 +00:00
co-authored by Claude Fable 5
parent e79822b26e
commit 59a0e0be13
+6 -9
View File
@@ -168,23 +168,20 @@ local function get_effective_roles(player_name)
role_ids[#role_ids + 1] = script_data.default_role_id
end
local roles, highest_priority = {}, nil
-- Only the roles with the highest priority apply, so the list restarts
-- whenever a higher priority is found
local rtn, highest_priority = {}, nil
for _, role_id in pairs(role_ids) do
local role = script_data.roles[role_id]
if role then
roles[#roles + 1] = role
if highest_priority == nil or role.priority > highest_priority then
highest_priority = role.priority
rtn = { role }
elseif role.priority == highest_priority then
rtn[#rtn + 1] = role
end
end
end
local rtn = {}
for _, role in pairs(roles) do
if role.priority == highest_priority then
rtn[#rtn + 1] = role
end
end
return rtn
end