]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
add πŸ‘· JobCondition system for reagents (#29023)
authoricekot8 <93311212+icekot8@users.noreply.github.com>
Sat, 15 Jun 2024 21:36:25 +0000 (00:36 +0300)
committerGitHub <noreply@github.com>
Sat, 15 Jun 2024 21:36:25 +0000 (17:36 -0400)
* hell :skull:

* you're right

i'm dumb

* use the beautiful protoid and or in localization :cut_of_meat:

* :pray:

Content.Server/Chemistry/ReagentEffectConditions/JobCondition.cs [new file with mode: 0644]
Content.Shared/Localizations/ContentLocalizationManager.cs
Resources/Locale/en-US/guidebook/chemistry/conditions.ftl

diff --git a/Content.Server/Chemistry/ReagentEffectConditions/JobCondition.cs b/Content.Server/Chemistry/ReagentEffectConditions/JobCondition.cs
new file mode 100644 (file)
index 0000000..0ede690
--- /dev/null
@@ -0,0 +1,49 @@
+using System.Linq;
+using Content.Shared.Chemistry.Reagent;
+using Content.Shared.Mobs;
+using Content.Shared.Mobs.Components;
+using Content.Shared.Localizations;
+using Robust.Shared.Prototypes;
+using Content.Shared.Mind;
+using Content.Shared.Mind.Components;
+using Content.Shared.Roles;
+using Content.Shared.Roles.Jobs;
+using Content.Shared.Station;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
+using Robust.Shared.IoC;
+
+namespace Content.Server.Chemistry.ReagentEffectConditions
+{    
+    public sealed partial class JobCondition : ReagentEffectCondition
+    {
+        [DataField(required: true)] public List<ProtoId<JobPrototype>> Job;
+                
+        public override bool Condition(ReagentEffectArgs args)
+        {   
+            args.EntityManager.TryGetComponent<MindContainerComponent>(args.SolutionEntity, out var mindContainer);
+            if (mindContainer != null && mindContainer.Mind != null)
+            {
+                var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
+                if (args.EntityManager.TryGetComponent<JobComponent>(mindContainer?.Mind, out var comp) && prototypeManager.TryIndex(comp.Prototype, out var prototype))
+                {
+                    foreach (var jobId in Job)
+                    {
+                        if (prototype.ID == jobId)
+                        {
+                            return true;
+                        }
+                    }
+                }
+            }
+            
+            return false;
+        }
+        
+        public override string GuidebookExplanation(IPrototypeManager prototype)
+        {
+            var localizedNames = Job.Select(jobId => prototype.Index(jobId).LocalizedName).ToList();
+            return Loc.GetString("reagent-effect-condition-guidebook-job-condition", ("job", ContentLocalizationManager.FormatListToOr(localizedNames)));
+        }
+    }
+}
+
index 7d40182f6cc896fd142acdb81b321f63ec286c83..ad8890ae0fdb04a313b80bf8c9509c2f943db256 100644 (file)
@@ -1,4 +1,4 @@
-ο»Ώusing System.Globalization;
+using System.Globalization;
 using System.Linq;
 using System.Text.RegularExpressions;
 using Robust.Shared.Utility;
@@ -119,6 +119,20 @@ namespace Content.Shared.Localizations
             };
         }
 
+        /// <summary>
+        /// Formats a list as per english grammar rules, but uses or instead of and.
+        /// </summary>
+        public static string FormatListToOr(List<string> list)
+        {
+            return list.Count switch
+            {
+                <= 0 => string.Empty,
+                1 => list[0],
+                2 => $"{list[0]} or {list[1]}",
+                _ => $"{string.Join(" or ", list)}"
+            };
+        }
+
         /// <summary>
         /// Formats a direction struct as a human-readable string.
         /// </summary>
index 6cbfc13a797433b013c91964d6a145b4639308d7..95aaf9126d7e0556f995e1f979b26570eda3f9c0 100644 (file)
@@ -28,6 +28,9 @@ reagent-effect-condition-guidebook-reagent-threshold =
 reagent-effect-condition-guidebook-mob-state-condition =
     the mob is { $state }
 
+reagent-effect-condition-guidebook-job-condition =
+    the target's job is { $job }
+
 reagent-effect-condition-guidebook-solution-temperature =
     the solution's temperature is { $max ->
             [2147483648] at least {NATURALFIXED($min, 2)}k