diff --git a/Content.Client/IgnoredComponents.cs b/Content.Client/IgnoredComponents.cs index 1959d0ebad..41c10d6f2d 100644 --- a/Content.Client/IgnoredComponents.cs +++ b/Content.Client/IgnoredComponents.cs @@ -210,8 +210,9 @@ "CrematoriumEntityStorage", "RandomArcade", "RandomSpriteState", + "WelderRefinable", "ConveyorAssembly", - "TwoWayLever" + "TwoWayLever", }; } } diff --git a/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs b/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs new file mode 100644 index 0000000000..1d5fb02d88 --- /dev/null +++ b/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs @@ -0,0 +1,71 @@ +#nullable enable +using System.Collections.Generic; +using System.Threading.Tasks; +using Content.Server.GameObjects.Components.Interactable; +using Content.Server.GameObjects.Components.Stack; +using Content.Shared.GameObjects.Components.Interactable; +using Content.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; + +namespace Content.Server.GameObjects.Components.Construction +{ + /// + /// Used for something that can be refined by welder. + /// For example, glass shard can be refined to glass sheet. + /// + [RegisterComponent] + public class WelderRefinableComponent : Component, IInteractUsing + { + [ViewVariables] + private HashSet? _refineResult = default; + [ViewVariables] + private float _refineTime; + + private bool _beingWelded; + + public override string Name => "WelderRefinable"; + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + serializer.DataField(ref _refineResult, "refineResult", new HashSet { "GlassStack" }); + serializer.DataField(ref _refineTime, "refineTime", 2f); + } + + public async Task InteractUsing(InteractUsingEventArgs eventArgs) + { + // check if object is welder + if (!eventArgs.Using.TryGetComponent(out ToolComponent? tool)) + return false; + + // check if someone is already welding object + if (_beingWelded) + return false; + _beingWelded = true; + + if (!await tool.UseTool(eventArgs.User, Owner, _refineTime, ToolQuality.Welding)) + { + // failed to veld - abort refine + _beingWelded = false; + return false; + } + + // get last owner coordinates and delete it + var resultPosition = Owner.Transform.Coordinates; + Owner.Delete(); + + // spawn each result afrer refine + foreach (var result in _refineResult!) + { + var droppedEnt = Owner.EntityManager.SpawnEntity(result, resultPosition); + + if (droppedEnt.TryGetComponent(out var stackComp)) + stackComp.Count = 1; + } + + return true; + } + } +} diff --git a/Resources/Prototypes/Entities/Constructible/Walls/windows.yml b/Resources/Prototypes/Entities/Constructible/Walls/windows.yml index 97e6310a7c..87ee34936b 100644 --- a/Resources/Prototypes/Entities/Constructible/Walls/windows.yml +++ b/Resources/Prototypes/Entities/Constructible/Walls/windows.yml @@ -33,7 +33,7 @@ spawnOnDestroy: ShardGlass: Min: 1 - Max: 3 + Max: 2 - type: SnapGrid offset: Center - type: Airtight @@ -58,6 +58,10 @@ sprite: Constructible/Structures/Windows/reinforced_window.rsi - type: Destructible deadThreshold: 75 + spawnOnDestroy: + ShardGlassReinforced: + Min: 1 + Max: 2 resistances: metallicResistances - type: Window base: rwindow @@ -77,6 +81,10 @@ sprite: Constructible/Structures/Windows/phoron_window.rsi - type: Destructible deadThreshold: 100 + spawnOnDestroy: + ShardGlassPhoron: + Min: 1 + Max: 2 resistances: metallicResistances - type: Window base: pwindow diff --git a/Resources/Prototypes/Entities/Objects/shards.yml b/Resources/Prototypes/Entities/Objects/shards.yml index 0807101774..b9803cf51b 100644 --- a/Resources/Prototypes/Entities/Objects/shards.yml +++ b/Resources/Prototypes/Entities/Objects/shards.yml @@ -25,10 +25,13 @@ description: A small piece of glass. It looks sharp, you wouldn't want to step on it barefoot. parent: ShardBase components: - - type: Sprite - color: "#bbeeff" - - type: Item - color: "#bbeeff" + - type: Sprite + color: "#bbeeff" + - type: Item + color: "#bbeeff" + - type: WelderRefinable + refineResult: + - GlassStack - type: entity id: ShardGlassReinforced @@ -36,11 +39,14 @@ description: A small piece of reinforced glass. It looks sharp, you wouldn't want to step on it barefoot. parent: ShardBase components: - - type: Sprite - color: "#96cdef" - - type: Item - color: "#96cdef" - + - type: Sprite + color: "#96cdef" + - type: Item + color: "#96cdef" + - type: WelderRefinable + refineResult: + - GlassStack + - MetalStack - type: entity id: ShardGlassPhoron name: phoron glass shard @@ -51,3 +57,7 @@ color: "#f3b489" - type: Item color: "#f3b489" + - type: WelderRefinable + refineResult: + - GlassStack + - PhoronStack