-
Notifications
You must be signed in to change notification settings - Fork 95
fix: bug with not tracking limit of spawned players in custom roles #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bug with not tracking limit of spawned players in custom roles #585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a bug in the custom role spawn system by enforcing the configured player limit.
- Added a check to skip role assignment once the spawn limit is reached.
- Treated a limit of 0 as “unlimited” to maintain prior behavior.
Comments suppressed due to low confidence (2)
EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs:927
- There’s no test verifying that
SpawnProperties.Limit
is enforced correctly. Consider adding unit or integration tests to cover scenarios where the limit is reached and when it’s treated as unlimited (limit == 0).
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit))
EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs:927
- [nitpick] Using
Limit == 0
to represent "unlimited" can be non-intuitive. You might consider usingnull
or-1
, or ensure the API docs clearly state that zero disables the limit check.
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit))
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit)) | ||
AddRole(ev.Player); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This condition is becoming quite long and could be extracted into a well-named helper method (e.g. CanSpawnMorePlayers(ev.Player)
) to improve readability and reduce complexity.
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit)) | |
AddRole(ev.Player); | |
} | |
if (CanSpawnMorePlayers(ev.Player)) | |
AddRole(ev.Player); | |
} | |
private bool CanSpawnMorePlayers(Player player) | |
{ | |
return !IgnoreSpawnSystem && | |
SpawnChance > 0 && | |
!Check(player) && | |
player.Role.Type == Role && | |
Loader.Random.NextDouble() * 100 <= SpawnChance && | |
(SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit); | |
} |
Copilot uses AI. Check for mistakes.
Description
Describe the changes
Fixes bug with custom roles spawn system
What is the current behavior? (You can also link to an open issue here)
ignores limit for spawn
What is the new behavior? (if this is a feature change)
do not give custom role if limit was reached
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
no
Other information:
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other