Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
Spatison committed Aug 23, 2024
1 parent 7b4801d commit eec5fa2
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Store/Ui/StoreMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void AddListingGui(ListingData listing)

var newListing = new StoreListingControl(listing, GetListingPriceString(listing), hasBalance, texture);

if (listing.SaleAmount > 0) // WD EDIT
if (listing.DiscountValue > 0) // WD EDIT
newListing.StoreItemBuyButton.AddStyleClass("ButtonColorRed");

newListing.StoreItemBuyButton.OnButtonDown += args
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Store/Systems/StoreSystem.Ui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ private void OnBuyRequest(EntityUid uid, StoreComponent component, StoreBuyListi
_audio.PlayEntity(component.BuySuccessSound, msg.Session, uid); //cha-ching!

//WD EDIT START
if (listing.SaleLimit != 0 && listing.SaleAmount > 0 && listing.PurchaseAmount >= listing.SaleLimit)
if (listing.SaleLimit != 0 && listing.DiscountValue > 0 && listing.PurchaseAmount >= listing.SaleLimit)
{
listing.SaleAmount = 0;
listing.DiscountValue = 0;
listing.Cost = listing.OldCost;
}
//WD EDIT END
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Store/Systems/StoreSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void InitializeFromPreset(StorePresetPrototype preset, EntityUid uid, Sto
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);

_storeDiscount.ApplySales(component.Listings, preset); // WD EDIT
_storeDiscount.ApplyDiscounts(component.Listings, preset); // WD EDIT

var ui = _ui.GetUiOrNull(uid, StoreUiKey.Key);
if (ui != null)
Expand Down
8 changes: 4 additions & 4 deletions Content.Server/_White/StoreDiscount/StoreDiscountSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class StoreDiscountSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;

public void ApplySales(IEnumerable<ListingData> listings, StorePresetPrototype store)
public void ApplyDiscounts(IEnumerable<ListingData> listings, StorePresetPrototype store)
{
if (!store.Sales.Enabled)
return;
Expand All @@ -24,7 +24,7 @@ public void ApplySales(IEnumerable<ListingData> listings, StorePresetPrototype s

foreach (var listing in listings)
{
var sale = GetSale(store.Sales.MinMultiplier, store.Sales.MaxMultiplier);
var sale = GetDiscount(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))));

Expand All @@ -33,7 +33,7 @@ public void ApplySales(IEnumerable<ListingData> listings, StorePresetPrototype s

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.DiscountValue = 100 - (newCost[key] / listing.Cost[key] * 100).Int();
listing.Cost = newCost;
listing.Categories = new() {store.Sales.SalesCategory};
}
Expand All @@ -46,7 +46,7 @@ private IEnumerable<string> ChangedFormatCategories(List<ProtoId<StoreCategoryPr
return modified;
}

private float GetSale(float minMultiplier, float maxMultiplier)
private float GetDiscount(float minMultiplier, float maxMultiplier)
{
return _random.NextFloat() * (maxMultiplier - minMultiplier) + minMultiplier;
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Store/ListingLocalisationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static string GetLocalisedNameOrEntityName(ListingData listingData, IProt
name = prototypeManager.Index(listingData.ProductEntity.Value).Name;

// WD START
if (listingData.SaleAmount > 0)
name += " " + Loc.GetString("store-sales-amount", ("amount", listingData.SaleAmount));
if (listingData.DiscountValue > 0)
name += " " + Loc.GetString("store-sales-amount", ("amount", listingData.DiscountValue));
else if (listingData.OldCost.Count > 0)
name += " " + Loc.GetString("store-sales-over");
// WD END
Expand Down
8 changes: 4 additions & 4 deletions Content.Shared/Store/ListingPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
public TimeSpan RestockTime = TimeSpan.Zero;

// WD START
[DataField("saleLimit")]
[DataField]
public int SaleLimit = 3;

[DataField("saleBlacklist")]
[DataField]
public bool SaleBlacklist;

public int SaleAmount;
public int DiscountValue;

public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> OldCost = new();

Expand Down Expand Up @@ -184,7 +184,7 @@ public object Clone()
// WD START
SaleLimit = SaleLimit,
SaleBlacklist = SaleBlacklist,
SaleAmount = SaleAmount,
DiscountValue = DiscountValue,
OldCost = OldCost,
Components = Components,
// WD END
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Store/StorePresetPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed partial class StorePresetPrototype : IPrototype
public HashSet<string> CurrencyWhitelist { get; private set; } = new();

// WD EDIT START
[DataField("sales")]
[DataField]
public SalesSpecifier Sales { get; private set; } = new();
// WD EDIT END
}
12 changes: 6 additions & 6 deletions Content.Shared/_White/StoreDiscount/SalesSpecifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ namespace Content.Shared._White.StoreDiscount;
[DataDefinition]
public sealed partial class SalesSpecifier
{
[DataField("enabled")]
[DataField]
public bool Enabled { get; private set; }

[DataField("minMultiplier")]
[DataField]
public float MinMultiplier { get; private set; }

[DataField("maxMultiplier")]
[DataField]
public float MaxMultiplier { get; private set; }

[DataField("minItems")]
[DataField]
public int MinItems { get; private set; }

[DataField("maxItems")]
[DataField]
public int MaxItems { get; private set; }

[DataField("salesCategory")]
[DataField]
public string SalesCategory { get; private set; } = string.Empty;

public SalesSpecifier()
Expand Down
2 changes: 1 addition & 1 deletion Resources/Locale/en-US/_white/store/sales.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
store-sales-amount = [SALE] { $amount }%!
store-sales-amount = [DISCOUNT] { $amount }%!
store-sales-over = [The sale is over]
4 changes: 2 additions & 2 deletions Resources/Prototypes/Store/presets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
- Telecrystal
sales: # WD EDIT
enabled: true
minMultiplier: 0.01
maxMultiplier: 0.99
minMultiplier: 0.2
maxMultiplier: 0.8
minItems: 3
maxItems: 8
salesCategory: UplinkSales

0 comments on commit eec5fa2

Please sign in to comment.