Make the material ejection control completely generic (#23308)
* Finish decoupling material ejection from lathes * commented
This commit is contained in:
@@ -5,10 +5,10 @@ using Content.Shared.Popups;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Database;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -22,6 +22,7 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
{
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly StackSystem _stackSystem = default!;
|
||||
@@ -31,7 +32,7 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
|
||||
|
||||
SubscribeLocalEvent<MaterialStorageComponent, EjectMaterialMessage>(OnEjectMessage);
|
||||
SubscribeAllEvent<EjectMaterialMessage>(OnEjectMessage);
|
||||
}
|
||||
|
||||
private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args)
|
||||
@@ -45,9 +46,23 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEjectMessage(EntityUid uid, MaterialStorageComponent component, EjectMaterialMessage message)
|
||||
private void OnEjectMessage(EjectMaterialMessage msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!component.CanEjectStoredMaterials || !_prototypeManager.TryIndex<MaterialPrototype>(message.Material, out var material))
|
||||
if (args.SenderSession.AttachedEntity is not { } player)
|
||||
return;
|
||||
|
||||
var uid = GetEntity(msg.Entity);
|
||||
|
||||
if (!TryComp<MaterialStorageComponent>(uid, out var component))
|
||||
return;
|
||||
|
||||
if (!Exists(uid))
|
||||
return;
|
||||
|
||||
if (!_actionBlocker.CanInteract(player, uid))
|
||||
return;
|
||||
|
||||
if (!component.CanEjectStoredMaterials || !_prototypeManager.TryIndex<MaterialPrototype>(msg.Material, out var material))
|
||||
return;
|
||||
|
||||
var volume = 0;
|
||||
@@ -57,13 +72,13 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
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));
|
||||
var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == msg.Material).Value;
|
||||
var sheetsToExtract = Math.Min(msg.SheetsToExtract, _stackSystem.GetMaxCount(material.StackEntity));
|
||||
|
||||
volume = sheetsToExtract * volumePerSheet;
|
||||
}
|
||||
|
||||
if (volume <= 0 || !TryChangeMaterialAmount(uid, message.Material, -volume))
|
||||
if (volume <= 0 || !TryChangeMaterialAmount(uid, msg.Material, -volume))
|
||||
return;
|
||||
|
||||
var mats = SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out _);
|
||||
@@ -121,7 +136,7 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
overflowMaterial = 0;
|
||||
if (!_prototypeManager.TryIndex<MaterialPrototype>(material, out var stackType))
|
||||
{
|
||||
Logger.Error("Failed to index material prototype " + material);
|
||||
Log.Error("Failed to index material prototype " + material);
|
||||
return new List<EntityUid>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user