From 25b2be3ffe2b32122ad0153982297c5ecf561d14 Mon Sep 17 00:00:00 2001
From: Kistras <81854722+Kistras@users.noreply.github.com>
Date: Fri, 25 Aug 2023 08:17:01 +0500
Subject: [PATCH] Research director should be able to buy science-related items
in uplink (#18986)
---
.../Conditions/BuyerDepartmentCondition.cs | 76 +++++++++++++++++++
.../Prototypes/Catalog/uplink_catalog.yml | 8 +-
2 files changed, 80 insertions(+), 4 deletions(-)
create mode 100644 Content.Server/Store/Conditions/BuyerDepartmentCondition.cs
diff --git a/Content.Server/Store/Conditions/BuyerDepartmentCondition.cs b/Content.Server/Store/Conditions/BuyerDepartmentCondition.cs
new file mode 100644
index 0000000000..788764ce95
--- /dev/null
+++ b/Content.Server/Store/Conditions/BuyerDepartmentCondition.cs
@@ -0,0 +1,76 @@
+using Content.Server.Mind.Components;
+using Content.Server.Roles;
+using Content.Shared.Roles;
+using Content.Shared.Store;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Store.Conditions;
+
+///
+/// Allows a store entry to be filtered out based on the user's job.
+/// Supports both blacklists and whitelists
+///
+public sealed class BuyerDepartmentCondition : ListingCondition
+{
+ ///
+ /// A whitelist of department prototypes that can purchase this listing. Only one needs to be found.
+ ///
+ [DataField("whitelist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
+ public HashSet? Whitelist;
+
+ ///
+ /// A blacklist of department prototypes that can purchase this listing. Only one needs to be found.
+ ///
+ [DataField("blacklist", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
+ public HashSet? Blacklist;
+
+ public override bool Condition(ListingConditionArgs args)
+ {
+ var prototypeManager = IoCManager.Resolve();
+
+ var ent = args.EntityManager;
+
+ if (!ent.TryGetComponent(args.Buyer, out var mind) || mind.Mind == null)
+ return true; //this is for things like surplus crate
+
+ if (Blacklist != null)
+ {
+ foreach (var role in mind.Mind.AllRoles)
+ {
+ if (role is not Job job)
+ continue;
+
+ foreach (var department in prototypeManager.EnumeratePrototypes())
+ if (department.Roles.Contains(job.Prototype.ID))
+ if (Blacklist.Contains(department.ID))
+ return false;
+ }
+ }
+
+ if (Whitelist != null)
+ {
+ var found = false;
+ foreach (var role in mind.Mind.AllRoles)
+ {
+ if (role is not Job job)
+ continue;
+
+ foreach (var department in prototypeManager.EnumeratePrototypes())
+ if (department.Roles.Contains(job.Prototype.ID))
+ if (Whitelist.Contains(department.ID))
+ {
+ found = true;
+ break;
+ }
+
+ if (found)
+ break;
+ }
+ if (!found)
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/Resources/Prototypes/Catalog/uplink_catalog.yml b/Resources/Prototypes/Catalog/uplink_catalog.yml
index 7ebf25eb93..cf41fd903d 100644
--- a/Resources/Prototypes/Catalog/uplink_catalog.yml
+++ b/Resources/Prototypes/Catalog/uplink_catalog.yml
@@ -965,10 +965,9 @@
categories:
- UplinkJob
conditions:
- - !type:BuyerJobCondition
+ - !type:BuyerDepartmentCondition
whitelist:
- - Scientist
- - SeniorResearcher
+ - Science
- type: listing
id: uplinkProximityMine
@@ -999,11 +998,12 @@
categories:
- UplinkJob
conditions:
- - !type:BuyerJobCondition
+ - !type:BuyerJobCondition # We can't use BuyerDepartmentCondition here since Zookeeper and Chef can also get this
whitelist:
- Zookeeper
- Scientist
- SeniorResearcher
+ - ResearchDirector
- Chef
# Armor