@@ -2,11 +2,49 @@ using System.Linq;
|
|||||||
using Content.Server.Store.Components;
|
using Content.Server.Store.Components;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Store;
|
using Content.Shared.Store;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
namespace Content.Server.Store.Systems;
|
namespace Content.Server.Store.Systems;
|
||||||
|
|
||||||
public sealed partial class StoreSystem
|
public sealed partial class StoreSystem
|
||||||
{
|
{
|
||||||
|
// WD START
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!; // WD
|
||||||
|
|
||||||
|
private void ApplySales(IEnumerable<ListingData> listings, StorePresetPrototype store)
|
||||||
|
{
|
||||||
|
if (!store.Sales.Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var count = _random.Next(store.Sales.MinItems, store.Sales.MaxItems + 1);
|
||||||
|
|
||||||
|
listings = listings
|
||||||
|
.Where(l => !l.SaleBlacklist && l.Cost.Any(x => x.Value > 1) && store.Categories.Overlaps(l.Categories))
|
||||||
|
.OrderBy(_ => _random.Next()).Take(count).ToList();
|
||||||
|
|
||||||
|
foreach (var listing in listings)
|
||||||
|
{
|
||||||
|
var sale = GetSale(store.Sales.MinMultiplier, store.Sales.MaxMultiplier);
|
||||||
|
var newCost = listing.Cost.ToDictionary(x => x.Key,
|
||||||
|
x => FixedPoint2.New(Math.Max(1, (int) MathF.Round(x.Value.Float() * sale))));
|
||||||
|
|
||||||
|
if (listing.Cost.All(x => x.Value.Int() == newCost[x.Key].Int()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var key = listing.Cost.First(x => x.Value > 0).Key;
|
||||||
|
listing.OldCost = listing.Cost;
|
||||||
|
listing.SaleAmount = 100 - (newCost[key] / listing.Cost[key] * 100).Int();
|
||||||
|
listing.Cost = newCost;
|
||||||
|
listing.Categories = new() {store.Sales.SalesCategory};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float GetSale(float minMultiplier, float maxMultiplier)
|
||||||
|
{
|
||||||
|
return _random.NextFloat() * (maxMultiplier - minMultiplier) + minMultiplier;
|
||||||
|
}
|
||||||
|
// WD END
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Refreshes all listings on a store.
|
/// Refreshes all listings on a store.
|
||||||
/// Do not use if you don't know what you're doing.
|
/// Do not use if you don't know what you're doing.
|
||||||
@@ -29,24 +67,7 @@ public sealed partial class StoreSystem
|
|||||||
|
|
||||||
foreach (var listing in allListings)
|
foreach (var listing in allListings)
|
||||||
{
|
{
|
||||||
// WD EDIT
|
allData.Add((ListingData) listing.Clone());
|
||||||
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()))
|
|
||||||
{
|
|
||||||
var key = listing.Cost.First(x => x.Value > 0).Key;
|
|
||||||
listingData.OldCost = listing.Cost;
|
|
||||||
listingData.SaleAmount = 100 - (newCost[key] / listing.Cost[key] * 100).Int();
|
|
||||||
listingData.Cost = newCost;
|
|
||||||
listingData.Categories = new() {sale.Item2};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
allData.Add(listingData);
|
|
||||||
// WD EDIT END
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return allData;
|
return allData;
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ using JetBrains.Annotations;
|
|||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.GameTicking.Events;
|
|
||||||
using Robust.Shared.Random;
|
|
||||||
|
|
||||||
namespace Content.Server.Store.Systems;
|
namespace Content.Server.Store.Systems;
|
||||||
|
|
||||||
@@ -23,9 +21,6 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!; // WD
|
|
||||||
|
|
||||||
private Dictionary<ListingPrototype, (float, string)> _sales = new(); // WD
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -39,45 +34,10 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<StoreComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<StoreComponent, ComponentShutdown>(OnShutdown);
|
||||||
SubscribeLocalEvent<StoreComponent, OpenUplinkImplantEvent>(OnImplantActivate);
|
SubscribeLocalEvent<StoreComponent, OpenUplinkImplantEvent>(OnImplantActivate);
|
||||||
|
|
||||||
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart); // WD
|
|
||||||
|
|
||||||
InitializeUi();
|
InitializeUi();
|
||||||
InitializeCommand();
|
InitializeCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
// WD START
|
|
||||||
private void OnRoundStart(RoundStartingEvent ev)
|
|
||||||
{
|
|
||||||
CalculateSales();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CalculateSales()
|
|
||||||
{
|
|
||||||
_sales.Clear();
|
|
||||||
foreach (var store in _proto.EnumeratePrototypes<StorePresetPrototype>())
|
|
||||||
{
|
|
||||||
if (!store.Sales.Enabled)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var count = _random.Next(store.Sales.MinItems, store.Sales.MaxItems + 1);
|
|
||||||
|
|
||||||
var storeListings = _proto.EnumeratePrototypes<ListingPrototype>()
|
|
||||||
.Where(l => !l.SaleBlacklist && l.Cost.Any(x => x.Value > 1) && !_sales.ContainsKey(l) &&
|
|
||||||
store.Categories.Overlaps(l.Categories)).OrderBy(_ => _random.Next()).Take(count)
|
|
||||||
.ToDictionary(l => l,
|
|
||||||
_ => (GetSale(store.Sales.MinMultiplier, store.Sales.MaxMultiplier), store.Sales.SalesCategory));
|
|
||||||
|
|
||||||
_sales = _sales.Concat(storeListings).ToDictionary(x => x.Key, x => x.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private float GetSale(float minMultiplier, float maxMultiplier)
|
|
||||||
{
|
|
||||||
return _random.NextFloat() * (maxMultiplier - minMultiplier) + minMultiplier;
|
|
||||||
}
|
|
||||||
// WD END
|
|
||||||
|
|
||||||
|
|
||||||
private void OnMapInit(EntityUid uid, StoreComponent component, MapInitEvent args)
|
private void OnMapInit(EntityUid uid, StoreComponent component, MapInitEvent args)
|
||||||
{
|
{
|
||||||
RefreshAllListings(component);
|
RefreshAllListings(component);
|
||||||
@@ -220,6 +180,8 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
if (component.Balance == new Dictionary<string, FixedPoint2>() && preset.InitialBalance != null) //if we don't have a value stored, use the preset
|
if (component.Balance == new Dictionary<string, FixedPoint2>() && preset.InitialBalance != null) //if we don't have a value stored, use the preset
|
||||||
TryAddCurrency(preset.InitialBalance, uid, component);
|
TryAddCurrency(preset.InitialBalance, uid, component);
|
||||||
|
|
||||||
|
ApplySales(component.Listings, preset); // WD
|
||||||
|
|
||||||
var ui = _ui.GetUiOrNull(uid, StoreUiKey.Key);
|
var ui = _ui.GetUiOrNull(uid, StoreUiKey.Key);
|
||||||
if (ui != null)
|
if (ui != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
|
|
||||||
// WD START
|
// WD START
|
||||||
[DataField("saleLimit")]
|
[DataField("saleLimit")]
|
||||||
public int SaleLimit = 5;
|
public int SaleLimit = 3;
|
||||||
|
|
||||||
[DataField("saleBlacklist")]
|
[DataField("saleBlacklist")]
|
||||||
public bool SaleBlacklist;
|
public bool SaleBlacklist;
|
||||||
|
|||||||
@@ -135,7 +135,6 @@
|
|||||||
Telecrystal: 4
|
Telecrystal: 4
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkExplosiveGrenadeFlash
|
id: UplinkExplosiveGrenadeFlash
|
||||||
@@ -146,7 +145,6 @@
|
|||||||
Telecrystal: 1
|
Telecrystal: 1
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkSmokeGrenade
|
id: UplinkSmokeGrenade
|
||||||
@@ -167,7 +165,6 @@
|
|||||||
Telecrystal: 6
|
Telecrystal: 6
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkSupermatterGrenade
|
id: UplinkSupermatterGrenade
|
||||||
@@ -203,7 +200,6 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
components:
|
components:
|
||||||
- SurplusBundle
|
- SurplusBundle
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkC4
|
id: UplinkC4
|
||||||
@@ -214,7 +210,6 @@
|
|||||||
Telecrystal: 2
|
Telecrystal: 2
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkGrenadierRig
|
id: UplinkGrenadierRig
|
||||||
@@ -252,7 +247,6 @@
|
|||||||
Telecrystal: 2
|
Telecrystal: 2
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkExplodingPen
|
id: UplinkExplodingPen
|
||||||
@@ -264,7 +258,6 @@
|
|||||||
Telecrystal: 5
|
Telecrystal: 5
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkSyndicateBomb
|
id: UplinkSyndicateBomb
|
||||||
@@ -276,6 +269,7 @@
|
|||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
restockTime: 30
|
restockTime: 30
|
||||||
|
saleLimit: 1
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkClusterGrenade
|
id: UplinkClusterGrenade
|
||||||
@@ -400,6 +394,7 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
tags:
|
tags:
|
||||||
- NukeOpsUplink
|
- NukeOpsUplink
|
||||||
|
saleLimit: 1
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkHolster
|
id: UplinkHolster
|
||||||
@@ -485,7 +480,6 @@
|
|||||||
Telecrystal: 8
|
Telecrystal: 8
|
||||||
categories:
|
categories:
|
||||||
- UplinkUtility
|
- UplinkUtility
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkStealthBox
|
id: UplinkStealthBox
|
||||||
@@ -1053,7 +1047,6 @@
|
|||||||
- !type:BuyerJobCondition
|
- !type:BuyerJobCondition
|
||||||
whitelist:
|
whitelist:
|
||||||
- Chaplain
|
- Chaplain
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: uplinkRevolverCapGunFake
|
id: uplinkRevolverCapGunFake
|
||||||
@@ -1085,7 +1078,6 @@
|
|||||||
- !type:BuyerJobCondition
|
- !type:BuyerJobCondition
|
||||||
whitelist:
|
whitelist:
|
||||||
- Clown
|
- Clown
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkClusterBananaPeel
|
id: UplinkClusterBananaPeel
|
||||||
@@ -1132,7 +1124,6 @@
|
|||||||
- Botanist
|
- Botanist
|
||||||
- Clown
|
- Clown
|
||||||
- Mime
|
- Mime
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkChimpUpgradeKit
|
id: UplinkChimpUpgradeKit
|
||||||
@@ -1165,7 +1156,6 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
components:
|
components:
|
||||||
- SurplusBundle
|
- SurplusBundle
|
||||||
saleLimit: 3
|
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkSyndicateSpongeBox
|
id: UplinkSyndicateSpongeBox
|
||||||
@@ -1195,6 +1185,7 @@
|
|||||||
Telecrystal: 12
|
Telecrystal: 12
|
||||||
categories:
|
categories:
|
||||||
- UplinkUtility
|
- UplinkUtility
|
||||||
|
saleLimit: 1
|
||||||
|
|
||||||
# Armor
|
# Armor
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,6 @@
|
|||||||
enabled: true
|
enabled: true
|
||||||
minMultiplier: 0.01
|
minMultiplier: 0.01
|
||||||
maxMultiplier: 0.99
|
maxMultiplier: 0.99
|
||||||
minItems: 5
|
minItems: 3
|
||||||
maxItems: 10
|
maxItems: 8
|
||||||
salesCategory: UplinkSales
|
salesCategory: UplinkSales
|
||||||
|
|||||||
Reference in New Issue
Block a user