2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind;
|
2022-08-17 00:34:25 -04:00
|
|
|
using Content.Shared.Roles;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Roles.Jobs;
|
2022-08-17 00:34:25 -04:00
|
|
|
using Content.Shared.Store;
|
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Store.Conditions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Allows a store entry to be filtered out based on the user's job.
|
|
|
|
|
/// Supports both blacklists and whitelists
|
|
|
|
|
/// </summary>
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class BuyerJobCondition : ListingCondition
|
2022-08-17 00:34:25 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A whitelist of jobs prototypes that can purchase this listing. Only one needs to be found.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("whitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<JobPrototype>))]
|
|
|
|
|
public HashSet<string>? Whitelist;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A blacklist of job prototypes that can purchase this listing. Only one needs to be found.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("blacklist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<JobPrototype>))]
|
|
|
|
|
public HashSet<string>? Blacklist;
|
|
|
|
|
|
|
|
|
|
public override bool Condition(ListingConditionArgs args)
|
|
|
|
|
{
|
|
|
|
|
var ent = args.EntityManager;
|
2023-08-30 21:46:11 -07:00
|
|
|
var minds = ent.System<SharedMindSystem>();
|
2022-08-17 00:34:25 -04:00
|
|
|
|
2023-08-28 16:53:24 -07:00
|
|
|
// this is for things like surplus crate
|
|
|
|
|
if (!minds.TryGetMind(args.Buyer, out var mindId, out _))
|
|
|
|
|
return true;
|
2022-08-17 00:34:25 -04:00
|
|
|
|
2023-08-30 21:46:11 -07:00
|
|
|
var jobs = ent.System<SharedJobSystem>();
|
2024-10-10 10:48:56 +02:00
|
|
|
jobs.MindTryGetJob(mindId, out var job);
|
2023-09-01 00:24:36 -07:00
|
|
|
|
|
|
|
|
if (Blacklist != null)
|
|
|
|
|
{
|
2024-10-10 10:48:56 +02:00
|
|
|
if (job is not null && Blacklist.Contains(job.ID))
|
2023-09-01 00:24:36 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Whitelist != null)
|
2022-08-17 00:34:25 -04:00
|
|
|
{
|
2024-10-10 10:48:56 +02:00
|
|
|
if (job == null || !Whitelist.Contains(job.ID))
|
2023-09-01 00:24:36 -07:00
|
|
|
return false;
|
2022-08-17 00:34:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|