mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add multiplayer mod validity check methods for server consumption
This commit is contained in:
@ -575,11 +575,16 @@ namespace osu.Game
|
|||||||
if (SelectedMods.Disabled)
|
if (SelectedMods.Disabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!ModUtils.CheckValidForGameplay(mods.NewValue, out var invalid))
|
var validMods = mods.NewValue;
|
||||||
{
|
|
||||||
|
if (!ModUtils.CheckCompatibleSet(validMods, out var incompatible))
|
||||||
|
validMods = validMods.Except(incompatible).ToArray();
|
||||||
|
|
||||||
|
if (!ModUtils.CheckValidForGameplay(validMods, out var invalid))
|
||||||
|
validMods = validMods.Except(invalid).ToArray();
|
||||||
|
|
||||||
// ensure we always have a valid set of mods.
|
// ensure we always have a valid set of mods.
|
||||||
SelectedMods.Value = mods.NewValue.Except(invalid).ToArray();
|
SelectedMods.Value = validMods;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -112,14 +112,34 @@ namespace osu.Game.Utils
|
|||||||
/// <param name="invalidMods">Invalid mods, if any were found. Can be null if all mods were valid.</param>
|
/// <param name="invalidMods">Invalid mods, if any were found. Can be null if all mods were valid.</param>
|
||||||
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
|
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
|
||||||
public static bool CheckValidForGameplay(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
|
public static bool CheckValidForGameplay(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
|
||||||
|
=> checkValid(mods, m => m.Type != ModType.System && m.HasImplementation && !(m is MultiMod), out invalidMods);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check the provided combination of mods are valid for a multiplayer match session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mods">The mods to check.</param>
|
||||||
|
/// <param name="invalidMods">Invalid mods, if any were found. Can be null if all mods were valid.</param>
|
||||||
|
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
|
||||||
|
public static bool CheckValidForMultiplayer(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
|
||||||
|
=> checkValid(mods, m => m.PlayableInMultiplayer, out invalidMods);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check the provided combination of mods are valid as "free mods" in a multiplayer match session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mods">The mods to check.</param>
|
||||||
|
/// <param name="invalidMods">Invalid mods, if any were found. Can be null if all mods were valid.</param>
|
||||||
|
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
|
||||||
|
public static bool CheckValidFreeModsForMultiplayer(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
|
||||||
|
=> checkValid(mods, m => m.ValidFreeModInMultiplayer, out invalidMods);
|
||||||
|
|
||||||
|
private static bool checkValid(IEnumerable<Mod> mods, Predicate<Mod> valid, [NotNullWhen(false)] out List<Mod>? invalidMods)
|
||||||
{
|
{
|
||||||
mods = mods.ToArray();
|
mods = mods.ToArray();
|
||||||
|
invalidMods = null;
|
||||||
CheckCompatibleSet(mods, out invalidMods);
|
|
||||||
|
|
||||||
foreach (var mod in mods)
|
foreach (var mod in mods)
|
||||||
{
|
{
|
||||||
if (mod.Type == ModType.System || !mod.HasImplementation || mod is MultiMod)
|
if (!valid(mod))
|
||||||
{
|
{
|
||||||
invalidMods ??= new List<Mod>();
|
invalidMods ??= new List<Mod>();
|
||||||
invalidMods.Add(mod);
|
invalidMods.Add(mod);
|
||||||
|
Reference in New Issue
Block a user