Uplink sales (#264)

This commit is contained in:
Aviu00
2023-08-04 03:44:17 +03:00
committed by Aviu00
parent eb17c43514
commit b34ade60d8
9 changed files with 133 additions and 1 deletions

View File

@@ -1,4 +1,6 @@
using System.Linq;
using Content.Server.Store.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Store;
namespace Content.Server.Store.Systems;
@@ -27,7 +29,22 @@ public sealed partial class StoreSystem
foreach (var listing in allListings)
{
allData.Add((ListingData) listing.Clone());
// WD EDIT
var listingData = (ListingData) listing.Clone();
if (_sales.TryGetValue(listing, out var sale))
{
var newCost = listing.Cost.ToDictionary(x => x.Key,
x => FixedPoint2.New(Math.Max(1, (int) MathF.Round(x.Value.Float() * sale.Item1))));
if (listing.Cost.Any(x => x.Value.Int() != newCost[x.Key].Int()))
{
listingData.Cost = newCost;
listingData.SaleAmount = 100 - (int) MathF.Round(sale.Item1 * 100);
listingData.Categories = new() {sale.Item2};
}
}
allData.Add(listingData);
// WD EDIT END
}
return allData;