diff --git a/MiraAPI/Modifiers/ModifierManager.cs b/MiraAPI/Modifiers/ModifierManager.cs index 819f289..65b6af7 100644 --- a/MiraAPI/Modifiers/ModifierManager.cs +++ b/MiraAPI/Modifiers/ModifierManager.cs @@ -97,6 +97,21 @@ public static class ModifierManager } var shuffledModifiers = filteredModifiers.Randomize(); + var map = new Dictionary(); + + foreach (var id in shuffledModifiers) + { + if (Activator.CreateInstance(IdToTypeModifierMap[id]) is not GameModifier mod) + { + Logger.Error($"Failed to create instance of {IdToTypeModifierMap[id].Name}"); + continue; + } + + map[id] = mod.Priority(); + } + + shuffledModifiers = map.OrderByDescending(x => x.Value).Select(x => x.Key).ToList(); + if (shuffledModifiers.Count > plrs.Count) { shuffledModifiers = shuffledModifiers.GetRange(0, plrs.Count); diff --git a/MiraAPI/Modifiers/Types/GameModifier.cs b/MiraAPI/Modifiers/Types/GameModifier.cs index 60c5f56..a7b1fe1 100644 --- a/MiraAPI/Modifiers/Types/GameModifier.cs +++ b/MiraAPI/Modifiers/Types/GameModifier.cs @@ -17,6 +17,12 @@ public abstract class GameModifier : BaseModifier /// An int value greater than or equal to zero. public abstract int GetAmountPerGame(); + /// + /// Gets the priority at which the modifier will spawn. The higher the value, the higher up on the assignment list. + /// + /// An int value greater than or equal to -1. + public virtual int Priority() => -1; + /// /// Determines whether the modifier is valid on a role. /// @@ -27,6 +33,7 @@ public abstract class GameModifier : BaseModifier /// /// Determines whether the player won the game with this modifier. /// + /// The reason why the game ended. /// True if the player won, false if they lost. Return null to use the player's default win condition. public virtual bool? DidWin(GameOverReason reason) => null; }