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!!
This commit is contained in:
committed by
GitHub
parent
ec82a05df9
commit
f850047341
@@ -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();
|
||||
|
||||
@@ -59,42 +59,6 @@ namespace Content.Server.Lathe
|
||||
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
||||
SubscribeLocalEvent<EmagLatheRecipesComponent, LatheGetRecipesEvent>(GetEmagLatheRecipes);
|
||||
SubscribeLocalEvent<LatheHeatProducingComponent, LatheStartPrintingEvent>(OnHeatStartPrinting);
|
||||
|
||||
SubscribeLocalEvent<LatheComponent, LatheEjectMaterialMessage>(OnLatheEjectMessage);
|
||||
}
|
||||
|
||||
private void OnLatheEjectMessage(EntityUid uid, LatheComponent lathe, LatheEjectMaterialMessage message)
|
||||
{
|
||||
if (!lathe.CanEjectStoredMaterials)
|
||||
return;
|
||||
|
||||
if (!_proto.TryIndex<MaterialPrototype>(message.Material, out var material))
|
||||
return;
|
||||
|
||||
var volume = 0;
|
||||
|
||||
if (material.StackEntity != null)
|
||||
{
|
||||
var entProto = _proto.Index<EntityPrototype>(material.StackEntity);
|
||||
if (!entProto.TryGetComponent<PhysicalCompositionComponent>(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)
|
||||
|
||||
@@ -30,6 +30,8 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
|
||||
|
||||
SubscribeLocalEvent<MaterialStorageComponent, EjectMaterialMessage>(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<MaterialPrototype>(message.Material, out var material))
|
||||
return;
|
||||
|
||||
var volume = 0;
|
||||
|
||||
if (material.StackEntity != null)
|
||||
{
|
||||
if (!_prototypeManager.Index<EntityPrototype>(material.StackEntity).TryGetComponent<PhysicalCompositionComponent>(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,
|
||||
|
||||
@@ -47,12 +47,6 @@ namespace Content.Shared.Lathe
|
||||
[ViewVariables]
|
||||
public LatheRecipePrototype? CurrentRecipe;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the lathe can eject the materials stored within it
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool CanEjectStoredMaterials = true;
|
||||
|
||||
#region MachineUpgrading
|
||||
/// <summary>
|
||||
/// A modifier that changes how long it takes to print a recipe
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,12 @@ public sealed partial class MaterialStorageComponent : Component
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing
|
||||
|
||||
/// <summary>
|
||||
/// Whether the storage can eject the materials stored within it
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool CanEjectStoredMaterials = true;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -94,3 +100,20 @@ public record struct GetMaterialWhitelistEvent(EntityUid Storage)
|
||||
|
||||
public List<ProtoId<MaterialPrototype>> Whitelist = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message sent to try and eject a material from a storage
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class EjectMaterialMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public string Material;
|
||||
public int SheetsToExtract;
|
||||
|
||||
public EjectMaterialMessage(string material, int sheetsToExtract)
|
||||
{
|
||||
Material = material;
|
||||
SheetsToExtract = sheetsToExtract;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user