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.Lathe;
|
||||||
|
using Content.Shared.Materials;
|
||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
@@ -34,7 +35,7 @@ namespace Content.Client.Lathe.UI
|
|||||||
|
|
||||||
_menu.OnEjectPressed += (material, sheetsToExtract) =>
|
_menu.OnEjectPressed += (material, sheetsToExtract) =>
|
||||||
{
|
{
|
||||||
SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract));
|
SendMessage(new EjectMaterialMessage(material, sheetsToExtract));
|
||||||
};
|
};
|
||||||
|
|
||||||
_menu.OpenCentered();
|
_menu.OpenCentered();
|
||||||
|
|||||||
@@ -59,42 +59,6 @@ namespace Content.Server.Lathe
|
|||||||
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
||||||
SubscribeLocalEvent<EmagLatheRecipesComponent, LatheGetRecipesEvent>(GetEmagLatheRecipes);
|
SubscribeLocalEvent<EmagLatheRecipesComponent, LatheGetRecipesEvent>(GetEmagLatheRecipes);
|
||||||
SubscribeLocalEvent<LatheHeatProducingComponent, LatheStartPrintingEvent>(OnHeatStartPrinting);
|
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)
|
public override void Update(float frameTime)
|
||||||
@@ -116,7 +80,7 @@ namespace Content.Server.Lathe
|
|||||||
continue;
|
continue;
|
||||||
heatComp.NextSecond += TimeSpan.FromSeconds(1);
|
heatComp.NextSecond += TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
var position = _transform.GetGridTilePositionOrDefault((uid,xform));
|
var position = _transform.GetGridTilePositionOrDefault((uid, xform));
|
||||||
_environments.Clear();
|
_environments.Clear();
|
||||||
|
|
||||||
if (_atmosphere.GetTileMixture(xform.GridUid, xform.MapUid, position, true) is { } tileMix)
|
if (_atmosphere.GetTileMixture(xform.GridUid, xform.MapUid, position, true) is { } tileMix)
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
|
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<MaterialStorageComponent, EjectMaterialMessage>(OnEjectMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args)
|
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,
|
public override bool TryInsertMaterialEntity(EntityUid user,
|
||||||
EntityUid toInsert,
|
EntityUid toInsert,
|
||||||
EntityUid receiver,
|
EntityUid receiver,
|
||||||
|
|||||||
@@ -47,12 +47,6 @@ namespace Content.Shared.Lathe
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public LatheRecipePrototype? CurrentRecipe;
|
public LatheRecipePrototype? CurrentRecipe;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the lathe can eject the materials stored within it
|
|
||||||
/// </summary>
|
|
||||||
[DataField]
|
|
||||||
public bool CanEjectStoredMaterials = true;
|
|
||||||
|
|
||||||
#region MachineUpgrading
|
#region MachineUpgrading
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A modifier that changes how long it takes to print a recipe
|
/// 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>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing
|
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]
|
[Serializable, NetSerializable]
|
||||||
@@ -94,3 +100,20 @@ public record struct GetMaterialWhitelistEvent(EntityUid Storage)
|
|||||||
|
|
||||||
public List<ProtoId<MaterialPrototype>> Whitelist = new();
|
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
|
- type: MaterialStorage
|
||||||
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
|
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
|
||||||
ignoreColor: true
|
ignoreColor: true
|
||||||
|
canEjectStoredMaterials: false
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- Ore
|
- Ore
|
||||||
- type: Lathe
|
- type: Lathe
|
||||||
idleState: icon
|
idleState: icon
|
||||||
runningState: building
|
runningState: building
|
||||||
canEjectStoredMaterials: false
|
|
||||||
staticRecipes:
|
staticRecipes:
|
||||||
- SheetSteel30
|
- SheetSteel30
|
||||||
- SheetGlass30
|
- SheetGlass30
|
||||||
@@ -991,6 +991,7 @@
|
|||||||
- type: MaterialStorage
|
- type: MaterialStorage
|
||||||
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
|
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
|
||||||
ignoreColor: true
|
ignoreColor: true
|
||||||
|
canEjectStoredMaterials: false
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- Raw
|
- Raw
|
||||||
@@ -998,7 +999,6 @@
|
|||||||
- type: Lathe
|
- type: Lathe
|
||||||
idleState: base_machine
|
idleState: base_machine
|
||||||
runningState: base_machine_processing
|
runningState: base_machine_processing
|
||||||
canEjectStoredMaterials: false
|
|
||||||
staticRecipes:
|
staticRecipes:
|
||||||
- MaterialSheetMeat
|
- MaterialSheetMeat
|
||||||
- SheetPaper
|
- SheetPaper
|
||||||
|
|||||||
Reference in New Issue
Block a user