From a8130f177f069483664ddd5da2c3b3e1137c6f9e Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 27 Mar 2023 04:01:42 +1100 Subject: [PATCH] Fix static pricing for stacks (#14865) 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 | 47 ++++++++++++++++++- Content.Server/Cargo/Systems/PricingSystem.cs | 17 ++++++- .../Prototypes/Entities/Objects/base_item.yml | 2 - 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/Content.IntegrationTests/Tests/CargoTest.cs b/Content.IntegrationTests/Tests/CargoTest.cs index 0cb4524cb4..19cedddb00 100644 --- a/Content.IntegrationTests/Tests/CargoTest.cs +++ b/Content.IntegrationTests/Tests/CargoTest.cs @@ -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(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(ent)) + { + if (entManager.TryGetComponent(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(); + var priceSystem = entManager.System(); + + var ent = entManager.SpawnEntity("StackEnt", MapCoordinates.Nullspace); + var price = priceSystem.GetPrice(ent); + Assert.That(price, Is.EqualTo(100.0)); + + await pairTracker.CleanReturnAsync(); + } } diff --git a/Content.Server/Cargo/Systems/PricingSystem.cs b/Content.Server/Cargo/Systems/PricingSystem.cs index 17ab0bf376..6a1125ef36 100644 --- a/Content.Server/Cargo/Systems/PricingSystem.cs +++ b/Content.Server/Cargo/Systems/PricingSystem.cs @@ -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(uid, out var containers)) { diff --git a/Resources/Prototypes/Entities/Objects/base_item.yml b/Resources/Prototypes/Entities/Objects/base_item.yml index f9b171a7eb..e72823220c 100644 --- a/Resources/Prototypes/Entities/Objects/base_item.yml +++ b/Resources/Prototypes/Entities/Objects/base_item.yml @@ -5,8 +5,6 @@ components: - type: Item size: 5 - - type: StaticPrice - price: 20 - type: Clickable - type: InteractionOutline - type: MovedByPressure -- 2.51.2