-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port] Uplink Discounts From White Dream (#930)
# Description This is a port of WWhiteDreamProject/wwdpublic#11 from White Dream. This feature selects random items in the traitor uplink each round to be discounted and moved to the Discount tab, which are the same for every traitor. This in theory helps encourage players to be spontaneous, and use items that they otherwise might not normally consider using, which helps mix things up from round to round. <details><summary><h1>Media</h1></summary> <p> > # Описание PR > Порт скидок в аплинке. > > # Изменения > 🆑 Spatison > > * add: Added discounts in uplink / Добавлены скидки в аплинк </p> </details> # Changelog :cl: Spatison add: Added discounts in uplink / Добавлены скидки в аплинк --------- Signed-off-by: VMSolidus <[email protected]> Co-authored-by: Spatison <[email protected]> Co-authored-by: DEATHB4DEFEAT <[email protected]>
- Loading branch information
1 parent
49d128c
commit f126bb4
Showing
13 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Linq; | ||
using Content.Shared.FixedPoint; | ||
using Content.Shared.Store; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server.StoreDiscount; | ||
|
||
public sealed class StoreDiscountSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
|
||
public void ApplyDiscounts(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(ChangedFormatCategories(l.Categories))) | ||
.OrderBy(_ => _random.Next()).Take(count).ToList(); | ||
|
||
foreach (var listing in listings) | ||
{ | ||
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)))); | ||
|
||
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.DiscountValue = 100 - (newCost[key] / listing.Cost[key] * 100).Int(); | ||
listing.Cost = newCost; | ||
listing.Categories = new() {store.Sales.SalesCategory}; | ||
} | ||
} | ||
|
||
private IEnumerable<string> ChangedFormatCategories(List<ProtoId<StoreCategoryPrototype>> categories) | ||
{ | ||
var modified = from p in categories select p.Id; | ||
|
||
return modified; | ||
} | ||
|
||
private float GetDiscount(float minMultiplier, float maxMultiplier) | ||
{ | ||
return _random.NextFloat() * (maxMultiplier - minMultiplier) + minMultiplier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Content.Shared.StoreDiscount; | ||
|
||
[DataDefinition] | ||
public sealed partial class SalesSpecifier | ||
{ | ||
[DataField] | ||
public bool Enabled { get; private set; } | ||
|
||
[DataField] | ||
public float MinMultiplier { get; private set; } | ||
|
||
[DataField] | ||
public float MaxMultiplier { get; private set; } | ||
|
||
[DataField] | ||
public int MinItems { get; private set; } | ||
|
||
[DataField] | ||
public int MaxItems { get; private set; } | ||
|
||
[DataField] | ||
public string SalesCategory { get; private set; } = 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
store-sales-amount = [DISCOUNT] { $amount }%! | ||
store-sales-over = [The sale is over] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
store-sales-amount = [СКИДКА] { $amount }%! | ||
store-sales-over = [Скидка закончилась] |
Oops, something went wrong.