Uplink sales (#264)
This commit is contained in:
@@ -159,7 +159,14 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
canBuy = false;
|
canBuy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listing.SaleAmount > 0) // WD
|
||||||
|
listingName += $" [СКИДКА] ({listing.SaleAmount}%!)";
|
||||||
|
|
||||||
var newListing = new StoreListingControl(listingName, listingDesc, listingInStock, canBuy, texture);
|
var newListing = new StoreListingControl(listingName, listingDesc, listingInStock, canBuy, texture);
|
||||||
|
|
||||||
|
if (listing.SaleAmount > 0) // WD
|
||||||
|
newListing.StoreItemBuyButton.AddStyleClass("ButtonColorRed");
|
||||||
|
|
||||||
newListing.StoreItemBuyButton.OnButtonDown += args
|
newListing.StoreItemBuyButton.OnButtonDown += args
|
||||||
=> OnListingButtonPressed?.Invoke(args, listing);
|
=> OnListingButtonPressed?.Invoke(args, listing);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using System.Linq;
|
||||||
using Content.Server.Store.Components;
|
using Content.Server.Store.Components;
|
||||||
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Store;
|
using Content.Shared.Store;
|
||||||
|
|
||||||
namespace Content.Server.Store.Systems;
|
namespace Content.Server.Store.Systems;
|
||||||
@@ -27,7 +29,22 @@ public sealed partial class StoreSystem
|
|||||||
|
|
||||||
foreach (var listing in allListings)
|
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;
|
return allData;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ 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;
|
||||||
|
|
||||||
@@ -21,6 +23,9 @@ 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()
|
||||||
{
|
{
|
||||||
@@ -34,10 +39,45 @@ 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);
|
||||||
|
|||||||
@@ -94,6 +94,13 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
[DataField("restockTime")]
|
[DataField("restockTime")]
|
||||||
public int RestockTime;
|
public int RestockTime;
|
||||||
|
|
||||||
|
// WD START
|
||||||
|
[DataField("saleBlacklist")]
|
||||||
|
public bool SaleBlacklist;
|
||||||
|
|
||||||
|
public int SaleAmount;
|
||||||
|
// WD END
|
||||||
|
|
||||||
public bool Equals(ListingData? listing)
|
public bool Equals(ListingData? listing)
|
||||||
{
|
{
|
||||||
if (listing == null)
|
if (listing == null)
|
||||||
@@ -147,6 +154,10 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
ProductEvent = ProductEvent,
|
ProductEvent = ProductEvent,
|
||||||
PurchaseAmount = PurchaseAmount,
|
PurchaseAmount = PurchaseAmount,
|
||||||
RestockTime = RestockTime,
|
RestockTime = RestockTime,
|
||||||
|
// WD START
|
||||||
|
SaleBlacklist = SaleBlacklist,
|
||||||
|
SaleAmount = SaleAmount,
|
||||||
|
// WD END
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Robust.Shared.Prototypes;
|
|||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
|
using Content.Shared.White.Sales;
|
||||||
|
|
||||||
namespace Content.Shared.Store;
|
namespace Content.Shared.Store;
|
||||||
|
|
||||||
@@ -38,4 +39,7 @@ public sealed partial class StorePresetPrototype : IPrototype
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("currencyWhitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<CurrencyPrototype>))]
|
[DataField("currencyWhitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<CurrencyPrototype>))]
|
||||||
public HashSet<string> CurrencyWhitelist { get; private set; } = new();
|
public HashSet<string> CurrencyWhitelist { get; private set; } = new();
|
||||||
|
|
||||||
|
[DataField("sales")]
|
||||||
|
public SalesSpecifier Sales { get; private set; } = new(); // WD
|
||||||
}
|
}
|
||||||
|
|||||||
38
Content.Shared/White/Sales/SalesSpecifier.cs
Normal file
38
Content.Shared/White/Sales/SalesSpecifier.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
namespace Content.Shared.White.Sales;
|
||||||
|
|
||||||
|
[DataDefinition]
|
||||||
|
public sealed class SalesSpecifier
|
||||||
|
{
|
||||||
|
[DataField("enabled")]
|
||||||
|
public bool Enabled { get; }
|
||||||
|
|
||||||
|
[DataField("minMultiplier")]
|
||||||
|
public float MinMultiplier { get; }
|
||||||
|
|
||||||
|
[DataField("maxMultiplier")]
|
||||||
|
public float MaxMultiplier { get; }
|
||||||
|
|
||||||
|
[DataField("minItems")]
|
||||||
|
public int MinItems { get; }
|
||||||
|
|
||||||
|
[DataField("maxItems")]
|
||||||
|
public int MaxItems { get; }
|
||||||
|
|
||||||
|
[DataField("salesCategory")]
|
||||||
|
public string SalesCategory { get; } = string.Empty;
|
||||||
|
|
||||||
|
public SalesSpecifier()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SalesSpecifier(bool enabled, float minMultiplier, float maxMultiplier, int minItems, int maxItems,
|
||||||
|
string salesCategory)
|
||||||
|
{
|
||||||
|
Enabled = enabled;
|
||||||
|
MinMultiplier = minMultiplier;
|
||||||
|
MaxMultiplier = maxMultiplier;
|
||||||
|
MinItems = minItems;
|
||||||
|
MaxItems = maxItems;
|
||||||
|
SalesCategory = salesCategory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -669,6 +669,7 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
tags:
|
tags:
|
||||||
- NukeOpsUplink
|
- NukeOpsUplink
|
||||||
|
saleBlacklist: true
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkDeathRattle
|
id: UplinkDeathRattle
|
||||||
@@ -854,6 +855,7 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
components:
|
components:
|
||||||
- SurplusBundle
|
- SurplusBundle
|
||||||
|
saleBlacklist: true
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkSuperSurplusBundle
|
id: UplinkSuperSurplusBundle
|
||||||
@@ -873,6 +875,7 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
components:
|
components:
|
||||||
- SurplusBundle
|
- SurplusBundle
|
||||||
|
saleBlacklist: true
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
|
|
||||||
|
|||||||
@@ -13,5 +13,13 @@
|
|||||||
- UplinkJob
|
- UplinkJob
|
||||||
- UplinkArmor
|
- UplinkArmor
|
||||||
- UplinkPointless
|
- UplinkPointless
|
||||||
|
- UplinkSales
|
||||||
currencyWhitelist:
|
currencyWhitelist:
|
||||||
- Telecrystal
|
- Telecrystal
|
||||||
|
sales:
|
||||||
|
enabled: true
|
||||||
|
minMultiplier: 0.01
|
||||||
|
maxMultiplier: 0.99
|
||||||
|
minItems: 5
|
||||||
|
maxItems: 10
|
||||||
|
salesCategory: UplinkSales
|
||||||
|
|||||||
4
Resources/Prototypes/White/store_categories.yml
Normal file
4
Resources/Prototypes/White/store_categories.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
- type: storeCategory
|
||||||
|
id: UplinkSales
|
||||||
|
name: Скидки!
|
||||||
|
priority: 10
|
||||||
Reference in New Issue
Block a user