mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
add check inactive variants of hasmodifier
This commit is contained in:
1 parent
a56b6d52ef
commit
140b697aaf
3 files changed
+69
-11
No files matched your search
@@ -507,4 +507,61 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
{
|
{
|
||||||
return ActiveModifiers.Exists(x => x.UniqueId == id);
|
return ActiveModifiers.Exists(x => x.UniqueId == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a player has an active modifier by its type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="checkInactive">Whether to check inactive modifiers (those pending to be added or removed).</param>
|
||||||
|
/// <param name="predicate">The predicate to check the modifier.</param>
|
||||||
|
/// <typeparam name="T">The Type of the Modifier.</typeparam>
|
||||||
|
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||||
|
[HideFromIl2Cpp]
|
||||||
|
public bool HasModifier<T>(bool checkInactive, Func<T, bool>? predicate=null) where T : BaseModifier
|
||||||
|
{
|
||||||
|
return ActiveModifiers.Exists(MatchExpr) || (checkInactive && (_toAdd.Exists(MatchExpr) || _toRemove.Exists(MatchExpr)));
|
||||||
|
bool MatchExpr(BaseModifier bm) => bm is T modifier && (predicate == null || predicate(modifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a player has an active modifier by its type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The modifier type.</param>
|
||||||
|
/// <param name="checkInactive">Whether to check inactive modifiers (those pending to be added or removed).</param>
|
||||||
|
/// <param name="predicate">The predicate to check the modifier.</param>
|
||||||
|
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||||
|
[HideFromIl2Cpp]
|
||||||
|
public bool HasModifier(Type type, bool checkInactive, Func<BaseModifier, bool>? predicate=null)
|
||||||
|
{
|
||||||
|
return ActiveModifiers.Exists(MatchExpr) || (checkInactive && (_toAdd.Exists(MatchExpr) || _toRemove.Exists(MatchExpr)));
|
||||||
|
bool MatchExpr(BaseModifier bm) => bm.GetType() == type && (predicate == null || predicate(bm));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a player has an active modifier by its type ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The modifier's type ID.</param>
|
||||||
|
/// <param name="checkInactive">Whether to check inactive modifiers (those pending to be added or removed).</param>
|
||||||
|
/// <param name="predicate">The predicate to check the modifier.</param>
|
||||||
|
/// <returns>True if the modifier is present, false otherwise.</returns>
|
||||||
|
[HideFromIl2Cpp]
|
||||||
|
public bool HasModifier(uint id, bool checkInactive, Func<BaseModifier, bool>? predicate=null)
|
||||||
|
{
|
||||||
|
var type = ModifierManager.GetModifierType(id) ?? throw new InvalidOperationException(
|
||||||
|
$"Cannot get modifier with id {id} because it is not registered.");
|
||||||
|
|
||||||
|
return HasModifier(type, checkInactive, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a player has an active modifier by its unique ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The modifier's guid.</param>
|
||||||
|
/// <param name="checkInactive">Whether to check inactive modifiers (those pending to be added or removed).</param>
|
||||||
|
/// <returns>True if the modifier is present, false otherwise.</returns>
|
||||||
|
[HideFromIl2Cpp]
|
||||||
|
public bool HasModifier(Guid id, bool checkInactive)
|
||||||
|
{
|
||||||
|
return ActiveModifiers.Exists(MatchExpr) || (checkInactive && (_toAdd.Exists(MatchExpr) || _toRemove.Exists(MatchExpr)));
|
||||||
|
bool MatchExpr(BaseModifier bm) => bm.UniqueId == id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -180,6 +180,17 @@ public static class ModifierExtensions
|
|||||||
return player.GetModifierComponent().HasModifier(typeId, predicate);
|
return player.GetModifierComponent().HasModifier(typeId, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the player has a specific modifier by its GUID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player">The PlayerControl instance.</param>
|
||||||
|
/// <param name="uniqueId">The unique ID of the modifier.</param>
|
||||||
|
/// <returns>True if the player has the modifier, false otherwise.</returns>
|
||||||
|
public static bool HasModifier(this PlayerControl player, Guid uniqueId)
|
||||||
|
{
|
||||||
|
return player.GetModifierComponent().HasModifier(uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears all modifiers from a player.
|
/// Clears all modifiers from a player.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -204,17 +215,6 @@ public static class ModifierExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the player has a specific modifier by its GUID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="player">The PlayerControl instance.</param>
|
|
||||||
/// <param name="uniqueId">The unique ID of the modifier.</param>
|
|
||||||
/// <returns>True if the player has the modifier, false otherwise.</returns>
|
|
||||||
public static bool HasModifier(this PlayerControl player, Guid uniqueId)
|
|
||||||
{
|
|
||||||
return player.GetModifierComponent().HasModifier(uniqueId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to get a modifier by its type.
|
/// Tries to get a modifier by its type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ public static class ModifierManager
|
|||||||
|
|
||||||
// Filter and sort modifiers by descending priority.
|
// Filter and sort modifiers by descending priority.
|
||||||
var modifiers = IdToTypeModifierMap
|
var modifiers = IdToTypeModifierMap
|
||||||
|
.Where(x=>x.Value.IsAssignableTo(typeof(GameModifier)))
|
||||||
.Select(x => Activator.CreateInstance(x.Value) as GameModifier)
|
.Select(x => Activator.CreateInstance(x.Value) as GameModifier)
|
||||||
.OfType<GameModifier>()
|
.OfType<GameModifier>()
|
||||||
.Where(x => x.GetAmountPerGame() > 0 && x.GetAssignmentChance() > 0)
|
.Where(x => x.GetAmountPerGame() > 0 && x.GetAssignmentChance() > 0)
|
||||||
|
|||||||
Reference in new issue
Block a user