Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ namespace Exiled.CustomRoles.API.Features
/// </summary>
public abstract class CustomRole
{
/// <summary>
/// Gets or sets the number of players that naturally spawned with this custom role.
/// </summary>
[YamlIgnore]
#pragma warning disable SA1401 // Fields should be private
public int SpawnedPlayers = 0;
#pragma warning restore SA1401 // Fields should be private

private const float AddRoleDelay = 0.25f;

private static Dictionary<Type, CustomRole?> typeLookupTable = new();
Expand Down Expand Up @@ -184,6 +176,12 @@ public abstract class CustomRole
/// </summary>
public virtual string AbilityUsage { get; set; } = "Enter \".special\" in the console to use your ability. If you have multiple abilities, you can use this command to cycle through them, or specify the one to use with \".special ROLENAME AbilityNum\"";

/// <summary>
/// Gets or sets the number of players that naturally spawned with this custom role.
/// </summary>
[YamlIgnore]
public int SpawnedPlayers { get; set; }

/// <summary>
/// Gets a <see cref="CustomRole"/> by ID.
/// </summary>
Expand Down
11 changes: 6 additions & 5 deletions EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace Exiled.CustomRoles.Events
/// </summary>
public class PlayerHandlers
{
private readonly CustomRoles plugin;
private readonly HashSet<SpawnReason> validSpawnReasons = new()
private static readonly HashSet<SpawnReason> ValidSpawnReasons = new()
{
SpawnReason.RoundStart,
SpawnReason.Respawn,
Expand All @@ -33,6 +32,8 @@ public class PlayerHandlers
SpawnReason.ItemUsage,
};

private readonly CustomRoles plugin;

/// <summary>
/// Initializes a new instance of the <see cref="PlayerHandlers"/> class.
/// </summary>
Expand Down Expand Up @@ -64,7 +65,7 @@ internal void OnSpawningRagdoll(SpawningRagdollEventArgs ev)
/// <inheritdoc cref="Exiled.Events.Handlers.Player.Spawning"/>
internal void OnSpawned(SpawnedEventArgs ev)
{
if (!validSpawnReasons.Contains(ev.Reason) || ev.Player.HasAnyCustomRole())
if (!ValidSpawnReasons.Contains(ev.Reason) || ev.Player.HasAnyCustomRole())
{
return;
}
Expand Down Expand Up @@ -108,15 +109,15 @@ internal void OnSpawned(SpawnedEventArgs ev)
break;
}

int newSpawnCount = Interlocked.Increment(ref candidateRole.SpawnedPlayers);
int newSpawnCount = candidateRole.SpawnedPlayers++;
if (newSpawnCount <= candidateRole.SpawnProperties.Limit)
{
candidateRole.AddRole(ev.Player);
break;
}
else
{
Interlocked.Decrement(ref candidateRole.SpawnedPlayers);
candidateRole.SpawnedPlayers--;
randomRoll -= candidateRole.SpawnChance;
}
}
Expand Down