@@ -12,13 +12,73 @@ public class AssigningRolesEventArgs : BooleanEventArgs
1212 /// <summary>
1313 /// A dictionary of players and their decided roles.
1414 /// </summary>
15- public Dictionary < ExPlayer ? , RoleTypeId > Roles { get ; }
15+ public Dictionary < ExPlayer , RoleTypeId > Roles { get ; }
1616
1717 /// <summary>
1818 /// Creates a new <see cref="AssigningRolesEventArgs"/> instance.
1919 /// </summary>
20- /// <param name="roles"></param>
21- public AssigningRolesEventArgs ( Dictionary < ExPlayer ? , RoleTypeId > roles )
20+ /// <param name="roles">The assigned roles. </param>
21+ public AssigningRolesEventArgs ( Dictionary < ExPlayer , RoleTypeId > roles )
2222 => Roles = roles ;
23+
24+ /// <summary>
25+ /// Sets the role for the specified player if the player exists in the collection.
26+ /// </summary>
27+ /// <param name="player">The player whose role is to be set. Cannot be null.</param>
28+ /// <param name="role">The role to assign to the specified player.</param>
29+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="player"/> is null.</exception>
30+ public void Set ( ExPlayer player , RoleTypeId role )
31+ {
32+ if ( player is null )
33+ throw new ArgumentNullException ( nameof ( player ) ) ;
34+
35+ if ( ! Roles . ContainsKey ( player ) )
36+ return ;
37+
38+ Roles [ player ] = role ;
39+ }
40+
41+ /// <summary>
42+ /// Sets the role for all players by applying the specified selector function to each player.
43+ /// </summary>
44+ /// <param name="selector">A function that takes an ExPlayer and returns the RoleTypeId to assign to that player.</param>
45+ /// <exception cref="ArgumentNullException">Thrown if selector is null.</exception>
46+ public void SetAll ( Func < ExPlayer , RoleTypeId > selector )
47+ {
48+ if ( selector is null )
49+ throw new ArgumentNullException ( nameof ( selector ) ) ;
50+
51+ foreach ( var player in ExPlayer . Players )
52+ {
53+ if ( ! Roles . ContainsKey ( player ) )
54+ continue ;
55+
56+ Roles [ player ] = selector ( player ) ;
57+ }
58+ }
59+
60+ /// <summary>
61+ /// Sets the specified role for all players that match the given predicate.
62+ /// </summary>
63+ /// <param name="predicate">A predicate used to determine which players should have their role set. The method applies the role to each
64+ /// player for whom this predicate returns <see langword="true"/>.</param>
65+ /// <param name="role">The role to assign to each player that matches the predicate.</param>
66+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="predicate"/> is <see langword="null"/>.</exception>
67+ public void SetWhere ( Predicate < ExPlayer > predicate , RoleTypeId role )
68+ {
69+ if ( predicate is null )
70+ throw new ArgumentNullException ( nameof ( predicate ) ) ;
71+
72+ foreach ( var player in ExPlayer . Players )
73+ {
74+ if ( ! Roles . ContainsKey ( player ) )
75+ continue ;
76+
77+ if ( ! predicate ( player ) )
78+ continue ;
79+
80+ Roles [ player ] = role ;
81+ }
82+ }
2383 }
2484}
0 commit comments