]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add strange pills, RandomFillSolutionComponent (#15067)
authorMisterMecky <mrmecky@hotmail.com>
Mon, 1 May 2023 14:43:31 +0000 (22:43 +0800)
committerGitHub <noreply@github.com>
Mon, 1 May 2023 14:43:31 +0000 (00:43 +1000)
Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs [new file with mode: 0644]
Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs [new file with mode: 0644]
Resources/Prototypes/Catalog/Fills/Lockers/misc.yml
Resources/Prototypes/Entities/Objects/Specific/Medical/randompill.yml [new file with mode: 0644]

diff --git a/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs b/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs
new file mode 100644 (file)
index 0000000..bf75df0
--- /dev/null
@@ -0,0 +1,31 @@
+using Content.Server.Chemistry.EntitySystems;
+using Content.Shared.FixedPoint;
+using Content.Shared.Random;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
+
+namespace Content.Server.Chemistry.Components.SolutionManager;
+
+/// <summary>
+///     Fills a solution container randomly using a weighted random prototype
+/// </summary>
+[RegisterComponent, Access(typeof(SolutionRandomFillSystem))]
+public sealed class RandomFillSolutionComponent : Component
+{
+    /// <summary>
+    ///     Solution name which to add reagents to.
+    /// </summary>
+    [DataField("solution")]
+    public string Solution { get; set; } = "default";
+
+    /// <summary>
+    ///     Weighted random prototype Id. Used to pick reagent.
+    /// </summary>
+    [DataField("weightedRandomId", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomPrototype>))]
+    public string WeightedRandomId { get; set; } = "default";
+
+    /// <summary>
+    ///     Amount of reagent to add.
+    /// </summary>
+    [DataField("quantity")]
+    public FixedPoint2 Quantity { get; set; } = 0;
+}
diff --git a/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs
new file mode 100644 (file)
index 0000000..0d653e1
--- /dev/null
@@ -0,0 +1,37 @@
+using Content.Server.Chemistry.Components.SolutionManager;
+using Content.Shared.Chemistry.Reagent;
+using Content.Shared.Random;
+using Content.Shared.Random.Helpers;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Random;
+
+namespace Content.Server.Chemistry.EntitySystems;
+
+public sealed class SolutionRandomFillSystem : EntitySystem
+{
+    [Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
+    [Dependency] private readonly IPrototypeManager _proto = default!;
+    [Dependency] private readonly IRobustRandom _random = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RandomFillSolutionComponent, MapInitEvent>(OnRandomSolutionFillMapInit);
+    }
+
+    public void OnRandomSolutionFillMapInit(EntityUid uid, RandomFillSolutionComponent component, MapInitEvent args)
+    {
+        var target = _solutionsSystem.EnsureSolution(uid, component.Solution);
+        var reagent = _proto.Index<WeightedRandomPrototype>(component.WeightedRandomId).Pick(_random);
+
+        if (!_proto.TryIndex<ReagentPrototype>(reagent, out ReagentPrototype? reagentProto))
+        {
+            Logger.Error(
+                $"Tried to add invalid reagent Id {reagent} using SolutionRandomFill.");
+            return;
+        }
+
+        target.AddReagent(reagent, component.Quantity);
+    }
+}
index 99ae6811c1eb7dc14f94c897574e8b6985311e50..686fea920d9e9acf04014ff1fff328bb7abea531 100644 (file)
           prob: 0.1
         - id: ClothingHandsGlovesColorYellowBudget
           prob: 0.25
+        - id: StrangePill
+          prob: 0.20
 
 - type: entity
   id: ClosetWallMaintenanceFilledRandom
diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/randompill.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/randompill.yml
new file mode 100644 (file)
index 0000000..6d57716
--- /dev/null
@@ -0,0 +1,98 @@
+- type: weightedRandom
+  id: RandomFillStrangePill
+  weights:
+    # Elements
+    Aluminium: 1
+    Carbon: 1
+    Chlorine: 1
+    Copper: 1
+    Fluorine: 1
+    Hydrogen: 1
+    Iodine: 1
+    Lithium: 1
+    Mercury: 1
+    Potassium: 1
+    Phosphorus: 1
+    Radium: 1
+    Silicon: 1
+    Sulfur: 1
+    Sodium: 1
+    # Medicines
+    Ipecac: 3
+    Omnizine: 2
+    Tricordrazine: 3
+    # Narcotics
+    Desoxyephedrine: 3
+    Ephedrine: 3
+    SpaceDrugs: 5
+    Nocturine: 3
+    MuteToxin: 3
+    NorepinephricAcid: 3
+    # Toxins
+    ChloralHydrate: 3
+    Mold: 3
+    Pax: 3
+    Toxin: 5
+
+- type: entity
+  name: strange pill
+  parent: Pill
+  id: StrangePill
+  description: This unusual pill bears no markings. There's no telling what it contains.
+  components:
+  - type: SolutionContainerManager
+    solutions:
+      food:
+        maxVol: 20
+  - type: RandomFillSolution
+    solution: food
+    weightedRandomId: RandomFillStrangePill
+    quantity: 20
+  - type: Sprite
+    sprite: Objects/Specific/Chemistry/pills.rsi
+    netsync: false
+    layers:
+    - state: pill1
+      map: [ "enum.DamageStateVisualLayers.Base" ]
+  - type: RandomSprite
+    available:
+      - enum.DamageStateVisualLayers.Base:
+          pill1: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill2: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill3: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill4: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill5: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill6: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill7: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill8: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill9: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill10: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill11: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill12: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill13: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill14: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill15: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill16: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill17: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill18: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill19: ""
+      - enum.DamageStateVisualLayers.Base:
+          pill20: ""