From 57cb533e9cf117ce82a260393d08cc61cc2c68ff Mon Sep 17 00:00:00 2001 From: MisterMecky Date: Mon, 1 May 2023 22:43:31 +0800 Subject: [PATCH] Add strange pills, RandomFillSolutionComponent (#15067) --- .../RandomFillSolutionComponent.cs | 31 ++++++ .../EntitySystems/SolutionRandomFillSystem.cs | 37 +++++++ .../Prototypes/Catalog/Fills/Lockers/misc.yml | 2 + .../Objects/Specific/Medical/randompill.yml | 98 +++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs create mode 100644 Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs create mode 100644 Resources/Prototypes/Entities/Objects/Specific/Medical/randompill.yml diff --git a/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs b/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs new file mode 100644 index 0000000000..bf75df03a7 --- /dev/null +++ b/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs @@ -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; + +/// +/// Fills a solution container randomly using a weighted random prototype +/// +[RegisterComponent, Access(typeof(SolutionRandomFillSystem))] +public sealed class RandomFillSolutionComponent : Component +{ + /// + /// Solution name which to add reagents to. + /// + [DataField("solution")] + public string Solution { get; set; } = "default"; + + /// + /// Weighted random prototype Id. Used to pick reagent. + /// + [DataField("weightedRandomId", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))] + public string WeightedRandomId { get; set; } = "default"; + + /// + /// Amount of reagent to add. + /// + [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 index 0000000000..0d653e1da9 --- /dev/null +++ b/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs @@ -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(OnRandomSolutionFillMapInit); + } + + public void OnRandomSolutionFillMapInit(EntityUid uid, RandomFillSolutionComponent component, MapInitEvent args) + { + var target = _solutionsSystem.EnsureSolution(uid, component.Solution); + var reagent = _proto.Index(component.WeightedRandomId).Pick(_random); + + if (!_proto.TryIndex(reagent, out ReagentPrototype? reagentProto)) + { + Logger.Error( + $"Tried to add invalid reagent Id {reagent} using SolutionRandomFill."); + return; + } + + target.AddReagent(reagent, component.Quantity); + } +} diff --git a/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml b/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml index 99ae6811c1..686fea920d 100644 --- a/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml +++ b/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml @@ -125,6 +125,8 @@ 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 index 0000000000..6d57716a86 --- /dev/null +++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/randompill.yml @@ -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: ""