From c06ee05461ad407aa7b3831839b181589448bdf6 Mon Sep 17 00:00:00 2001 From: Moony Date: Thu, 23 Dec 2021 12:38:14 -0600 Subject: [PATCH] Conditional map support (#5868) Co-authored-by: E F R <602406+Efruit@users.noreply.github.com> Co-authored-by: Paul Ritter --- .../Maps/Conditions/HolidayMapCondition.cs | 22 +++++++++++++++++++ Content.Server/Maps/GameMapCondition.cs | 11 ++++++++++ Content.Server/Maps/GameMapManager.cs | 4 +++- Content.Server/Maps/GameMapPrototype.cs | 3 +++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Content.Server/Maps/Conditions/HolidayMapCondition.cs create mode 100644 Content.Server/Maps/GameMapCondition.cs diff --git a/Content.Server/Maps/Conditions/HolidayMapCondition.cs b/Content.Server/Maps/Conditions/HolidayMapCondition.cs new file mode 100644 index 0000000000..a68057380e --- /dev/null +++ b/Content.Server/Maps/Conditions/HolidayMapCondition.cs @@ -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(); + + return Holidays.Any(holiday => holidaySystem.IsCurrentlyHoliday(holiday)) ^ Inverted; + } +} diff --git a/Content.Server/Maps/GameMapCondition.cs b/Content.Server/Maps/GameMapCondition.cs new file mode 100644 index 0000000000..7a9e66d054 --- /dev/null +++ b/Content.Server/Maps/GameMapCondition.cs @@ -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); +} diff --git a/Content.Server/Maps/GameMapManager.cs b/Content.Server/Maps/GameMapManager.cs index efabeeae3e..974c89057c 100644 --- a/Content.Server/Maps/GameMapManager.cs +++ b/Content.Server/Maps/GameMapManager.cs @@ -111,7 +111,9 @@ public class GameMapManager : IGameMapManager 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) diff --git a/Content.Server/Maps/GameMapPrototype.cs b/Content.Server/Maps/GameMapPrototype.cs index d64fe04192..09c0c98ab4 100644 --- a/Content.Server/Maps/GameMapPrototype.cs +++ b/Content.Server/Maps/GameMapPrototype.cs @@ -66,6 +66,9 @@ public class GameMapPrototype : IPrototype [DataField("votable")] public bool Votable { get; } = true; + [DataField("conditions")] + public List Conditions { get; } = new(); + /// /// 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!