From 7b2a35259dd7bfef168405d1de80ff7f5f082902 Mon Sep 17 00:00:00 2001 From: oof2win2 Date: Sun, 13 Nov 2022 09:27:33 +0100 Subject: [PATCH] feat(roles): deferred role assignment message --- expcore/roles.lua | 17 ++++++++++++++--- locale/en/expcore.cfg | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/expcore/roles.lua b/expcore/roles.lua index 28ba0b80..0dcaa2ac 100644 --- a/expcore/roles.lua +++ b/expcore/roles.lua @@ -148,7 +148,7 @@ end) --- Internal function used to trigger a few different things when roles are changed -- this is the raw internal trigger as the other function is called at other times -- there is a second half called role_update which triggers after the event call, it also is called when a player joins -local function emit_player_roles_updated(player, type, roles, by_player_name, skip_game_print) +local function emit_player_roles_updated(player, type, roles, by_player_name, skip_game_print, deferred) by_player_name = game.player and game.player.name or by_player_name or '' local by_player = game.players[by_player_name] local by_player_index = by_player and by_player.index or 0 @@ -168,7 +168,11 @@ local function emit_player_roles_updated(player, type, roles, by_player_name, sk end -- output to all the different locations: game print, player sound, event trigger and role log if not skip_game_print then - game.print({'expcore-roles.game-message-'..type, player.name, table.concat(role_names, ', '), by_player_name}, Colours.cyan) + if deferred then + game.print({'expcore-roles.game-message-deferred-'..type, player.name, table.concat(role_names, ', '), by_player_name}, Colours.cyan) + else + game.print({'expcore-roles.game-message-'..type, player.name, table.concat(role_names, ', '), by_player_name}, Colours.cyan) + end end if type == 'assign' then player.play_sound{path='utility/achievement_unlocked'} @@ -378,10 +382,17 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent) -- if the player has a role that needs to defer the role changes, save the roles that need to be assigned later into a table if valid_player and Roles.player_has_flag(player, "defer_role_changes") then local assign_later = Roles.config.deferred_roles[valid_player.name] or {} + local were_changes = false for _, role in ipairs(roles) do - assign_later[role] = 1 + if not assign_later[role] then + assign_later[role] = 1 + were_changes = true + end end Roles.config.deferred_roles[valid_player.name] = assign_later + if were_changes then + emit_player_roles_updated(valid_player, 'assign', roles, by_player_name, silent, true) + end return end diff --git a/locale/en/expcore.cfg b/locale/en/expcore.cfg index bdc4907d..3bfb6828 100644 --- a/locale/en/expcore.cfg +++ b/locale/en/expcore.cfg @@ -29,6 +29,7 @@ error-log-format-flag=[ERROR] roleFlag/__1__ :: __2__ error-log-format-assign=[ERROR] rolePromote/__1__ :: __2__ game-message-assign=__1__ has been assigned to __2__ by __3__ game-message-unassign=__1__ has been unassigned from __2__ by __3__ +game-message-deferred-assign=__1__ will been assigned to __2__ by __3__ reject-role=Invalid Role Name. reject-player-role=Player has a higher role.