]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Moves ID field to ListingData and adds BuyBeforeCondition (#22438)
authorkeronshb <54602815+keronshb@users.noreply.github.com>
Wed, 13 Dec 2023 21:57:38 +0000 (16:57 -0500)
committerGitHub <noreply@github.com>
Wed, 13 Dec 2023 21:57:38 +0000 (16:57 -0500)
Content.Server/Store/Conditions/BuyBeforeCondition.cs [new file with mode: 0644]
Content.Shared/Store/ListingPrototype.cs

diff --git a/Content.Server/Store/Conditions/BuyBeforeCondition.cs b/Content.Server/Store/Conditions/BuyBeforeCondition.cs
new file mode 100644 (file)
index 0000000..132f353
--- /dev/null
@@ -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
+{
+    /// <summary>
+    ///     Required listing(s) needed to purchase before this listing is available
+    /// </summary>
+    [DataField(required: true)]
+    public HashSet<ProtoId<ListingPrototype>> Whitelist;
+
+    /// <summary>
+    ///     Listing(s) that if bought, block this purchase, if any.
+    /// </summary>
+    public HashSet<ProtoId<ListingPrototype>>? Blacklist;
+
+    public override bool Condition(ListingConditionArgs args)
+    {
+        if (!args.EntityManager.TryGetComponent<StoreComponent>(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;
+    }
+}
index 0adcbd46374cc8e42e96793b51b159f80e95ef27..d80c5cf6c83af23428f48628c30234cbd623d5ea 100644 (file)
@@ -18,6 +18,10 @@ namespace Content.Shared.Store;
 [Virtual, DataDefinition]
 public partial class ListingData : IEquatable<ListingData>, ICloneable
 {
+    [ViewVariables]
+    [IdDataField]
+    public string ID { get; private set; } = default!;
+
     /// <summary>
     /// The name of the listing. If empty, uses the entity's name (if present)
     /// </summary>
@@ -131,6 +135,7 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
     {
         return new ListingData
         {
+            ID = ID,
             Name = Name,
             Description = Description,
             Categories = Categories,
@@ -156,7 +161,5 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
 [DataDefinition]
 public sealed partial class ListingPrototype : ListingData, IPrototype
 {
-    [ViewVariables]
-    [IdDataField]
-    public string ID { get; private set; } = default!;
+
 }