Fix price calculation of stacks (#12645)

* stackprice is not compatible with static price

* adjust prices

* more price adjust

* staticprice = 0

* add a test
This commit is contained in:
corentt
2022-11-17 14:59:45 +01:00
committed by GitHub
parent 03e8076915
commit 29224f166c
4 changed files with 51 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using Content.Server.Cargo.Components;
using Content.Server.Cargo.Systems; using Content.Server.Cargo.Systems;
using Content.Shared.Cargo.Prototypes; using Content.Shared.Cargo.Prototypes;
using NUnit.Framework; using NUnit.Framework;
@@ -41,4 +43,43 @@ public sealed class CargoTest
await pairTracker.CleanReturnAsync(); await pairTracker.CleanReturnAsync();
} }
[Test]
public async Task NoStaticPriceAndStackPrice()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true});
var server = pairTracker.Pair.Server;
var entManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var coord = new EntityCoordinates(grid.GridEntityId, 0, 0);
var protoIds = protoManager.EnumeratePrototypes<EntityPrototype>()
.Where(p=>!p.Abstract)
.Select(p => p.ID)
.ToList();
foreach (var proto in protoIds)
{
var ent = entManager.SpawnEntity(proto, coord);
if (entManager.TryGetComponent<StackPriceComponent>(ent, out var stackpricecomp)
&& stackpricecomp.Price > 0)
{
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.");
}
entManager.DeleteEntity(ent);
}
mapManager.DeleteMap(mapId);
});
await pairTracker.CleanReturnAsync();
}
} }

View File

@@ -4,7 +4,7 @@
sprite: Objects/Tools/cable-coils.rsi sprite: Objects/Tools/cable-coils.rsi
state: coillv-30 state: coillv-30
product: CrateEngineeringCableLV product: CrateEngineeringCableLV
cost: 300 cost: 600
category: Engineering category: Engineering
group: market group: market
@@ -14,7 +14,7 @@
sprite: Objects/Tools/cable-coils.rsi sprite: Objects/Tools/cable-coils.rsi
state: coilmv-30 state: coilmv-30
product: CrateEngineeringCableMV product: CrateEngineeringCableMV
cost: 300 cost: 600
category: Engineering category: Engineering
group: market group: market
@@ -24,7 +24,7 @@
sprite: Objects/Tools/cable-coils.rsi sprite: Objects/Tools/cable-coils.rsi
state: coilhv-30 state: coilhv-30
product: CrateEngineeringCableHV product: CrateEngineeringCableHV
cost: 300 cost: 600
category: Engineering category: Engineering
group: market group: market
@@ -34,7 +34,7 @@
sprite: Objects/Tools/cable-coils.rsi sprite: Objects/Tools/cable-coils.rsi
state: coilall-30 state: coilall-30
product: CrateEngineeringCableBulk product: CrateEngineeringCableBulk
cost: 500 cost: 1200
category: Engineering category: Engineering
group: market group: market
@@ -66,4 +66,4 @@
product: CrateEngineeringMiniJetpack product: CrateEngineeringMiniJetpack
cost: 750 cost: 750
category: Engineering category: Engineering
group: market group: market

View File

@@ -14,6 +14,8 @@
- type: Stack - type: Stack
count: 20 count: 20
stackType: Telecrystal stackType: Telecrystal
- type: StaticPrice
price: 0
- type: StackPrice - type: StackPrice
price: 200 price: 200
- type: Currency - type: Currency

View File

@@ -22,8 +22,10 @@
sprite: Objects/Tools/cable-coils.rsi sprite: Objects/Tools/cable-coils.rsi
- type: CablePlacer - type: CablePlacer
- type: Clickable - type: Clickable
- type: StaticPrice
price: 0
- type: StackPrice - type: StackPrice
price: 0.5 price: 5
- type: entity - type: entity
id: CableHVStack id: CableHVStack