using Content.Shared.Humanoid;
using Content.Shared.Store;
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
using Content.Shared.Mind;
namespace Content.Server.Store.Conditions;
///
/// Allows a store entry to be filtered out based on the user's species.
/// Supports both blacklists and whitelists.
///
public sealed partial class BuyerSpeciesCondition : ListingCondition
{
///
/// A whitelist of species that can purchase this listing.
///
[DataField("whitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
public HashSet? Whitelist;
///
/// A blacklist of species that cannot purchase this listing.
///
[DataField("blacklist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
public HashSet? Blacklist;
public override bool Condition(ListingConditionArgs args)
{
var ent = args.EntityManager;
if (!ent.TryGetComponent(args.Buyer, out var mind))
return true; // needed to obtain body entityuid to check for humanoid appearance
if (!ent.TryGetComponent(mind.OwnedEntity, out var appearance))
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;
}
}