]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Clean up RefiningSystem (#27904)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Wed, 29 May 2024 18:06:50 +0000 (14:06 -0400)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 18:06:50 +0000 (11:06 -0700)
cleanup RefiningSystem

Content.Server/Construction/Components/WelderRefinableComponent.cs
Content.Server/Construction/RefiningSystem.cs
Resources/Prototypes/Entities/Objects/Materials/shards.yml
Resources/Prototypes/Entities/Objects/Misc/broken_bottle.yml
Resources/Prototypes/Entities/Objects/Power/lights.yml

index ed37d6f74b83a74de6dda8b1354332980929d4c9..2fe88f2670c1008882a4e30e8e6c2459d7554392 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Storage;
 using Content.Shared.Tools;
 using Robust.Shared.Prototypes;
 
@@ -7,18 +8,30 @@ namespace Content.Server.Construction.Components;
 /// Used for something that can be refined by welder.
 /// For example, glass shard can be refined to glass sheet.
 /// </summary>
-[RegisterComponent]
+[RegisterComponent, Access(typeof(RefiningSystem))]
 public sealed partial class WelderRefinableComponent : Component
 {
-    [DataField]
-    public HashSet<EntProtoId>? RefineResult = new();
+    /// <summary>
+    /// The items created when the item is refined.
+    /// </summary>
+    [DataField(required: true)]
+    public List<EntitySpawnEntry> RefineResult = new();
 
+    /// <summary>
+    /// The amount of time it takes to refine a given item.
+    /// </summary>
     [DataField]
     public float RefineTime = 2f;
 
+    /// <summary>
+    /// The amount of fuel it takes to refine a given item.
+    /// </summary>
     [DataField]
     public float RefineFuel;
 
+    /// <summary>
+    /// The tool type needed in order to refine this item.
+    /// </summary>
     [DataField]
     public ProtoId<ToolQualityPrototype> QualityNeeded = "Welding";
 }
index 53cfb14528edb6c3943e6082270a77e065049ff2..ce7eb49ef1d7c7c8151309fe25f167bdd5f2ee2e 100644 (file)
@@ -1,50 +1,51 @@
 using Content.Server.Construction.Components;
-using Content.Server.Stack;
 using Content.Shared.Construction;
 using Content.Shared.Interaction;
-using Content.Shared.Stacks;
-using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
+using Content.Shared.Storage;
+using Content.Shared.Tools.Systems;
+using Robust.Shared.Random;
 
-namespace Content.Server.Construction
+namespace Content.Server.Construction;
+
+public sealed class RefiningSystem : EntitySystem
 {
-    public sealed class RefiningSystem : EntitySystem
+    [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly SharedToolSystem _toolSystem = default!;
+
+    public override void Initialize()
     {
-        [Dependency] private readonly SharedToolSystem _toolSystem = default!;
-        [Dependency] private readonly StackSystem _stackSystem = default!;
-        public override void Initialize()
-        {
-            base.Initialize();
-            SubscribeLocalEvent<WelderRefinableComponent, InteractUsingEvent>(OnInteractUsing);
-            SubscribeLocalEvent<WelderRefinableComponent, WelderRefineDoAfterEvent>(OnDoAfter);
-        }
+        base.Initialize();
+        SubscribeLocalEvent<WelderRefinableComponent, InteractUsingEvent>(OnInteractUsing);
+        SubscribeLocalEvent<WelderRefinableComponent, WelderRefineDoAfterEvent>(OnDoAfter);
+    }
 
-        private void OnInteractUsing(EntityUid uid, WelderRefinableComponent component, InteractUsingEvent args)
-        {
-            if (args.Handled)
-                return;
+    private void OnInteractUsing(EntityUid uid, WelderRefinableComponent component, InteractUsingEvent args)
+    {
+        if (args.Handled)
+            return;
 
-            args.Handled = _toolSystem.UseTool(args.Used, args.User, uid, component.RefineTime, component.QualityNeeded, new WelderRefineDoAfterEvent(), fuel: component.RefineFuel);
-        }
+        args.Handled = _toolSystem.UseTool(
+            args.Used,
+            args.User,
+            uid,
+            component.RefineTime,
+            component.QualityNeeded,
+            new WelderRefineDoAfterEvent(),
+            fuel: component.RefineFuel);
+    }
 
-        private void OnDoAfter(EntityUid uid, WelderRefinableComponent component, WelderRefineDoAfterEvent args)
+    private void OnDoAfter(EntityUid uid, WelderRefinableComponent component, WelderRefineDoAfterEvent args)
+    {
+        if (args.Cancelled)
+            return;
+
+        var xform = Transform(uid);
+        var spawns = EntitySpawnCollection.GetSpawns(component.RefineResult, _random);
+        foreach (var spawn in spawns)
         {
-            if (args.Cancelled)
-                return;
-
-            // get last owner coordinates and delete it
-            var resultPosition = Transform(uid).Coordinates;
-            EntityManager.DeleteEntity(uid);
-
-            // spawn each result after refine
-            foreach (var result in component.RefineResult!)
-            {
-                var droppedEnt = Spawn(result, resultPosition);
-
-                // TODO: If something has a stack... Just use a prototype with a single thing in the stack.
-                // This is not a good way to do it.
-                if (TryComp<StackComponent>(droppedEnt, out var stack))
-                    _stackSystem.SetCount(droppedEnt, 1, stack);
-            }
+            SpawnNextToOrDrop(spawn, uid, xform);
         }
+
+        Del(uid);
     }
 }
index dfd02b6fccf7faadaca0304cb3e7564af699432f..561140a46a44de942da24eba6dbc7aa64d39a75b 100644 (file)
@@ -87,7 +87,7 @@
     color: "#bbeeff"
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
+    - id: SheetGlass1
   - type: DamageUserOnTrigger
     damage:
       types:
         Slash: 4.5
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - PartRodMetal1
+    - id: SheetGlass1
+    - id: PartRodMetal1
   - type: DamageUserOnTrigger
     damage:
       types:
         Slash: 5.5
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - SheetPlasma1
+    - id: SheetGlass1
+    - id: SheetPlasma1
   - type: DamageUserOnTrigger
     damage:
       types:
         Radiation: 2
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - SheetUranium1
+    - id: SheetGlass1
+    - id: SheetUranium1
   - type: DamageUserOnTrigger
     damage:
       types:
     color: "#e0aa36"
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - SheetBrass1
+    - id: SheetGlass1
+    - id: SheetBrass1
   - type: DamageUserOnTrigger
     damage:
       types:
index b7c73f5e0cc84acdf30738eac5561c7d3425e6c6..32222d0036cd1fdd474f564a83a24b0c9bd3d9bf 100644 (file)
@@ -28,4 +28,4 @@
   - type: SpaceGarbage
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
+    - id: SheetGlass1
index a5cf712d099c3c05b36ef3968308c111b95bd925..bccf10bee53578f91407771c7e7845cd9f0219c8 100644 (file)
@@ -68,7 +68,7 @@
   - type: SpaceGarbage
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
+    - id: SheetGlass1
 
 - type: entity
   parent: BaseLightbulb
     node: icon
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - ShardCrystalCyan
+    - id: SheetGlass1
+    - id: ShardCrystalCyan
 
 - type: entity
   parent: LightTubeCrystalCyan
     node: icon
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - ShardCrystalBlue
+    - id: SheetGlass1
+    - id: ShardCrystalBlue
 
 - type: entity
   parent: LightTubeCrystalCyan
     node: icon
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - ShardCrystalPink
+    - id: SheetGlass1
+    - id: ShardCrystalPink
 
 - type: entity
   parent: LightTubeCrystalCyan
     node: icon
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - ShardCrystalOrange
+    - id: SheetGlass1
+    - id: ShardCrystalOrange
 
 - type: entity
   parent: LightTubeCrystalCyan
     node: icon
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - ShardCrystalRed
+    - id: SheetGlass1
+    - id: ShardCrystalRed
 
 - type: entity
   parent: LightTubeCrystalCyan
     node: icon
   - type: WelderRefinable
     refineResult:
-    - SheetGlass1
-    - ShardCrystalGreen
+    - id: SheetGlass1
+    - id: ShardCrystalGreen