using Content.Server.Mind; using Content.Server.Roles.Jobs; using Content.Shared.Roles; using Content.Shared.Store; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set; namespace Content.Server.Store.Conditions; /// /// Allows a store entry to be filtered out based on the user's job. /// Supports both blacklists and whitelists /// public sealed partial class BuyerJobCondition : ListingCondition { /// /// A whitelist of jobs prototypes that can purchase this listing. Only one needs to be found. /// [DataField("whitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))] public HashSet? Whitelist; /// /// A blacklist of job prototypes that can purchase this listing. Only one needs to be found. /// [DataField("blacklist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))] public HashSet? Blacklist; public override bool Condition(ListingConditionArgs args) { var ent = args.EntityManager; var minds = ent.System(); // this is for things like surplus crate if (!minds.TryGetMind(args.Buyer, out var mindId, out _)) return true; var jobs = ent.System(); if (jobs.MindTryGetJob(mindId, out var job, out _)) { if (Blacklist != null) { if (job.PrototypeId != null && Blacklist.Contains(job.PrototypeId)) return false; } if (Whitelist != null) { if (job.PrototypeId == null || !Whitelist.Contains(job.PrototypeId)) return false; } } return true; } }