Skip to content

Commit

Permalink
add modifier assignment priority
Browse files Browse the repository at this point in the history
  • Loading branch information
AlchlcDvl committed Sep 25, 2024
1 parent 2a3c8fe commit 46490af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions MiraAPI/Modifiers/ModifierManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ internal static void AssignModifiers(List<PlayerControl> plrs)
}

var shuffledModifiers = filteredModifiers.Randomize();
var map = new Dictionary<uint, int>();

foreach (var id in shuffledModifiers)
{
if (Activator.CreateInstance(IdToTypeModifierMap[id]) is not GameModifier mod)
{
Logger<MiraApiPlugin>.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);
Expand Down
7 changes: 7 additions & 0 deletions MiraAPI/Modifiers/Types/GameModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public abstract class GameModifier : BaseModifier
/// <returns>An int value greater than or equal to zero.</returns>
public abstract int GetAmountPerGame();

/// <summary>
/// Gets the priority at which the modifier will spawn. The higher the value, the higher up on the assignment list.
/// </summary>
/// <returns>An int value greater than or equal to -1.</returns>
public virtual int Priority() => -1;

/// <summary>
/// Determines whether the modifier is valid on a role.
/// </summary>
Expand All @@ -27,6 +33,7 @@ public abstract class GameModifier : BaseModifier
/// <summary>
/// Determines whether the player won the game with this modifier.
/// </summary>
/// <param name="reason">The reason why the game ended.</param>
/// <returns>True if the player won, false if they lost. Return null to use the player's default win condition.</returns>
public virtual bool? DidWin(GameOverReason reason) => null;
}

0 comments on commit 46490af

Please sign in to comment.