Conditional map support (#5868)

Co-authored-by: E F R <602406+Efruit@users.noreply.github.com>
Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
This commit is contained in:
Moony
2021-12-23 12:38:14 -06:00
committed by GitHub
parent e2bcf619d1
commit c06ee05461
4 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
using System.Linq;
using Content.Server.Holiday;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Server.Maps.Conditions;
public class HolidayMapCondition : GameMapCondition
{
[DataField("holidays")]
public string[] Holidays { get; } = default!;
public override bool Check(GameMapPrototype map)
{
var holidaySystem = EntitySystem.Get<HolidaySystem>();
return Holidays.Any(holiday => holidaySystem.IsCurrentlyHoliday(holiday)) ^ Inverted;
}
}

View File

@@ -0,0 +1,11 @@
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Maps;
[ImplicitDataDefinitionForInheritors]
public abstract class GameMapCondition
{
[DataField("inverted")]
public bool Inverted { get; }
public abstract bool Check(GameMapPrototype map);
}

View File

@@ -111,7 +111,9 @@ public class GameMapManager : IGameMapManager
private bool IsMapEligible(GameMapPrototype map) private bool IsMapEligible(GameMapPrototype map)
{ {
return map.MaxPlayers >= _playerManager.PlayerCount && map.MinPlayers <= _playerManager.PlayerCount; return map.MaxPlayers >= _playerManager.PlayerCount &&
map.MinPlayers <= _playerManager.PlayerCount &&
map.Conditions.All(x => x.Check(map));
} }
private bool TryLookupMap(string gameMap, [NotNullWhen(true)] out GameMapPrototype? map) private bool TryLookupMap(string gameMap, [NotNullWhen(true)] out GameMapPrototype? map)

View File

@@ -66,6 +66,9 @@ public class GameMapPrototype : IPrototype
[DataField("votable")] [DataField("votable")]
public bool Votable { get; } = true; public bool Votable { get; } = true;
[DataField("conditions")]
public List<GameMapCondition> Conditions { get; } = new();
/// <summary> /// <summary>
/// Jobs used at round start should the station run out of job slots. /// Jobs used at round start should the station run out of job slots.
/// Doesn't necessarily mean the station has infinite slots for the given jobs midround! /// Doesn't necessarily mean the station has infinite slots for the given jobs midround!