1
0

ContainmentFieldSystem.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Server.Popups;
  2. using Content.Server.Singularity.Events;
  3. using Content.Shared.Shuttles.Components;
  4. using Content.Shared.Popups;
  5. using Content.Shared.Singularity.Components;
  6. using Content.Shared.Throwing;
  7. using Robust.Shared.Physics.Components;
  8. using Robust.Shared.Physics.Events;
  9. namespace Content.Server.Singularity.EntitySystems;
  10. public sealed class ContainmentFieldSystem : EntitySystem
  11. {
  12. [Dependency] private readonly ThrowingSystem _throwing = default!;
  13. [Dependency] private readonly PopupSystem _popupSystem = default!;
  14. [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<ContainmentFieldComponent, StartCollideEvent>(HandleFieldCollide);
  19. SubscribeLocalEvent<ContainmentFieldComponent, EventHorizonAttemptConsumeEntityEvent>(HandleEventHorizon);
  20. }
  21. private void HandleFieldCollide(EntityUid uid, ContainmentFieldComponent component, ref StartCollideEvent args)
  22. {
  23. var otherBody = args.OtherEntity;
  24. if (component.DestroyGarbage && HasComp<SpaceGarbageComponent>(otherBody))
  25. {
  26. _popupSystem.PopupEntity(Loc.GetString("comp-field-vaporized", ("entity", otherBody)), uid, PopupType.LargeCaution);
  27. QueueDel(otherBody);
  28. }
  29. if (TryComp<PhysicsComponent>(otherBody, out var physics) && physics.Mass <= component.MaxMass && physics.Hard)
  30. {
  31. var fieldDir = _transformSystem.GetWorldPosition(uid);
  32. var playerDir = _transformSystem.GetWorldPosition(otherBody);
  33. _throwing.TryThrow(otherBody, playerDir-fieldDir, baseThrowSpeed: component.ThrowForce);
  34. }
  35. }
  36. private void HandleEventHorizon(EntityUid uid, ContainmentFieldComponent component, ref EventHorizonAttemptConsumeEntityEvent args)
  37. {
  38. if(!args.Cancelled && !args.EventHorizon.CanBreachContainment)
  39. args.Cancelled = true;
  40. }
  41. }