From 7c085b1072f8ed4b3ea2f0ce3af3f142ecef73a0 Mon Sep 17 00:00:00 2001
From: Atony <75191600+AtonyGit@users.noreply.github.com>
Date: Sat, 25 Jul 2026 18:03:29 -0500
Subject: [PATCH] Add modifier post assignment-check
---
MiraAPI/Modifiers/ModifierManager.cs | 7 ++++++-
MiraAPI/Modifiers/Types/GameModifier.cs | 7 +++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/MiraAPI/Modifiers/ModifierManager.cs b/MiraAPI/Modifiers/ModifierManager.cs
index 12a9519..c2688a0 100644
--- a/MiraAPI/Modifiers/ModifierManager.cs
+++ b/MiraAPI/Modifiers/ModifierManager.cs
@@ -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);
+ }
}
diff --git a/MiraAPI/Modifiers/Types/GameModifier.cs b/MiraAPI/Modifiers/Types/GameModifier.cs
index b58f8e0..f5ae883 100644
--- a/MiraAPI/Modifiers/Types/GameModifier.cs
+++ b/MiraAPI/Modifiers/Types/GameModifier.cs
@@ -33,6 +33,13 @@ public abstract class GameModifier : BaseModifier
/// if the modifier is valid on the role, otherwise .
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
+ ///
+ /// Determines whether the modifier is valid on a role, which runs after players are determined but before the modifiers are given.
+ ///
+ /// The role to be checked.
+ /// if the modifier is valid on the role, otherwise .
+ public virtual bool IsModifierValidOnPostCheck(RoleBehaviour role) => IsModifierValidOn(role);
+
///
/// Determines whether the player won the game with this modifier. The modifier with the highest priority will override other modifiers.
///