species restriction for uplink listings (#11185)
This commit is contained in:
47
Content.Server/Store/Conditions/BuyerSpeciesCondition.cs
Normal file
47
Content.Server/Store/Conditions/BuyerSpeciesCondition.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Content.Shared.Store;
|
||||
using Content.Shared.Species;
|
||||
using Content.Shared.CharacterAppearance.Components;
|
||||
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 species.
|
||||
/// Supports both blacklists and whitelists.
|
||||
/// </summary>
|
||||
public sealed class BuyerSpeciesCondition : ListingCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// A whitelist of species that can purchase this listing.
|
||||
/// </summary>
|
||||
[DataField("whitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<SpeciesPrototype>))]
|
||||
public HashSet<string>? Whitelist;
|
||||
|
||||
/// <summary>
|
||||
/// A blacklist of species that cannot purchase this listing.
|
||||
/// </summary>
|
||||
[DataField("blacklist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<SpeciesPrototype>))]
|
||||
public HashSet<string>? Blacklist;
|
||||
|
||||
public override bool Condition(ListingConditionArgs args)
|
||||
{
|
||||
var ent = args.EntityManager;
|
||||
|
||||
if (!ent.TryGetComponent<HumanoidAppearanceComponent>(args.Buyer, out var appearance) || appearance.Species == null)
|
||||
return true; // inanimate or non-humanoid entities should be handled elsewhere, main example being surplus crates
|
||||
|
||||
if (Blacklist != null)
|
||||
{
|
||||
if (Blacklist.Contains(appearance.Species))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Whitelist != null)
|
||||
{
|
||||
if (!Whitelist.Contains(appearance.Species))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user