Skip to content

Commit

Permalink
new listing condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeZer2 committed Jan 4, 2025
1 parent d4cdfcc commit 08e7548
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Content.Client/SS220/Contractor/UI/ContractorPDAMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ui220:SpriteButton Name="WithdrawButton" Margin="0 133 255 0" VerticalAlignment="Top" SetSize="138 35" StyleClasses="ContractorWithdrawButton"/>
<ui220:SpriteButton Name="ContractsButton" Margin="0 218 269 0" VerticalAlignment="Top" MaxSize="138 35" StyleClasses="ContractorContractsButton"/>
<ui220:SpriteButton Name="HubButton" Margin="20 218 0 0" VerticalAlignment="Top" MaxSize="138 35" StyleClasses="ContractorHubButton"/>
<ui220:SpriteButton Name="ExecutionButton" Access="Public" Margin="321 184 0 0" VerticalAlignment="Top" MaxSize="138 40" StyleClasses="ContractorExecutionButton"/>
<ui220:SpriteButton Name="ExecutionButton" Access="Public" Disabled="True" Margin="321 184 0 0" VerticalAlignment="Top" MaxSize="138 40" StyleClasses="ContractorExecutionButton"/>
<ScrollContainer Name="ContractsList" Margin="51 260 50 51" VScrollEnabled="True" HorizontalExpand="True" VerticalExpand="True" HScrollEnabled="False">
<BoxContainer Name="ContractsListPanel" Orientation="Vertical" Access="Public" SeparationOverride="5" HorizontalExpand="True" VerticalExpand="False"/>
<BoxContainer Name="HubPanel" Visible="False" Orientation="Vertical" Access="Public" SeparationOverride="5" HorizontalExpand="True" VerticalExpand="False"/>
Expand Down
38 changes: 30 additions & 8 deletions Content.Server/Store/Conditions/BuyBeforeCondition.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Content.Shared.Store;
using Content.Shared.Store.Components;
using Robust.Shared.Prototypes;
Expand All @@ -6,11 +7,19 @@ namespace Content.Server.Store.Conditions;

public sealed partial class BuyBeforeCondition : ListingCondition
{
//ss220 blocking all listings, if any other listing was bought start
/// <summary>
/// Required listing(s) needed to purchase before this listing is available
/// </summary>
[DataField(required: true)]
public HashSet<ProtoId<ListingPrototype>> Whitelist;
[DataField]
public HashSet<ProtoId<ListingPrototype>>? Whitelist;

/// <summary>
/// If true, block to buy listing if any other listing was bought
/// </summary>
[DataField]
public bool BlacklistAll;
//ss220 blocking all listings, if any other listing was bought end

/// <summary>
/// Listing(s) that if bought, block this purchase, if any.
Expand All @@ -24,7 +33,15 @@ public override bool Condition(ListingConditionArgs args)

var allListings = storeComp.FullListingsCatalog;

var purchasesFound = false;
//ss220 blocking all listings, if any other listing was bought start
if (BlacklistAll)
{
if (allListings.Any(listing => listing.PurchaseAmount > 0))
return false;
}

var purchasesFound = true;
//ss220 blocking all listings, if any other listing was bought end

if (Blacklist != null)
{
Expand All @@ -38,17 +55,22 @@ public override bool Condition(ListingConditionArgs args)
}
}

foreach (var requiredListing in Whitelist)
//ss220 blocking all listings, if any other listing was bought start
if (Whitelist != null)
{
foreach (var listing in allListings)
foreach (var requiredListing in Whitelist)
{
if (listing.ID == requiredListing.Id)
foreach (var listing in allListings)
{
purchasesFound = listing.PurchaseAmount > 0;
break;
if (listing.ID == requiredListing.Id)
{
purchasesFound = listing.PurchaseAmount > 0;
break;
}
}
}
}
//ss220 blocking all listings, if any other listing was bought end

return purchasesFound;
}
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/SS220/Catalog/uplink_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@
conditions:
- !type:ListingLimitedStockCondition
stock: 1
- !type:BuyBeforeCondition #block buy listing, if any other listing was bought
blacklistAll: true
- !type:StoreWhitelistCondition
blacklist:
tags:
Expand Down

0 comments on commit 08e7548

Please sign in to comment.