using System.Diagnostics.CodeAnalysis;
using Content.Shared.Preferences;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Roles;
public static class JobRequirements
{
///
/// Checks if the requirements of the job are met by the provided play-times.
///
/// The job to test.
/// The playtimes used for the check.
/// If the requirements were not met, details are provided here.
/// Returns true if all requirements were met or there were no requirements.
public static bool TryRequirementsMet(
JobPrototype job,
IReadOnlyDictionary playTimes,
[NotNullWhen(false)] out FormattedMessage? reason,
IEntityManager entManager,
IPrototypeManager protoManager,
HumanoidCharacterProfile? profile)
{
var sys = entManager.System();
var requirements = sys.GetRoleRequirements(job);
return TryRequirementsMet(requirements, playTimes, out reason, entManager, protoManager, profile);
}
///
/// Checks if the list of requirements are met by the provided play-times.
///
/// The requirements to test.
/// The playtimes used for the check.
/// If the requirements were not met, details are provided here.
/// Returns true if all requirements were met or there were no requirements.
public static bool TryRequirementsMet(
HashSet? requirements,
IReadOnlyDictionary playTimes,
[NotNullWhen(false)] out FormattedMessage? reason,
IEntityManager entManager,
IPrototypeManager protoManager,
HumanoidCharacterProfile? profile)
{
reason = null;
if (requirements == null)
return true;
foreach (var requirement in requirements)
{
if (!requirement.Check(entManager, protoManager, profile, playTimes, out reason))
return false;
}
return true;
}
}
///
/// Abstract class for playtime and other requirements for role gates.
///
[ImplicitDataDefinitionForInheritors]
[Serializable, NetSerializable]
public abstract partial class JobRequirement
{
[DataField]
public bool Inverted;
public abstract bool Check(
IEntityManager entManager,
IPrototypeManager protoManager,
HumanoidCharacterProfile? profile,
IReadOnlyDictionary playTimes,
[NotNullWhen(false)] out FormattedMessage? reason);
}