From: Hannah Giovanna Dawson Date: Sun, 31 Dec 2023 01:08:33 +0000 (+0000) Subject: Migrate Lathe Material Ejection Code to MaterialStorage (#23199) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=f850047341108b286170197d12f4d13946ee0b40;p=space-station-14.git Migrate Lathe Material Ejection Code to MaterialStorage (#23199) * SS14-23184 Migrate Lathe Material Ejection Code to MaterialStorage The lathe material ejection code acts as a do-nothing man-in-the-middle system that does work that would be reasonable for any MaterialStorage-using machine to use. This has been fixed by migrating the ejection code to MaterialStorage, allowing anything that uses the system to eject mats it is storing. * Fix some YAML references. Science!! --- diff --git a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs index 69e41d1885..3e04b184b4 100644 --- a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs +++ b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs @@ -1,4 +1,5 @@ using Content.Shared.Lathe; +using Content.Shared.Materials; using Content.Shared.Research.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; @@ -34,7 +35,7 @@ namespace Content.Client.Lathe.UI _menu.OnEjectPressed += (material, sheetsToExtract) => { - SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract)); + SendMessage(new EjectMaterialMessage(material, sheetsToExtract)); }; _menu.OpenCentered(); diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index a262c1a69f..9e06dca52b 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -59,42 +59,6 @@ namespace Content.Server.Lathe SubscribeLocalEvent(OnGetRecipes); SubscribeLocalEvent(GetEmagLatheRecipes); SubscribeLocalEvent(OnHeatStartPrinting); - - SubscribeLocalEvent(OnLatheEjectMessage); - } - - private void OnLatheEjectMessage(EntityUid uid, LatheComponent lathe, LatheEjectMaterialMessage message) - { - if (!lathe.CanEjectStoredMaterials) - return; - - if (!_proto.TryIndex(message.Material, out var material)) - return; - - var volume = 0; - - if (material.StackEntity != null) - { - var entProto = _proto.Index(material.StackEntity); - if (!entProto.TryGetComponent(out var composition)) - return; - - var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == message.Material).Value; - var sheetsToExtract = Math.Min(message.SheetsToExtract, _stack.GetMaxCount(material.StackEntity)); - - volume = sheetsToExtract * volumePerSheet; - } - - if (volume > 0 && _materialStorage.TryChangeMaterialAmount(uid, message.Material, -volume)) - { - var mats = _materialStorage.SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out _); - foreach (var mat in mats) - { - if (TerminatingOrDeleted(mat)) - continue; - _stack.TryMergeToContacts(mat); - } - } } public override void Update(float frameTime) @@ -116,7 +80,7 @@ namespace Content.Server.Lathe continue; heatComp.NextSecond += TimeSpan.FromSeconds(1); - var position = _transform.GetGridTilePositionOrDefault((uid,xform)); + var position = _transform.GetGridTilePositionOrDefault((uid, xform)); _environments.Clear(); if (_atmosphere.GetTileMixture(xform.GridUid, xform.MapUid, position, true) is { } tileMix) diff --git a/Content.Server/Materials/MaterialStorageSystem.cs b/Content.Server/Materials/MaterialStorageSystem.cs index 5d581220e2..336a987505 100644 --- a/Content.Server/Materials/MaterialStorageSystem.cs +++ b/Content.Server/Materials/MaterialStorageSystem.cs @@ -30,6 +30,8 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem { base.Initialize(); SubscribeLocalEvent(OnDeconstructed); + + SubscribeLocalEvent(OnEjectMessage); } private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args) @@ -43,6 +45,34 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem } } + private void OnEjectMessage(EntityUid uid, MaterialStorageComponent component, EjectMaterialMessage message) + { + if (!component.CanEjectStoredMaterials || !_prototypeManager.TryIndex(message.Material, out var material)) + return; + + var volume = 0; + + if (material.StackEntity != null) + { + if (!_prototypeManager.Index(material.StackEntity).TryGetComponent(out var composition)) + return; + + var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == message.Material).Value; + var sheetsToExtract = Math.Min(message.SheetsToExtract, _stackSystem.GetMaxCount(material.StackEntity)); + + volume = sheetsToExtract * volumePerSheet; + } + + if (volume <= 0 || !TryChangeMaterialAmount(uid, message.Material, -volume)) + return; + + var mats = SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out _); + foreach (var mat in mats.Where(mat => !TerminatingOrDeleted(mat))) + { + _stackSystem.TryMergeToContacts(mat); + } + } + public override bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, diff --git a/Content.Shared/Lathe/LatheComponent.cs b/Content.Shared/Lathe/LatheComponent.cs index 8607cf48e2..6bbdb61a42 100644 --- a/Content.Shared/Lathe/LatheComponent.cs +++ b/Content.Shared/Lathe/LatheComponent.cs @@ -47,12 +47,6 @@ namespace Content.Shared.Lathe [ViewVariables] public LatheRecipePrototype? CurrentRecipe; - /// - /// Whether the lathe can eject the materials stored within it - /// - [DataField] - public bool CanEjectStoredMaterials = true; - #region MachineUpgrading /// /// A modifier that changes how long it takes to print a recipe diff --git a/Content.Shared/Lathe/LatheEjectMaterialMessage.cs b/Content.Shared/Lathe/LatheEjectMaterialMessage.cs deleted file mode 100644 index 36e3005c65..0000000000 --- a/Content.Shared/Lathe/LatheEjectMaterialMessage.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Lathe; - -[Serializable, NetSerializable] -public sealed class LatheEjectMaterialMessage : BoundUserInterfaceMessage -{ - public string Material; - public int SheetsToExtract; - - public LatheEjectMaterialMessage(string material, int sheetsToExtract) - { - Material = material; - SheetsToExtract = sheetsToExtract; - } -} diff --git a/Content.Shared/Materials/MaterialStorageComponent.cs b/Content.Shared/Materials/MaterialStorageComponent.cs index c905478bca..6762dfeadc 100644 --- a/Content.Shared/Materials/MaterialStorageComponent.cs +++ b/Content.Shared/Materials/MaterialStorageComponent.cs @@ -61,6 +61,12 @@ public sealed partial class MaterialStorageComponent : Component /// [DataField] public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing + + /// + /// Whether the storage can eject the materials stored within it + /// + [DataField] + public bool CanEjectStoredMaterials = true; } [Serializable, NetSerializable] @@ -94,3 +100,20 @@ public record struct GetMaterialWhitelistEvent(EntityUid Storage) public List> Whitelist = new(); } + +/// +/// Message sent to try and eject a material from a storage +/// +[Serializable, NetSerializable] +public sealed class EjectMaterialMessage : BoundUserInterfaceMessage +{ + public string Material; + public int SheetsToExtract; + + public EjectMaterialMessage(string material, int sheetsToExtract) + { + Material = material; + SheetsToExtract = sheetsToExtract; + } +} + diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index 7472258f75..7811b13795 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -939,13 +939,13 @@ - type: MaterialStorage dropOnDeconstruct: false #should drop ores instead of ingots/sheets ignoreColor: true + canEjectStoredMaterials: false whitelist: tags: - Ore - type: Lathe idleState: icon runningState: building - canEjectStoredMaterials: false staticRecipes: - SheetSteel30 - SheetGlass30 @@ -991,6 +991,7 @@ - type: MaterialStorage dropOnDeconstruct: false #should drop ores instead of ingots/sheets ignoreColor: true + canEjectStoredMaterials: false whitelist: tags: - Raw @@ -998,7 +999,6 @@ - type: Lathe idleState: base_machine runningState: base_machine_processing - canEjectStoredMaterials: false staticRecipes: - MaterialSheetMeat - SheetPaper