AgeRequirement.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Diagnostics.CodeAnalysis;
  2. using Content.Shared.Preferences;
  3. using JetBrains.Annotations;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Serialization;
  6. using Robust.Shared.Utility;
  7. namespace Content.Shared.Roles;
  8. /// <summary>
  9. /// Requires the character to be older or younger than a certain age (inclusive)
  10. /// </summary>
  11. [UsedImplicitly]
  12. [Serializable, NetSerializable]
  13. public sealed partial class AgeRequirement : JobRequirement
  14. {
  15. [DataField(required: true)]
  16. public int RequiredAge;
  17. public override bool Check(IEntityManager entManager,
  18. IPrototypeManager protoManager,
  19. HumanoidCharacterProfile? profile,
  20. IReadOnlyDictionary<string, TimeSpan> playTimes,
  21. [NotNullWhen(false)] out FormattedMessage? reason)
  22. {
  23. reason = new FormattedMessage();
  24. if (profile is null) //the profile could be null if the player is a ghost. In this case we don't need to block the role selection for ghostrole
  25. return true;
  26. if (!Inverted)
  27. {
  28. reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-age-too-young",
  29. ("age", RequiredAge)));
  30. if (profile.Age < RequiredAge)
  31. return false;
  32. }
  33. else
  34. {
  35. reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-age-too-old",
  36. ("age", RequiredAge)));
  37. if (profile.Age > RequiredAge)
  38. return false;
  39. }
  40. return true;
  41. }
  42. }