From 73c8ad018370a8d8c1e89776d36da26e3a5d17d6 Mon Sep 17 00:00:00 2001 From: alexalexmax <149889301+alexalexmax@users.noreply.github.com> Date: Fri, 28 Nov 2025 02:43:47 -0800 Subject: [PATCH] Adds option to whitelist or blacklist store entries based on buyer objectives (#41493) * BuyerObjectiveWhitelistCondition done * fix to check every buyer objective for a blacklisted objective before checking whitelisted objectives * resolved requested changes * forgot a line * Update Content.Server/Store/Conditions/BuyerObjectiveWhitelistCondition.cs * Replaced IsBlacklistPass with IsWhitelistPass * cleaning up * placed whitelist == null check above objective loop * Moved empty whitelist check below foreach loop * final cleanup i pray --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- .../BuyerObjectiveWhitelistCondition.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Content.Server/Store/Conditions/BuyerObjectiveWhitelistCondition.cs diff --git a/Content.Server/Store/Conditions/BuyerObjectiveWhitelistCondition.cs b/Content.Server/Store/Conditions/BuyerObjectiveWhitelistCondition.cs new file mode 100644 index 0000000000..b6e7496ce9 --- /dev/null +++ b/Content.Server/Store/Conditions/BuyerObjectiveWhitelistCondition.cs @@ -0,0 +1,46 @@ +using Content.Shared.Mind; +using Content.Shared.Store; +using Content.Shared.Whitelist; + +namespace Content.Server.Store.Conditions; + +/// +/// Filters out an entry based on the objectives of an entity. +/// +public sealed partial class BuyerObjectiveWhitelistCondition : ListingCondition +{ + /// + /// A whitelist of objective types. + /// If there is no whitelist, the object will appear by default. + /// + [DataField] + public EntityWhitelist? Whitelist; + + /// + /// A blacklist of objective types. + /// If an objective is both whitelisted and blacklisted the blacklist will take priority and the entry will not appear. + /// + [DataField] + public EntityWhitelist? Blacklist; + + public override bool Condition(ListingConditionArgs args) + { + var ent = args.EntityManager; + var whitelistSystem = ent.System(); + + if (!args.EntityManager.TryGetComponent(args.Buyer, out var mindComp)) + return true; // inanimate objects don't have minds + + var whitelisted = false; + + foreach (var objective in mindComp.Objectives) + { + if (whitelistSystem.IsWhitelistPass(Blacklist, objective)) + return false; + if (whitelistSystem.IsWhitelistPass(Whitelist, objective)) + whitelisted = true; + } + + return Whitelist == null || whitelisted; + } +} -- 2.52.0