mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Cleanup: Modernize MaterialReclaimerSystem (#46281)
* MaterialReclaimerSystem: cleanup * more cleanup --------- Co-authored-by: Pok245 <113675512+Pok27@users.noreply.github.com>
This commit is contained in:
parent
e91add1eae
commit
a257d91f5f
2 changed files with 43 additions and 58 deletions
|
|
@ -2,7 +2,6 @@ using Content.Server.Administration.Logs;
|
|||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Ghost;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Damage.Systems;
|
||||
|
|
@ -28,31 +27,18 @@ namespace Content.Server.Materials;
|
|||
public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
|
||||
{
|
||||
[Dependency] private AppearanceSystem _appearance = default!;
|
||||
[Dependency] private GhostSystem _ghostSystem = default!;
|
||||
[Dependency] private GhostSystem _ghost = default!;
|
||||
[Dependency] private MaterialStorageSystem _materialStorage = default!;
|
||||
[Dependency] private PopupSystem _popup = default!;
|
||||
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
|
||||
[Dependency] private GibbingSystem _gibbing = default!;
|
||||
[Dependency] private PuddleSystem _puddle = default!;
|
||||
[Dependency] private StackSystem _stack = default!;
|
||||
[Dependency] private SharedMindSystem _mind = default!;
|
||||
[Dependency] private IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private SharedDestructibleSystem _destructible = default!;
|
||||
[Dependency] private DamageableSystem _damage = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, SuicideByEnvironmentEvent>(OnSuicideByEnvironment);
|
||||
SubscribeLocalEvent<ActiveMaterialReclaimerComponent, PowerChangedEvent>(OnActivePowerChanged);
|
||||
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, BreakageEventArgs>(OnBreakage);
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, RepairedEvent>(OnRepaired);
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnPowerChanged(Entity<MaterialReclaimerComponent> entity, ref PowerChangedEvent args)
|
||||
{
|
||||
AmbientSound.SetAmbience(entity.Owner, entity.Comp.Enabled && args.Powered);
|
||||
|
|
@ -60,6 +46,7 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
Dirty(entity);
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnSuicideByEnvironment(Entity<MaterialReclaimerComponent> entity, ref SuicideByEnvironmentEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
|
|
@ -69,7 +56,7 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
if (TryComp(victim, out ActorComponent? actor) &&
|
||||
_mind.TryGetMind(actor.PlayerSession, out var mindId, out var mind))
|
||||
{
|
||||
_ghostSystem.OnGhostAttempt(mindId, false, mind: mind);
|
||||
_ghost.OnGhostAttempt(mindId, false, mind: mind);
|
||||
if (mind.OwnedEntity is { Valid: true } suicider)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("recycler-component-suicide-message"), suicider);
|
||||
|
|
@ -87,12 +74,14 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
args.Handled = true;
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnActivePowerChanged(Entity<ActiveMaterialReclaimerComponent> entity, ref PowerChangedEvent args)
|
||||
{
|
||||
if (!args.Powered)
|
||||
TryFinishProcessItem(entity, null, entity.Comp);
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnBreakage(Entity<MaterialReclaimerComponent> ent, ref BreakageEventArgs args)
|
||||
{
|
||||
//un-emags itself when it breaks
|
||||
|
|
@ -100,6 +89,7 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
SetBroken(ent, true);
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnRepaired(Entity<MaterialReclaimerComponent> ent, ref RepairedEvent args)
|
||||
{
|
||||
SetBroken(ent, false);
|
||||
|
|
@ -133,7 +123,7 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
Dirty(uid, component);
|
||||
|
||||
// scales the output if the process was interrupted.
|
||||
var completion = 1f - Math.Clamp((float) Math.Round((active.EndTime - Timing.CurTime) / active.Duration),
|
||||
var completion = 1f - Math.Clamp((float)Math.Round((active.EndTime - Timing.CurTime) / active.Duration),
|
||||
0f,
|
||||
1f);
|
||||
Reclaim(uid, item, completion, component);
|
||||
|
|
@ -159,10 +149,7 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
|
||||
if (CanDamageAndGib(uid, item, component))
|
||||
{
|
||||
var didBloody = false;
|
||||
|
||||
if (component.DamageOnEmag is not null && _damage.TryChangeDamage(item, component.DamageOnEmag, false)) // It shouldn't ignore resistance
|
||||
didBloody = true;
|
||||
var didBloody = component.DamageOnEmag is not null && _damage.TryChangeDamage(item, component.DamageOnEmag); // It shouldn't ignore resistance
|
||||
|
||||
if (_destructible.CanDestroy(item) && component.GibOnEmag)
|
||||
{
|
||||
|
|
@ -204,7 +191,7 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
|
|||
|
||||
foreach (var (material, amount) in composition.MaterialComposition)
|
||||
{
|
||||
var outputAmount = (int) (amount * efficiency * modifier);
|
||||
var outputAmount = (int)(amount * efficiency * modifier);
|
||||
_materialStorage.TryChangeMaterialAmount(reclaimer, material, outputAmount, storage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Linq;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Body;
|
||||
|
|
@ -17,7 +18,6 @@ using Robust.Shared.Containers;
|
|||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Shared.Materials;
|
||||
|
||||
|
|
@ -27,30 +27,22 @@ namespace Content.Shared.Materials;
|
|||
/// </summary>
|
||||
public abstract partial class SharedMaterialReclaimerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private EmagSystem _emag = default!;
|
||||
[Dependency] private EntityWhitelistSystem _whitelist = default!;
|
||||
[Dependency] private ISharedAdminLogManager _adminLog = default!;
|
||||
[Dependency] private OpenableSystem _openable = default!;
|
||||
[Dependency] private SharedAudioSystem _audio = default!;
|
||||
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
|
||||
[Dependency] protected IGameTiming Timing = default!;
|
||||
[Dependency] protected SharedAmbientSoundSystem AmbientSound = default!;
|
||||
[Dependency] private SharedAudioSystem _audio = default!;
|
||||
[Dependency] protected SharedContainerSystem Container = default!;
|
||||
[Dependency] private EntityWhitelistSystem _whitelistSystem = default!;
|
||||
[Dependency] private EmagSystem _emag = default!;
|
||||
[Dependency] private OpenableSystem _openable = default!;
|
||||
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
|
||||
|
||||
[Dependency] private EntityQuery<MaterialReclaimerComponent> _materialReclaimerQuery;
|
||||
[Dependency] private EntityQuery<SolutionTransferComponent> _solutionTransferQuery;
|
||||
|
||||
public const string ActiveReclaimerContainerId = "active-material-reclaimer-container";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, GotEmaggedEvent>(OnEmagged);
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<CollideMaterialReclaimerComponent, StartCollideEvent>(OnCollide);
|
||||
SubscribeLocalEvent<ActiveMaterialReclaimerComponent, ComponentStartup>(OnActiveStartup);
|
||||
SubscribeLocalEvent<MaterialReclaimerComponent, InteractUsingEvent>(OnInteractUsing,
|
||||
before: [typeof(SolutionTransferSystem), typeof(AnchorableSystem)]);
|
||||
}
|
||||
[SubscribeLocalEvent(before: [typeof(SolutionTransferSystem), typeof(AnchorableSystem)])]
|
||||
private void OnInteractUsing(Entity<MaterialReclaimerComponent> entity, ref InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
|
|
@ -64,7 +56,7 @@ public abstract partial class SharedMaterialReclaimerSystem : EntitySystem
|
|||
if (_openable.IsClosed(args.Used))
|
||||
return;
|
||||
|
||||
if (TryComp<SolutionTransferComponent>(args.Used, out var transfer) &&
|
||||
if (_solutionTransferQuery.TryComp(args.Used, out var transfer) &&
|
||||
transfer.CanSend)
|
||||
return;
|
||||
}
|
||||
|
|
@ -73,44 +65,50 @@ public abstract partial class SharedMaterialReclaimerSystem : EntitySystem
|
|||
args.Handled = TryStartProcessItem(entity.Owner, args.Used, entity.Comp, args.User);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, MaterialReclaimerComponent component, MapInitEvent args)
|
||||
[SubscribeLocalEvent]
|
||||
private void OnMapInit(Entity<MaterialReclaimerComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
component.NextSound = Timing.CurTime;
|
||||
ent.Comp.NextSound = Timing.CurTime;
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, MaterialReclaimerComponent component, ComponentShutdown args)
|
||||
[SubscribeLocalEvent]
|
||||
private void OnShutdown(Entity<MaterialReclaimerComponent> ent, ref ComponentShutdown args)
|
||||
{
|
||||
_audio.Stop(component.Stream);
|
||||
_audio.Stop(ent.Comp.Stream);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, MaterialReclaimerComponent component, ExaminedEvent args)
|
||||
[SubscribeLocalEvent]
|
||||
private void OnExamined(Entity<MaterialReclaimerComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("recycler-count-items", ("items", component.ItemsProcessed)));
|
||||
args.PushMarkup(Loc.GetString("recycler-count-items", ("items", ent.Comp.ItemsProcessed)));
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, MaterialReclaimerComponent component, ref GotEmaggedEvent args)
|
||||
[SubscribeLocalEvent]
|
||||
private void OnEmagged(Entity<MaterialReclaimerComponent> ent, ref GotEmaggedEvent args)
|
||||
{
|
||||
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
|
||||
return;
|
||||
|
||||
if (_emag.CheckFlag(uid, EmagType.Interaction))
|
||||
if (_emag.CheckFlag(ent, EmagType.Interaction))
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnCollide(EntityUid uid, CollideMaterialReclaimerComponent component, ref StartCollideEvent args)
|
||||
[SubscribeLocalEvent]
|
||||
private void OnCollide(Entity<CollideMaterialReclaimerComponent> ent, ref StartCollideEvent args)
|
||||
{
|
||||
if (args.OurFixtureId != component.FixtureId)
|
||||
if (args.OurFixtureId != ent.Comp.FixtureId)
|
||||
return;
|
||||
if (!TryComp<MaterialReclaimerComponent>(uid, out var reclaimer))
|
||||
if (!_materialReclaimerQuery.TryComp(ent, out var reclaimer))
|
||||
return;
|
||||
TryStartProcessItem(uid, args.OtherEntity, reclaimer);
|
||||
TryStartProcessItem(ent, args.OtherEntity, reclaimer);
|
||||
}
|
||||
|
||||
private void OnActiveStartup(EntityUid uid, ActiveMaterialReclaimerComponent component, ComponentStartup args)
|
||||
[SubscribeLocalEvent]
|
||||
private void OnActiveStartup(Entity<ActiveMaterialReclaimerComponent> ent, ref ComponentStartup args)
|
||||
{
|
||||
component.ReclaimingContainer = Container.EnsureContainer<Container>(uid, ActiveReclaimerContainerId);
|
||||
ent.Comp.ReclaimingContainer = Container.EnsureContainer<Container>(ent, ActiveReclaimerContainerId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -127,8 +125,8 @@ public abstract partial class SharedMaterialReclaimerSystem : EntitySystem
|
|||
if (HasComp<MobStateComponent>(item) && !CanDamageAndGib(uid, item, component)) // whitelist? We be gibbing, boy!
|
||||
return false;
|
||||
|
||||
if (_whitelistSystem.IsWhitelistFail(component.Whitelist, item) ||
|
||||
_whitelistSystem.IsWhitelistPass(component.Blacklist, item))
|
||||
if (_whitelist.IsWhitelistFail(component.Whitelist, item) ||
|
||||
_whitelist.IsWhitelistPass(component.Blacklist, item))
|
||||
return false;
|
||||
|
||||
if (Container.TryGetContainingContainer((item, null, null), out _) && !Container.TryRemoveFromContainer(item))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue