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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
components:
|
||||
- type: Item
|
||||
size: 5
|
||||
- type: StaticPrice
|
||||
price: 20
|
||||
- type: Clickable
|
||||
- type: InteractionOutline
|
||||
- type: MovedByPressure
|
||||
|
||||
Reference in New Issue
Block a user