Files
OldThink/Content.Shared/Pulling/Systems/SharedPullerSystem.cs

78 lines
2.6 KiB
C#
Raw Normal View History

2021-07-31 03:14:00 +02:00
using Content.Shared.Alert;
using Content.Shared.Hands;
using Content.Shared.Movement.Components;
2021-07-31 03:14:00 +02:00
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
2021-07-31 03:14:00 +02:00
namespace Content.Shared.Pulling.Systems
2021-07-31 03:14:00 +02:00
{
[UsedImplicitly]
public sealed class SharedPullerSystem : EntitySystem
{
[Dependency] private readonly SharedPullingSystem _pullSystem = default!;
2021-07-31 03:14:00 +02:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedPullerComponent, PullStartedMessage>(PullerHandlePullStarted);
SubscribeLocalEvent<SharedPullerComponent, PullStoppedMessage>(PullerHandlePullStopped);
SubscribeLocalEvent<SharedPullerComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
}
private void OnVirtualItemDeleted(EntityUid uid, SharedPullerComponent component, VirtualItemDeletedEvent args)
{
if (component.Pulling == null)
return;
2021-09-21 00:13:03 +10:00
if (component.Pulling == EntityManager.GetEntity(args.BlockingEntity))
{
if (EntityManager.TryGetComponent<SharedPullableComponent>(args.BlockingEntity, out var comp))
{
_pullSystem.TryStopPull(comp, EntityManager.GetEntity(uid));
}
}
2021-07-31 03:14:00 +02:00
}
private static void PullerHandlePullStarted(
EntityUid uid,
SharedPullerComponent component,
PullStartedMessage args)
{
if (args.Puller.Owner.Uid != uid)
return;
if (component.Owner.TryGetComponent(out SharedAlertsComponent? alerts))
alerts.ShowAlert(AlertType.Pulling);
RefreshMovementSpeed(component);
2021-07-31 03:14:00 +02:00
}
private static void PullerHandlePullStopped(
EntityUid uid,
SharedPullerComponent component,
PullStoppedMessage args)
{
if (args.Puller.Owner.Uid != uid)
return;
if (component.Owner.TryGetComponent(out SharedAlertsComponent? alerts))
alerts.ClearAlert(AlertType.Pulling);
RefreshMovementSpeed(component);
}
private static void RefreshMovementSpeed(SharedPullerComponent component)
{
// Before changing how this is updated, please see SharedPullerComponent
if (component.Owner.TryGetComponent<MovementSpeedModifierComponent>(out var speed))
{
speed.RefreshMovementSpeedModifiers();
}
2021-07-31 03:14:00 +02:00
}
}
}