@@ -67,13 +67,15 @@ public override void OnUnregistered()
6767 WaveTimer ? . Dispose ( ) ;
6868 }
6969
70- internal override void Internal_RemoveInstance ( int id )
70+ /// <summary>
71+ /// Despawns all active instances.
72+ /// </summary>
73+ /// <param name="playerRole">The role to set alive players to.</param>
74+ public override void DespawnAll ( RoleTypeId playerRole = RoleTypeId . Spectator )
7175 {
72- if ( Instances . TryGetValue ( id , out var instance ) )
76+ while ( Instances . Count > 0 )
7377 {
74- Instances . Remove ( id ) ;
75-
76- OnDespawned ( instance ) ;
78+ Despawn ( Instances . First ( ) . Value , playerRole ) ;
7779 }
7880 }
7981
@@ -102,6 +104,20 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
102104 player . Role . Set ( playerRole ) ;
103105 }
104106
107+ for ( var i = 0 ; i < instance . OriginalPlayers . Count ; i ++ )
108+ {
109+ var player = instance . OriginalPlayers [ i ] ;
110+
111+ if ( player ? . ReferenceHub != null )
112+ {
113+ if ( ! string . IsNullOrWhiteSpace ( Name ) )
114+ {
115+ player . CustomInfo = string . Empty ;
116+ player . InfoArea &= ~ PlayerInfoArea . CustomInfo ;
117+ }
118+ }
119+ }
120+
105121 instance . AlivePlayers . Clear ( ) ;
106122 instance . OriginalPlayers . Clear ( ) ;
107123
@@ -117,11 +133,12 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
117133 /// </summary>
118134 /// <param name="maxPlayerCount">The maximum amount of players to spawn.</param>
119135 /// <param name="throwIfNotEnoughPlayers">Whether or not to throw an exception if there aren't enough players to match <paramref name="maxPlayerCount"/></param>
120- /// <param name="additionalChecks">Delegate used to check potential players, called after <see cref="IsSpawnable"/>.</param>
136+ /// <param name="assignInventory">Whether or not to assign inventory to players with game roles, has no effect on players with custom roles.</param>
137+ /// <param name="additionalChecks">Delegate used to check potential players, called after <see cref="CustomTeamHandlerBase.IsSpawnable"/>.</param>
121138 /// <returns>The spawned team instance (if spawned, null if there weren't enough players).</returns>
122139 /// <exception cref="ArgumentOutOfRangeException"></exception>
123140 /// <exception cref="Exception"></exception>
124- public TInstance ? Spawn ( int maxPlayerCount , bool throwIfNotEnoughPlayers = false , Predicate < ExPlayer > ? additionalChecks = null )
141+ public TInstance ? Spawn ( int maxPlayerCount , bool throwIfNotEnoughPlayers = false , bool assignInventory = true , Predicate < ExPlayer > ? additionalChecks = null )
125142 {
126143 if ( maxPlayerCount < 1 )
127144 throw new ArgumentOutOfRangeException ( nameof ( maxPlayerCount ) ) ;
@@ -153,7 +170,7 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
153170 return null ;
154171 }
155172
156- var instance = Spawn ( spawnablePlayers ) ;
173+ var instance = Spawn ( spawnablePlayers , assignInventory ) ;
157174
158175 ListPool < ExPlayer > . Shared . Return ( spawnablePlayers ) ;
159176 return instance ;
@@ -163,8 +180,9 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
163180 /// Spawns a new team instance.
164181 /// </summary>
165182 /// <param name="players">The list of players to spawn.</param>
183+ /// <param name="assignInventory">Whether or not to assign inventory to players with game roles, has no effect on players with custom roles.</param>
166184 /// <returns>The spawned team instance (if spawned, null if there weren't enough players).</returns>
167- public TInstance ? Spawn ( IList < ExPlayer > players )
185+ public TInstance ? Spawn ( IList < ExPlayer > players , bool assignInventory = true )
168186 {
169187 if ( players is null )
170188 throw new ArgumentNullException ( nameof ( players ) ) ;
@@ -199,8 +217,12 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
199217 if ( pair . Value is RoleTypeId roleType )
200218 {
201219 pair . Key . Role . Set ( roleType , RoleChangeReason . Respawn , spawnPosition . HasValue
202- ? RoleSpawnFlags . AssignInventory
203- : RoleSpawnFlags . All ) ;
220+ ? ( assignInventory
221+ ? RoleSpawnFlags . AssignInventory
222+ : RoleSpawnFlags . None )
223+ : ( assignInventory
224+ ? RoleSpawnFlags . AssignInventory
225+ : RoleSpawnFlags . UseSpawnpoint ) ) ;
204226 }
205227 else if ( pair . Value is CustomRoleData customRoleData )
206228 {
@@ -212,7 +234,7 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
212234
213235 if ( ! string . IsNullOrWhiteSpace ( Name ) )
214236 {
215- pair . Key . CustomInfo = Name ;
237+ pair . Key . CustomInfo = Name ! ;
216238
217239 if ( ( pair . Key . InfoArea & PlayerInfoArea . CustomInfo ) != PlayerInfoArea . CustomInfo )
218240 pair . Key . InfoArea |= PlayerInfoArea . CustomInfo ;
@@ -233,4 +255,35 @@ public void Despawn(TInstance instance, RoleTypeId playerRole = RoleTypeId.Spect
233255 teamInstance . OnSpawned ( ) ;
234256 return teamInstance ;
235257 }
258+
259+ internal override void Internal_RemoveInstance ( int id )
260+ {
261+ if ( Instances . TryGetValue ( id , out var instance ) )
262+ {
263+ Instances . Remove ( id ) ;
264+
265+ OnDespawned ( instance ) ;
266+ }
267+ }
268+
269+ internal override bool Internal_DespawnInstance ( int id )
270+ {
271+ if ( Instances . TryGetValue ( id , out var instance ) )
272+ {
273+ Despawn ( instance ) ;
274+ return true ;
275+ }
276+
277+ return false ;
278+ }
279+
280+ internal override IEnumerable < CustomTeamInstance > Internal_GetInstances ( )
281+ {
282+ return Instances . Values ;
283+ }
284+
285+ internal override CustomTeamInstance Internal_SpawnInstance ( int playerCount )
286+ {
287+ return Spawn ( playerCount ) ! ;
288+ }
236289}
0 commit comments