2022-07-16 13:51:52 +10:00
|
|
|
using Content.Shared.Movement.Components;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Movement.Systems;
|
|
|
|
|
|
|
|
|
|
public abstract partial class SharedMoverController
|
|
|
|
|
{
|
|
|
|
|
private void InitializeRelay()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<RelayInputMoverComponent, ComponentShutdown>(OnRelayShutdown);
|
2022-12-12 00:18:25 +11:00
|
|
|
SubscribeLocalEvent<MovementRelayTargetComponent, ComponentShutdown>(OnTargetRelayShutdown);
|
2023-05-13 02:02:50 +12:00
|
|
|
SubscribeLocalEvent<MovementRelayTargetComponent, AfterAutoHandleStateEvent>(OnAfterRelayTargetState);
|
|
|
|
|
SubscribeLocalEvent<RelayInputMoverComponent, AfterAutoHandleStateEvent>(OnAfterRelayState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAfterRelayTargetState(EntityUid uid, MovementRelayTargetComponent component, ref AfterAutoHandleStateEvent args)
|
|
|
|
|
{
|
|
|
|
|
Physics.UpdateIsPredicted(uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAfterRelayState(EntityUid uid, RelayInputMoverComponent component, ref AfterAutoHandleStateEvent args)
|
|
|
|
|
{
|
|
|
|
|
Physics.UpdateIsPredicted(uid);
|
2022-07-16 13:51:52 +10:00
|
|
|
}
|
|
|
|
|
|
2022-10-04 15:49:46 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the relay entity and marks the component as dirty. This only exists because people have previously
|
|
|
|
|
/// forgotten to Dirty(), so fuck you, you have to use this method now.
|
|
|
|
|
/// </summary>
|
2023-05-13 02:02:50 +12:00
|
|
|
public void SetRelay(EntityUid uid, EntityUid relayEntity)
|
2022-10-04 15:49:46 +13:00
|
|
|
{
|
2022-11-15 13:45:25 +13:00
|
|
|
if (uid == relayEntity)
|
|
|
|
|
{
|
2023-06-27 23:56:52 +10:00
|
|
|
Log.Error($"An entity attempted to relay movement to itself. Entity:{ToPrettyString(uid)}");
|
2022-11-15 13:45:25 +13:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
var component = EnsureComp<RelayInputMoverComponent>(uid);
|
|
|
|
|
if (component.RelayEntity == relayEntity)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (TryComp(component.RelayEntity, out MovementRelayTargetComponent? oldTarget))
|
2022-12-12 00:18:25 +11:00
|
|
|
{
|
2023-05-13 02:02:50 +12:00
|
|
|
oldTarget.Source = EntityUid.Invalid;
|
|
|
|
|
RemComp(component.RelayEntity, oldTarget);
|
|
|
|
|
Physics.UpdateIsPredicted(component.RelayEntity);
|
|
|
|
|
}
|
2022-12-12 00:18:25 +11:00
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
var targetComp = EnsureComp<MovementRelayTargetComponent>(relayEntity);
|
|
|
|
|
if (TryComp(targetComp.Source, out RelayInputMoverComponent? oldRelay))
|
|
|
|
|
{
|
|
|
|
|
oldRelay.RelayEntity = EntityUid.Invalid;
|
|
|
|
|
RemComp(targetComp.Source, oldRelay);
|
|
|
|
|
Physics.UpdateIsPredicted(targetComp.Source);
|
2022-12-12 00:18:25 +11:00
|
|
|
}
|
|
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
Physics.UpdateIsPredicted(uid);
|
|
|
|
|
Physics.UpdateIsPredicted(relayEntity);
|
2022-10-04 15:49:46 +13:00
|
|
|
component.RelayEntity = relayEntity;
|
2023-05-13 02:02:50 +12:00
|
|
|
targetComp.Source = uid;
|
2024-02-13 22:48:39 +01:00
|
|
|
Dirty(uid, component);
|
|
|
|
|
Dirty(relayEntity, targetComp);
|
2022-10-04 15:49:46 +13:00
|
|
|
}
|
|
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
private void OnRelayShutdown(EntityUid uid, RelayInputMoverComponent component, ComponentShutdown args)
|
|
|
|
|
{
|
2023-05-13 02:02:50 +12:00
|
|
|
Physics.UpdateIsPredicted(uid);
|
|
|
|
|
Physics.UpdateIsPredicted(component.RelayEntity);
|
2022-07-16 13:51:52 +10:00
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
|
|
|
|
SetMoveInput(inputMover, MoveButtons.None);
|
2022-07-16 13:51:52 +10:00
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
if (Timing.ApplyingState)
|
|
|
|
|
return;
|
2022-07-16 13:51:52 +10:00
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
if (TryComp(component.RelayEntity, out MovementRelayTargetComponent? target) && target.LifeStage <= ComponentLifeStage.Running)
|
|
|
|
|
RemComp(component.RelayEntity, target);
|
2022-07-16 13:51:52 +10:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 00:18:25 +11:00
|
|
|
private void OnTargetRelayShutdown(EntityUid uid, MovementRelayTargetComponent component, ComponentShutdown args)
|
|
|
|
|
{
|
2023-05-13 02:02:50 +12:00
|
|
|
Physics.UpdateIsPredicted(uid);
|
|
|
|
|
Physics.UpdateIsPredicted(component.Source);
|
2022-12-12 00:18:25 +11:00
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
if (Timing.ApplyingState)
|
2022-12-12 00:18:25 +11:00
|
|
|
return;
|
|
|
|
|
|
2023-05-13 02:02:50 +12:00
|
|
|
if (TryComp(component.Source, out RelayInputMoverComponent? relay) && relay.LifeStage <= ComponentLifeStage.Running)
|
|
|
|
|
RemComp(component.Source, relay);
|
2022-12-12 00:18:25 +11:00
|
|
|
}
|
2022-07-16 13:51:52 +10:00
|
|
|
}
|