* refactor JobRequirements * add profile support * fix * Update quartermaster.yml * sloth fixes * inport 30208 * Update DepartmentPrototype.cs * species restriction * left tweak stick * stringbuilder is cool!
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
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
|
|
{
|
|
public static bool TryRequirementsMet(
|
|
JobPrototype job,
|
|
IReadOnlyDictionary<string, TimeSpan> playTimes,
|
|
[NotNullWhen(false)] out FormattedMessage? reason,
|
|
IEntityManager entManager,
|
|
IPrototypeManager protoManager,
|
|
HumanoidCharacterProfile? profile)
|
|
{
|
|
var sys = entManager.System<SharedRoleSystem>();
|
|
var requirements = sys.GetJobRequirement(job);
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Abstract class for playtime and other requirements for role gates.
|
|
/// </summary>
|
|
[ImplicitDataDefinitionForInheritors]
|
|
[Serializable, NetSerializable]
|
|
public abstract partial class JobRequirement
|
|
{
|
|
[DataField]
|
|
public bool Inverted;
|
|
|
|
public abstract bool Check(
|
|
IEntityManager entManager,
|
|
IPrototypeManager protoManager,
|
|
HumanoidCharacterProfile? profile,
|
|
IReadOnlyDictionary<string, TimeSpan> playTimes,
|
|
[NotNullWhen(false)] out FormattedMessage? reason);
|
|
}
|