PointsCostLoadoutEffect.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Diagnostics.CodeAnalysis;
  2. using Robust.Shared.Player;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Utility;
  5. namespace Content.Shared.Preferences.Loadouts.Effects;
  6. public sealed partial class PointsCostLoadoutEffect : LoadoutEffect
  7. {
  8. [DataField(required: true)]
  9. public int Cost = 1;
  10. public override bool Validate(
  11. HumanoidCharacterProfile profile,
  12. RoleLoadout loadout,
  13. ICommonSession? session,
  14. IDependencyCollection collection,
  15. [NotNullWhen(false)] out FormattedMessage? reason)
  16. {
  17. reason = null;
  18. var protoManager = collection.Resolve<IPrototypeManager>();
  19. if (!protoManager.TryIndex(loadout.Role, out var roleProto) || roleProto.Points == null)
  20. {
  21. return true;
  22. }
  23. if (loadout.Points <= Cost)
  24. {
  25. reason = FormattedMessage.FromUnformatted("loadout-group-points-insufficient");
  26. return false;
  27. }
  28. return true;
  29. }
  30. public override void Apply(RoleLoadout loadout)
  31. {
  32. loadout.Points -= Cost;
  33. }
  34. }