Files

50 lines
1.8 KiB
C#
Raw Permalink Normal View History

2022-08-05 00:22:37 -04:00
using Content.Server.Popups;
using Content.Server.Shuttles.Components;
using Content.Server.Singularity.Events;
2022-08-05 00:22:37 -04:00
using Content.Shared.Popups;
using Content.Shared.Singularity.Components;
2022-08-05 00:22:37 -04:00
using Content.Shared.Throwing;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
2022-08-05 00:22:37 -04:00
namespace Content.Server.Singularity.EntitySystems;
public sealed class ContainmentFieldSystem : EntitySystem
{
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ContainmentFieldComponent, StartCollideEvent>(HandleFieldCollide);
SubscribeLocalEvent<ContainmentFieldComponent, EventHorizonAttemptConsumeEntityEvent>(HandleEventHorizon);
2022-08-05 00:22:37 -04:00
}
private void HandleFieldCollide(EntityUid uid, ContainmentFieldComponent component, ref StartCollideEvent args)
2022-08-05 00:22:37 -04:00
{
var otherBody = args.OtherEntity;
2022-08-05 00:22:37 -04:00
if (HasComp<SpaceGarbageComponent>(otherBody))
2022-08-05 00:22:37 -04:00
{
_popupSystem.PopupEntity(Loc.GetString("comp-field-vaporized", ("entity", otherBody)), uid, PopupType.LargeCaution);
QueueDel(otherBody);
2022-08-05 00:22:37 -04:00
}
if (TryComp<PhysicsComponent>(otherBody, out var physics) && physics.Mass <= component.MaxMass && physics.Hard)
{
var fieldDir = Transform(uid).WorldPosition;
var playerDir = Transform(otherBody).WorldPosition;
2022-08-05 00:22:37 -04:00
_throwing.TryThrow(otherBody, playerDir-fieldDir, strength: component.ThrowForce);
}
}
private void HandleEventHorizon(EntityUid uid, ContainmentFieldComponent component, ref EventHorizonAttemptConsumeEntityEvent args)
{
if(!args.Cancelled && !args.EventHorizon.CanBreachContainment)
args.Cancelled = true;
}
2022-08-05 00:22:37 -04:00
}