Add modifier post assignment-check

This commit is contained in:
Atony committed 2026-07-25 18:03:29 -05:00
1 parent 8750e5c894
commit 7c085b1072
2 files changed
+13 -1

No files matched your search

+6 -1
View File
@@ -152,7 +152,7 @@ public static class ModifierManager
}
var candidates = availablePlayers
.Where(x => IsGameModifierValid(x, modifier, modifier.TypeId))
.Where(x => IsGameModifierPostCheck(x, modifier, modifier.TypeId))
.ToList();
if (candidates.Count == 0)
@@ -181,4 +181,9 @@ public static class ModifierManager
!player.HasModifier(modifierId) && modifier.IsModifierValidOn(player.Data.Role) &&
modifier.CanSpawnOnCurrentMode();
}
private static bool IsGameModifierPostCheck(PlayerControl player, GameModifier modifier, uint modifierId)
{
return (player.Data.Role is not ICustomRole role || role.IsModifierApplicable(modifier)) &&
!player.HasModifier(modifierId) && modifier.IsModifierValidOnPostCheck(player.Data.Role);
}
}
+7
View File
@@ -33,6 +33,13 @@ public abstract class GameModifier : BaseModifier
/// <returns><see langword="true"/> if the modifier is valid on the role, otherwise <see langword="false"/>.</returns>
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
/// <summary>
/// Determines whether the modifier is valid on a role, which runs after players are determined but before the modifiers are given.
/// </summary>
/// <param name="role">The role to be checked.</param>
/// <returns><see langword="true"/> if the modifier is valid on the role, otherwise <see langword="false"/>.</returns>
public virtual bool IsModifierValidOnPostCheck(RoleBehaviour role) => IsModifierValidOn(role);
/// <summary>
/// Determines whether the player won the game with this modifier. The modifier with the highest priority will override other modifiers.
/// </summary>