From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 29 May 2024 18:06:50 +0000 (-0400) Subject: Clean up RefiningSystem (#27904) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=5d79f897b98540d9318e181403b25899dea1f1c6;p=space-station-14.git Clean up RefiningSystem (#27904) cleanup RefiningSystem --- diff --git a/Content.Server/Construction/Components/WelderRefinableComponent.cs b/Content.Server/Construction/Components/WelderRefinableComponent.cs index ed37d6f74b..2fe88f2670 100644 --- a/Content.Server/Construction/Components/WelderRefinableComponent.cs +++ b/Content.Server/Construction/Components/WelderRefinableComponent.cs @@ -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. /// -[RegisterComponent] +[RegisterComponent, Access(typeof(RefiningSystem))] public sealed partial class WelderRefinableComponent : Component { - [DataField] - public HashSet? RefineResult = new(); + /// + /// The items created when the item is refined. + /// + [DataField(required: true)] + public List RefineResult = new(); + /// + /// The amount of time it takes to refine a given item. + /// [DataField] public float RefineTime = 2f; + /// + /// The amount of fuel it takes to refine a given item. + /// [DataField] public float RefineFuel; + /// + /// The tool type needed in order to refine this item. + /// [DataField] public ProtoId QualityNeeded = "Welding"; } diff --git a/Content.Server/Construction/RefiningSystem.cs b/Content.Server/Construction/RefiningSystem.cs index 53cfb14528..ce7eb49ef1 100644 --- a/Content.Server/Construction/RefiningSystem.cs +++ b/Content.Server/Construction/RefiningSystem.cs @@ -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(OnInteractUsing); - SubscribeLocalEvent(OnDoAfter); - } + base.Initialize(); + SubscribeLocalEvent(OnInteractUsing); + SubscribeLocalEvent(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(droppedEnt, out var stack)) - _stackSystem.SetCount(droppedEnt, 1, stack); - } + SpawnNextToOrDrop(spawn, uid, xform); } + + Del(uid); } } diff --git a/Resources/Prototypes/Entities/Objects/Materials/shards.yml b/Resources/Prototypes/Entities/Objects/Materials/shards.yml index dfd02b6fcc..561140a46a 100644 --- a/Resources/Prototypes/Entities/Objects/Materials/shards.yml +++ b/Resources/Prototypes/Entities/Objects/Materials/shards.yml @@ -87,7 +87,7 @@ color: "#bbeeff" - type: WelderRefinable refineResult: - - SheetGlass1 + - id: SheetGlass1 - type: DamageUserOnTrigger damage: types: @@ -122,8 +122,8 @@ Slash: 4.5 - type: WelderRefinable refineResult: - - SheetGlass1 - - PartRodMetal1 + - id: SheetGlass1 + - id: PartRodMetal1 - type: DamageUserOnTrigger damage: types: @@ -158,8 +158,8 @@ Slash: 5.5 - type: WelderRefinable refineResult: - - SheetGlass1 - - SheetPlasma1 + - id: SheetGlass1 + - id: SheetPlasma1 - type: DamageUserOnTrigger damage: types: @@ -197,8 +197,8 @@ Radiation: 2 - type: WelderRefinable refineResult: - - SheetGlass1 - - SheetUranium1 + - id: SheetGlass1 + - id: SheetUranium1 - type: DamageUserOnTrigger damage: types: @@ -232,8 +232,8 @@ color: "#e0aa36" - type: WelderRefinable refineResult: - - SheetGlass1 - - SheetBrass1 + - id: SheetGlass1 + - id: SheetBrass1 - type: DamageUserOnTrigger damage: types: diff --git a/Resources/Prototypes/Entities/Objects/Misc/broken_bottle.yml b/Resources/Prototypes/Entities/Objects/Misc/broken_bottle.yml index b7c73f5e0c..32222d0036 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/broken_bottle.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/broken_bottle.yml @@ -28,4 +28,4 @@ - type: SpaceGarbage - type: WelderRefinable refineResult: - - SheetGlass1 + - id: SheetGlass1 diff --git a/Resources/Prototypes/Entities/Objects/Power/lights.yml b/Resources/Prototypes/Entities/Objects/Power/lights.yml index a5cf712d09..bccf10bee5 100644 --- a/Resources/Prototypes/Entities/Objects/Power/lights.yml +++ b/Resources/Prototypes/Entities/Objects/Power/lights.yml @@ -68,7 +68,7 @@ - type: SpaceGarbage - type: WelderRefinable refineResult: - - SheetGlass1 + - id: SheetGlass1 - type: entity parent: BaseLightbulb @@ -275,8 +275,8 @@ node: icon - type: WelderRefinable refineResult: - - SheetGlass1 - - ShardCrystalCyan + - id: SheetGlass1 + - id: ShardCrystalCyan - type: entity parent: LightTubeCrystalCyan @@ -295,8 +295,8 @@ node: icon - type: WelderRefinable refineResult: - - SheetGlass1 - - ShardCrystalBlue + - id: SheetGlass1 + - id: ShardCrystalBlue - type: entity parent: LightTubeCrystalCyan @@ -315,8 +315,8 @@ node: icon - type: WelderRefinable refineResult: - - SheetGlass1 - - ShardCrystalPink + - id: SheetGlass1 + - id: ShardCrystalPink - type: entity parent: LightTubeCrystalCyan @@ -335,8 +335,8 @@ node: icon - type: WelderRefinable refineResult: - - SheetGlass1 - - ShardCrystalOrange + - id: SheetGlass1 + - id: ShardCrystalOrange - type: entity parent: LightTubeCrystalCyan @@ -355,8 +355,8 @@ node: icon - type: WelderRefinable refineResult: - - SheetGlass1 - - ShardCrystalRed + - id: SheetGlass1 + - id: ShardCrystalRed - type: entity parent: LightTubeCrystalCyan @@ -375,5 +375,5 @@ node: icon - type: WelderRefinable refineResult: - - SheetGlass1 - - ShardCrystalGreen + - id: SheetGlass1 + - id: ShardCrystalGreen