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:
22
Content.Server/Maps/Conditions/HolidayMapCondition.cs
Normal file
22
Content.Server/Maps/Conditions/HolidayMapCondition.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
11
Content.Server/Maps/GameMapCondition.cs
Normal file
11
Content.Server/Maps/GameMapCondition.cs
Normal 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);
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -66,6 +66,9 @@ public class GameMapPrototype : IPrototype
|
||||
[DataField("votable")]
|
||||
public bool Votable { get; } = true;
|
||||
|
||||
[DataField("conditions")]
|
||||
public List<GameMapCondition> Conditions { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 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!
|
||||
|
||||
Reference in New Issue
Block a user