]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix static pricing for stacks (#14865)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 26 Mar 2023 17:01:42 +0000 (04:01 +1100)
committerGitHub <noreply@github.com>
Sun, 26 Mar 2023 17:01:42 +0000 (12:01 -0500)
Removed BaseItem price as it was always a placeholder and easier to just change without it.
Ensure staticprice is never used if stackprice is present.
Added StackComponent to the test so the behavior matches expectation.

Content.IntegrationTests/Tests/CargoTest.cs
Content.Server/Cargo/Systems/PricingSystem.cs
Resources/Prototypes/Entities/Objects/base_item.yml

index 0cb4524cb45fb2a80ec553011fa0db18102d4789..19cedddb00f061cf3119cd2fa67489e37e0412b1 100644 (file)
@@ -3,6 +3,7 @@ using System.Linq;
 using Content.Server.Cargo.Components;
 using Content.Server.Cargo.Systems;
 using Content.Shared.Cargo.Prototypes;
+using Content.Shared.Stacks;
 using NUnit.Framework;
 using Robust.Shared.GameObjects;
 using Robust.Shared.Map;
@@ -82,13 +83,57 @@ public sealed class CargoTest
                     if (entManager.TryGetComponent<StaticPriceComponent>(ent, out var staticpricecomp))
                     {
                         Assert.That(staticpricecomp.Price, Is.EqualTo(0),
-                            $"The prototype {proto} have a StackPriceComponent and StaticPriceComponent whose values are not compatible with each other.");
+                            $"The prototype {proto} has a StackPriceComponent and StaticPriceComponent whose values are not compatible with each other.");
                     }
                 }
+
+                if (entManager.HasComponent<StackComponent>(ent))
+                {
+                    if (entManager.TryGetComponent<StaticPriceComponent>(ent, out var staticpricecomp))
+                    {
+                        Assert.That(staticpricecomp.Price, Is.EqualTo(0),
+                            $"The prototype {proto} has a StackComponent and StaticPriceComponent whose values are not compatible with each other.");
+                    }
+                }
+
                 entManager.DeleteEntity(ent);
             }
             mapManager.DeleteMap(mapId);
         });
         await pairTracker.CleanReturnAsync();
     }
+
+    [Test]
+    public async Task StackPrice()
+    {
+        const string StackProto = @"
+- type: entity
+  id: A
+
+- type: stack
+  id: StackProto
+  spawn: A
+
+- type: entity
+  id: StackEnt
+  components:
+  - type: StackPrice
+    price: 20
+  - type: Stack
+    stackType: StackProto
+    count: 5
+";
+
+        await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = StackProto});
+        var server = pairTracker.Pair.Server;
+
+        var entManager = server.ResolveDependency<IEntityManager>();
+        var priceSystem = entManager.System<PricingSystem>();
+
+        var ent = entManager.SpawnEntity("StackEnt", MapCoordinates.Nullspace);
+        var price = priceSystem.GetPrice(ent);
+        Assert.That(price, Is.EqualTo(100.0));
+
+        await pairTracker.CleanReturnAsync();
+    }
 }
index 17ab0bf376d32fee348407a7b8ab2674ee0da519..6a1125ef36c2ba4cd74bca522bd4468879bdbe05 100644 (file)
@@ -149,8 +149,14 @@ public sealed class PricingSystem : EntitySystem
         var price = ev.Price;
         price += GetMaterialsPrice(prototype);
         price += GetSolutionsPrice(prototype);
+        // Can't use static price with stackprice
+        var oldPrice = price;
         price += GetStackPrice(prototype);
-        price += GetStaticPrice(prototype);
+
+        if (oldPrice.Equals(price))
+        {
+            price += GetStaticPrice(prototype);
+        }
 
         // TODO: Proper container support.
 
@@ -179,8 +185,15 @@ public sealed class PricingSystem : EntitySystem
         // DO NOT FORGET TO UPDATE ESTIMATED PRICING
         price += GetMaterialsPrice(uid);
         price += GetSolutionsPrice(uid);
+
+        // Can't use static price with stackprice
+        var oldPrice = price;
         price += GetStackPrice(uid);
-        price += GetStaticPrice(uid);
+
+        if (oldPrice.Equals(price))
+        {
+            price += GetStaticPrice(uid);
+        }
 
         if (TryComp<ContainerManagerComponent>(uid, out var containers))
         {
index f9b171a7eb81be574d9d8ad2fb9241822f579ebc..e72823220c42af71c9482b8f987b62fe46b9825e 100644 (file)
@@ -5,8 +5,6 @@
   components:
   - type: Item
     size: 5
-  - type: StaticPrice
-    price: 20
   - type: Clickable
   - type: InteractionOutline
   - type: MovedByPressure