mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using Content.Shared.Store;
|
|
using Content.Shared.Store.Components;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Store.Conditions;
|
|
|
|
public sealed partial class BuyBeforeCondition : ListingCondition
|
|
{
|
|
/// <summary>
|
|
/// Required listing(s) needed to purchase before this listing is available
|
|
/// </summary>
|
|
[DataField]
|
|
public HashSet<ProtoId<ListingPrototype>>? Whitelist;
|
|
|
|
/// <summary>
|
|
/// Listing(s) that if bought, block this purchase, if any.
|
|
/// </summary>
|
|
[DataField]
|
|
public HashSet<ProtoId<ListingPrototype>>? Blacklist;
|
|
|
|
public override bool Condition(ListingConditionArgs args)
|
|
{
|
|
if (!args.EntityManager.TryGetComponent<StoreComponent>(args.StoreEntity, out var storeComp))
|
|
return false;
|
|
|
|
var allListings = storeComp.FullListingsCatalog;
|
|
|
|
var purchasesFound = false;
|
|
|
|
if (Blacklist != null)
|
|
{
|
|
foreach (var blacklistListing in Blacklist)
|
|
{
|
|
foreach (var listing in allListings)
|
|
{
|
|
if (listing.ID == blacklistListing.Id && listing.PurchaseAmount > 0)
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Whitelist != null)
|
|
{
|
|
foreach (var requiredListing in Whitelist)
|
|
{
|
|
foreach (var listing in allListings)
|
|
{
|
|
if (listing.ID == requiredListing.Id)
|
|
{
|
|
purchasesFound = listing.PurchaseAmount > 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return purchasesFound;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|