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:
Hannah Giovanna Dawson
2023-12-31 01:08:33 +00:00
committed by GitHub
parent ec82a05df9
commit f850047341
7 changed files with 58 additions and 62 deletions

View File

@@ -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)
@@ -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)