From 9864cb02327396d7d126881fc966c31d94db0f42 Mon Sep 17 00:00:00 2001 From: keronshb <54602815+keronshb@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:57:38 -0500 Subject: [PATCH] Moves ID field to ListingData and adds BuyBeforeCondition (#22438) --- .../Store/Conditions/BuyBeforeCondition.cs | 56 +++++++++++++++++++ Content.Shared/Store/ListingPrototype.cs | 9 ++- 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Content.Server/Store/Conditions/BuyBeforeCondition.cs diff --git a/Content.Server/Store/Conditions/BuyBeforeCondition.cs b/Content.Server/Store/Conditions/BuyBeforeCondition.cs new file mode 100644 index 0000000000..132f353439 --- /dev/null +++ b/Content.Server/Store/Conditions/BuyBeforeCondition.cs @@ -0,0 +1,56 @@ +using Content.Server.Store.Components; +using Content.Server.Store.Systems; +using Content.Shared.Store; +using Robust.Shared.Prototypes; + +namespace Content.Server.Store.Conditions; + +public sealed partial class BuyBeforeCondition : ListingCondition +{ + /// + /// Required listing(s) needed to purchase before this listing is available + /// + [DataField(required: true)] + public HashSet> Whitelist; + + /// + /// Listing(s) that if bought, block this purchase, if any. + /// + public HashSet>? Blacklist; + + public override bool Condition(ListingConditionArgs args) + { + if (!args.EntityManager.TryGetComponent(args.StoreEntity, out var storeComp)) + return false; + + var allListings = storeComp.Listings; + + var purchasesFound = false; + + if (Blacklist != null) + { + foreach (var blacklistListing in Blacklist) + { + foreach (var listing in allListings) + { + if (listing.ID == blacklistListing.Id && listing.PurchaseAmount > 0) + return false; + } + } + } + + foreach (var requiredListing in Whitelist) + { + foreach (var listing in allListings) + { + if (listing.ID == requiredListing.Id) + { + purchasesFound = listing.PurchaseAmount > 0; + break; + } + } + } + + return purchasesFound; + } +} diff --git a/Content.Shared/Store/ListingPrototype.cs b/Content.Shared/Store/ListingPrototype.cs index 0adcbd4637..d80c5cf6c8 100644 --- a/Content.Shared/Store/ListingPrototype.cs +++ b/Content.Shared/Store/ListingPrototype.cs @@ -18,6 +18,10 @@ namespace Content.Shared.Store; [Virtual, DataDefinition] public partial class ListingData : IEquatable, ICloneable { + [ViewVariables] + [IdDataField] + public string ID { get; private set; } = default!; + /// /// The name of the listing. If empty, uses the entity's name (if present) /// @@ -131,6 +135,7 @@ public partial class ListingData : IEquatable, ICloneable { return new ListingData { + ID = ID, Name = Name, Description = Description, Categories = Categories, @@ -156,7 +161,5 @@ public partial class ListingData : IEquatable, ICloneable [DataDefinition] public sealed partial class ListingPrototype : ListingData, IPrototype { - [ViewVariables] - [IdDataField] - public string ID { get; private set; } = default!; + } -- 2.51.2