Remove IRelayMoveInput (#4663)
* Remove IRelayMoveInput This interface gets called every time a movement key is pressed so it gets called a lot. * Remove RelayMovementEntityMessage Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,21 +1,15 @@
|
|||||||
using Content.Server.GameTicking;
|
|
||||||
using Content.Server.Ghost;
|
using Content.Server.Ghost;
|
||||||
using Content.Server.Mind.Components;
|
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Body.Part;
|
using Content.Shared.Body.Part;
|
||||||
using Content.Shared.Body.Slot;
|
using Content.Shared.Body.Slot;
|
||||||
using Content.Shared.MobState;
|
|
||||||
using Content.Shared.Movement.Components;
|
|
||||||
using Content.Shared.Random.Helpers;
|
using Content.Shared.Random.Helpers;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Players;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
|
||||||
namespace Content.Server.Body
|
namespace Content.Server.Body
|
||||||
@@ -23,7 +17,7 @@ namespace Content.Server.Body
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(SharedBodyComponent))]
|
[ComponentReference(typeof(SharedBodyComponent))]
|
||||||
[ComponentReference(typeof(IGhostOnMove))]
|
[ComponentReference(typeof(IGhostOnMove))]
|
||||||
public class BodyComponent : SharedBodyComponent, IRelayMoveInput, IGhostOnMove
|
public class BodyComponent : SharedBodyComponent, IGhostOnMove
|
||||||
{
|
{
|
||||||
private Container _partContainer = default!;
|
private Container _partContainer = default!;
|
||||||
|
|
||||||
@@ -89,17 +83,6 @@ namespace Content.Server.Body
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRelayMoveInput.MoveInputPressed(ICommonSession session)
|
|
||||||
{
|
|
||||||
if (Owner.TryGetComponent(out IMobStateComponent? mobState) &&
|
|
||||||
mobState.IsDead() &&
|
|
||||||
Owner.TryGetComponent(out MindComponent? mind) &&
|
|
||||||
mind.HasMind)
|
|
||||||
{
|
|
||||||
EntitySystem.Get<GameTicker>().OnGhostAttempt(mind.Mind!, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Gib(bool gibParts = false)
|
public override void Gib(bool gibParts = false)
|
||||||
{
|
{
|
||||||
base.Gib(gibParts);
|
base.Gib(gibParts);
|
||||||
|
|||||||
32
Content.Server/Body/BodySystem.cs
Normal file
32
Content.Server/Body/BodySystem.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Content.Server.GameTicking;
|
||||||
|
using Content.Server.Mind.Components;
|
||||||
|
using Content.Shared.MobState;
|
||||||
|
using Content.Shared.MobState.State;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
|
namespace Content.Server.Body
|
||||||
|
{
|
||||||
|
public sealed class BodySystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly GameTicker _ticker = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<BodyComponent, RelayMoveInputEvent>(OnRelayMoveInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRelayMoveInput(EntityUid uid, BodyComponent component, RelayMoveInputEvent args)
|
||||||
|
{
|
||||||
|
if (ComponentManager.TryGetComponent<IMobStateComponent>(uid, out var mobState) &&
|
||||||
|
mobState.IsDead() &&
|
||||||
|
ComponentManager.TryGetComponent<MindComponent>(uid, out var mind) &&
|
||||||
|
mind.HasMind)
|
||||||
|
{
|
||||||
|
_ticker.OnGhostAttempt(mind.Mind!, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,14 +4,11 @@ using Content.Server.Construction.Components;
|
|||||||
using Content.Server.Disposal.Unit.Components;
|
using Content.Server.Disposal.Unit.Components;
|
||||||
using Content.Shared.Acts;
|
using Content.Shared.Acts;
|
||||||
using Content.Shared.Disposal.Components;
|
using Content.Shared.Disposal.Components;
|
||||||
using Content.Shared.Movement;
|
|
||||||
using Content.Shared.Notification;
|
|
||||||
using Content.Shared.Notification.Managers;
|
using Content.Shared.Notification.Managers;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Server.Console;
|
using Robust.Server.Console;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -19,7 +16,6 @@ using Robust.Shared.Localization;
|
|||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Player;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
@@ -28,16 +24,14 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
{
|
{
|
||||||
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct
|
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
|
||||||
private static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
|
public static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
|
||||||
private TimeSpan _lastClang;
|
public TimeSpan LastClang;
|
||||||
|
|
||||||
private bool _connected;
|
private bool _connected;
|
||||||
private bool _broken;
|
private bool _broken;
|
||||||
[DataField("clangSound")]
|
[DataField("clangSound")] public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
|
||||||
private SoundSpecifier _clangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Container of entities that are currently inside this tube
|
/// Container of entities that are currently inside this tube
|
||||||
@@ -253,24 +247,6 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
||||||
{
|
|
||||||
base.HandleMessage(message, component);
|
|
||||||
|
|
||||||
switch (message)
|
|
||||||
{
|
|
||||||
case RelayMovementEntityMessage _:
|
|
||||||
if (_gameTiming.CurTime < _lastClang + ClangDelay)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastClang = _gameTiming.CurTime;
|
|
||||||
SoundSystem.Play(Filter.Pvs(Owner), _clangSound.GetSound(), Owner);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IBreakAct.OnBreak(BreakageEventArgs eventArgs)
|
void IBreakAct.OnBreak(BreakageEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
_broken = true; // TODO: Repair
|
_broken = true; // TODO: Repair
|
||||||
|
|||||||
@@ -1,15 +1,35 @@
|
|||||||
using Content.Server.Disposal.Tube.Components;
|
using Content.Server.Disposal.Tube.Components;
|
||||||
|
using Content.Shared.Movement;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Player;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Server.Disposal.Tube
|
namespace Content.Server.Disposal.Tube
|
||||||
{
|
{
|
||||||
public sealed class DisposalTubeSystem : EntitySystem
|
public sealed class DisposalTubeSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<DisposalTubeComponent, PhysicsBodyTypeChangedEvent>(BodyTypeChanged);
|
SubscribeLocalEvent<DisposalTubeComponent, PhysicsBodyTypeChangedEvent>(BodyTypeChanged);
|
||||||
|
SubscribeLocalEvent<DisposalTubeComponent, RelayMovementEntityEvent>(OnRelayMovement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRelayMovement(EntityUid uid, DisposalTubeComponent component, RelayMovementEntityEvent args)
|
||||||
|
{
|
||||||
|
if (_gameTiming.CurTime < component.LastClang + DisposalTubeComponent.ClangDelay)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = EntityManager.GetEntity(uid);
|
||||||
|
component.LastClang = _gameTiming.CurTime;
|
||||||
|
SoundSystem.Play(Filter.Pvs(entity), component.ClangSound.GetSound(), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BodyTypeChanged(
|
private static void BodyTypeChanged(
|
||||||
|
|||||||
@@ -10,19 +10,10 @@ namespace Content.Server.Ghost.Components
|
|||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(IGhostOnMove))]
|
[ComponentReference(typeof(IGhostOnMove))]
|
||||||
public class GhostOnMoveComponent : Component, IRelayMoveInput, IGhostOnMove
|
public class GhostOnMoveComponent : Component,IGhostOnMove
|
||||||
{
|
{
|
||||||
public override string Name => "GhostOnMove";
|
public override string Name => "GhostOnMove";
|
||||||
|
|
||||||
[DataField("canReturn")] public bool CanReturn { get; set; } = true;
|
[DataField("canReturn")] public bool CanReturn { get; set; } = true;
|
||||||
|
|
||||||
void IRelayMoveInput.MoveInputPressed(ICommonSession session)
|
|
||||||
{
|
|
||||||
// Let's not ghost if our mind is visiting...
|
|
||||||
if (Owner.HasComponent<VisitingMindComponent>()) return;
|
|
||||||
if (!Owner.TryGetComponent(out MindComponent? mind) || !mind.HasMind || mind.Mind!.IsVisitingEntity) return;
|
|
||||||
|
|
||||||
EntitySystem.Get<GameTicker>().OnGhostAttempt(mind.Mind!, CanReturn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Server.GameTicking;
|
||||||
using Content.Server.Ghost.Components;
|
using Content.Server.Ghost.Components;
|
||||||
using Content.Server.Mind.Components;
|
using Content.Server.Mind.Components;
|
||||||
using Content.Server.Players;
|
using Content.Server.Players;
|
||||||
@@ -7,6 +8,7 @@ using Content.Server.Visible;
|
|||||||
using Content.Server.Warps;
|
using Content.Server.Warps;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Ghost;
|
using Content.Shared.Ghost;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
@@ -23,6 +25,7 @@ namespace Content.Server.Ghost
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
[Dependency] private readonly GameTicker _ticker = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -36,12 +39,23 @@ namespace Content.Server.Ghost
|
|||||||
SubscribeLocalEvent<GhostComponent, MindRemovedMessage>(OnMindRemovedMessage);
|
SubscribeLocalEvent<GhostComponent, MindRemovedMessage>(OnMindRemovedMessage);
|
||||||
SubscribeLocalEvent<GhostComponent, MindUnvisitedMessage>(OnMindUnvisitedMessage);
|
SubscribeLocalEvent<GhostComponent, MindUnvisitedMessage>(OnMindUnvisitedMessage);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<GhostOnMoveComponent, RelayMoveInputEvent>(OnRelayMoveInput);
|
||||||
|
|
||||||
SubscribeNetworkEvent<GhostWarpsRequestEvent>(OnGhostWarpsRequest);
|
SubscribeNetworkEvent<GhostWarpsRequestEvent>(OnGhostWarpsRequest);
|
||||||
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
||||||
SubscribeNetworkEvent<GhostWarpToLocationRequestEvent>(OnGhostWarpToLocationRequest);
|
SubscribeNetworkEvent<GhostWarpToLocationRequestEvent>(OnGhostWarpToLocationRequest);
|
||||||
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRelayMoveInput(EntityUid uid, GhostOnMoveComponent component, RelayMoveInputEvent args)
|
||||||
|
{
|
||||||
|
// Let's not ghost if our mind is visiting...
|
||||||
|
if (ComponentManager.HasComponent<VisitingMindComponent>(uid)) return;
|
||||||
|
if (!ComponentManager.TryGetComponent<MindComponent>(uid, out var mind) || !mind.HasMind || mind.Mind!.IsVisitingEntity) return;
|
||||||
|
|
||||||
|
_ticker.OnGhostAttempt(mind.Mind!, component.CanReturn);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
|
private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
// Allow this entity to be seen by other ghosts.
|
// Allow this entity to be seen by other ghosts.
|
||||||
|
|||||||
@@ -36,11 +36,9 @@ namespace Content.Server.Medical.Components
|
|||||||
public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDestroyAct
|
public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDestroyAct
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IServerPreferencesManager _prefsManager = null!;
|
[Dependency] private readonly IServerPreferencesManager _prefsManager = null!;
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = null!;
|
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
||||||
|
|
||||||
private static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
|
public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
|
||||||
private TimeSpan _lastInternalOpenAttempt;
|
public TimeSpan LastInternalOpenAttempt;
|
||||||
|
|
||||||
private ContainerSlot _bodyContainer = default!;
|
private ContainerSlot _bodyContainer = default!;
|
||||||
private readonly Vector2 _ejectOffset = new(0f, 0f);
|
private readonly Vector2 _ejectOffset = new(0f, 0f);
|
||||||
@@ -70,31 +68,6 @@ namespace Content.Server.Medical.Components
|
|||||||
UpdateUserInterface();
|
UpdateUserInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
||||||
{
|
|
||||||
base.HandleMessage(message, component);
|
|
||||||
|
|
||||||
switch (message)
|
|
||||||
{
|
|
||||||
case RelayMovementEntityMessage msg:
|
|
||||||
{
|
|
||||||
if (EntitySystem.Get<ActionBlockerSystem>().CanInteract(msg.Entity))
|
|
||||||
{
|
|
||||||
if (_gameTiming.CurTime <
|
|
||||||
_lastInternalOpenAttempt + InternalOpenAttemptDelay)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastInternalOpenAttempt = _gameTiming.CurTime;
|
|
||||||
EjectBody();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly MedicalScannerBoundUserInterfaceState EmptyUIState =
|
private static readonly MedicalScannerBoundUserInterfaceState EmptyUIState =
|
||||||
new(
|
new(
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -1,12 +1,39 @@
|
|||||||
using Content.Server.Medical.Components;
|
using Content.Server.Medical.Components;
|
||||||
|
using Content.Shared.ActionBlocker;
|
||||||
|
using Content.Shared.Movement;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Server.Medical
|
namespace Content.Server.Medical
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal sealed class MedicalScannerSystem : EntitySystem
|
internal sealed class MedicalScannerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<MedicalScannerComponent, RelayMovementEntityEvent>(OnRelayMovement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRelayMovement(EntityUid uid, MedicalScannerComponent component, RelayMovementEntityEvent args)
|
||||||
|
{
|
||||||
|
if (_blocker.CanInteract(args.Entity))
|
||||||
|
{
|
||||||
|
if (_gameTiming.CurTime <
|
||||||
|
component.LastInternalOpenAttempt + MedicalScannerComponent.InternalOpenAttemptDelay)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
component.LastInternalOpenAttempt = _gameTiming.CurTime;
|
||||||
|
component.EjectBody();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.Hands.Components;
|
|
||||||
using Content.Server.Tools.Components;
|
using Content.Server.Tools.Components;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Acts;
|
using Content.Shared.Acts;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Movement;
|
|
||||||
using Content.Shared.Notification.Managers;
|
using Content.Shared.Notification.Managers;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Content.Shared.Placeable;
|
using Content.Shared.Placeable;
|
||||||
@@ -27,7 +25,6 @@ using Robust.Shared.Maths;
|
|||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using Robust.Shared.Timing;
|
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Server.Storage.Components
|
namespace Content.Server.Storage.Components
|
||||||
@@ -37,14 +34,12 @@ namespace Content.Server.Storage.Components
|
|||||||
[ComponentReference(typeof(IStorageComponent))]
|
[ComponentReference(typeof(IStorageComponent))]
|
||||||
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker, IExAct
|
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker, IExAct
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
||||||
|
|
||||||
public override string Name => "EntityStorage";
|
public override string Name => "EntityStorage";
|
||||||
|
|
||||||
private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage.
|
private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage.
|
||||||
|
|
||||||
private static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
|
public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
|
||||||
private TimeSpan _lastInternalOpenAttempt;
|
public TimeSpan LastInternalOpenAttempt;
|
||||||
|
|
||||||
private const int OpenMask = (int) (
|
private const int OpenMask = (int) (
|
||||||
CollisionGroup.MobImpassable |
|
CollisionGroup.MobImpassable |
|
||||||
@@ -227,7 +222,7 @@ namespace Content.Server.Storage.Components
|
|||||||
|
|
||||||
ModifyComponents();
|
ModifyComponents();
|
||||||
SoundSystem.Play(Filter.Pvs(Owner), _closeSound.GetSound(), Owner);
|
SoundSystem.Play(Filter.Pvs(Owner), _closeSound.GetSound(), Owner);
|
||||||
_lastInternalOpenAttempt = default;
|
LastInternalOpenAttempt = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OpenStorage()
|
protected virtual void OpenStorage()
|
||||||
@@ -313,29 +308,6 @@ namespace Content.Server.Storage.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
||||||
{
|
|
||||||
base.HandleMessage(message, component);
|
|
||||||
|
|
||||||
switch (message)
|
|
||||||
{
|
|
||||||
case RelayMovementEntityMessage msg:
|
|
||||||
if (msg.Entity.HasComponent<HandsComponent>())
|
|
||||||
{
|
|
||||||
if (_gameTiming.CurTime <
|
|
||||||
_lastInternalOpenAttempt + InternalOpenAttemptDelay)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastInternalOpenAttempt = _gameTiming.CurTime;
|
|
||||||
TryOpenStorage(msg.Entity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool TryOpenStorage(IEntity user)
|
public virtual bool TryOpenStorage(IEntity user)
|
||||||
{
|
{
|
||||||
if (!CanOpen(user)) return false;
|
if (!CanOpen(user)) return false;
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.Hands.Components;
|
||||||
using Content.Server.Interaction;
|
using Content.Server.Interaction;
|
||||||
using Content.Server.Storage.Components;
|
using Content.Server.Storage.Components;
|
||||||
|
using Content.Shared.Movement;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Server.Storage.EntitySystems
|
namespace Content.Server.Storage.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal sealed class StorageSystem : EntitySystem
|
internal sealed class StorageSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
|
||||||
private readonly List<IPlayerSession> _sessionCache = new();
|
private readonly List<IPlayerSession> _sessionCache = new();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -20,6 +26,22 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
|
|
||||||
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
|
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
|
||||||
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
|
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
|
||||||
|
SubscribeLocalEvent<EntityStorageComponent, RelayMovementEntityEvent>(OnRelayMovement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRelayMovement(EntityUid uid, EntityStorageComponent component, RelayMovementEntityEvent args)
|
||||||
|
{
|
||||||
|
if (ComponentManager.HasComponent<HandsComponent>(uid))
|
||||||
|
{
|
||||||
|
if (_gameTiming.CurTime <
|
||||||
|
component.LastInternalOpenAttempt + EntityStorageComponent.InternalOpenAttemptDelay)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
component.LastInternalOpenAttempt = _gameTiming.CurTime;
|
||||||
|
component.TryOpenStorage(args.Entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using Robust.Shared.Players;
|
|
||||||
|
|
||||||
namespace Content.Shared.Movement.Components
|
|
||||||
{
|
|
||||||
public interface IRelayMoveInput
|
|
||||||
{
|
|
||||||
void MoveInputPressed(ICommonSession session);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,7 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
private void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
||||||
{
|
{
|
||||||
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||||
return;
|
return;
|
||||||
@@ -50,19 +50,13 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
|
|
||||||
if (owner != null && session != null)
|
if (owner != null && session != null)
|
||||||
{
|
{
|
||||||
foreach (var comp in owner.GetAllComponents<IRelayMoveInput>().ToArray())
|
EntityManager.EventBus.RaiseLocalEvent(owner.Uid, new RelayMoveInputEvent(session));
|
||||||
{
|
|
||||||
comp.MoveInputPressed(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For stuff like "Moving out of locker" or the likes
|
// For stuff like "Moving out of locker" or the likes
|
||||||
if (owner.IsInContainer() &&
|
if (owner.IsInContainer() &&
|
||||||
(!owner.TryGetComponent(out IMobStateComponent? mobState) ||
|
(!owner.TryGetComponent(out IMobStateComponent? mobState) ||
|
||||||
mobState.IsAlive()))
|
mobState.IsAlive()))
|
||||||
{
|
{
|
||||||
var relayEntityMoveMessage = new RelayMovementEntityMessage(owner);
|
|
||||||
owner.Transform.Parent!.Owner.SendMessage(owner.Transform, relayEntityMoveMessage);
|
|
||||||
|
|
||||||
var relayMoveEvent = new RelayMovementEntityEvent(owner);
|
var relayMoveEvent = new RelayMovementEntityEvent(owner);
|
||||||
owner.EntityManager.EventBus.RaiseLocalEvent(owner.Transform.ParentUid, relayMoveEvent);
|
owner.EntityManager.EventBus.RaiseLocalEvent(owner.Transform.ParentUid, relayMoveEvent);
|
||||||
}
|
}
|
||||||
@@ -114,7 +108,7 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleDirChange(session, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
Get<SharedMoverSystem>().HandleDirChange(session, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,4 +127,14 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class RelayMoveInputEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public ICommonSession Session { get; }
|
||||||
|
|
||||||
|
public RelayMoveInputEvent(ICommonSession session)
|
||||||
|
{
|
||||||
|
Session = session;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
Content.Shared/Movement/RelayMovementEntityEvent.cs
Normal file
14
Content.Shared/Movement/RelayMovementEntityEvent.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Shared.Movement
|
||||||
|
{
|
||||||
|
public sealed class RelayMovementEntityEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public IEntity Entity { get; }
|
||||||
|
|
||||||
|
public RelayMovementEntityEvent(IEntity entity)
|
||||||
|
{
|
||||||
|
Entity = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
using System;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
|
|
||||||
namespace Content.Shared.Movement
|
|
||||||
{
|
|
||||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
|
||||||
public class RelayMovementEntityMessage : ComponentMessage
|
|
||||||
{
|
|
||||||
[PublicAPI]
|
|
||||||
public readonly IEntity Entity;
|
|
||||||
|
|
||||||
public RelayMovementEntityMessage(IEntity entity)
|
|
||||||
{
|
|
||||||
Entity = entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RelayMovementEntityEvent : EntityEventArgs
|
|
||||||
{
|
|
||||||
public IEntity Entity { get; }
|
|
||||||
|
|
||||||
public RelayMovementEntityEvent(IEntity entity)
|
|
||||||
{
|
|
||||||
Entity = entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Shared.ActionBlocker;
|
|
||||||
using Content.Shared.Alert;
|
|
||||||
using Content.Shared.Movement;
|
|
||||||
using Content.Shared.Movement.Components;
|
|
||||||
using Content.Shared.Physics.Pull;
|
using Content.Shared.Physics.Pull;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -17,7 +13,7 @@ using Robust.Shared.Serialization;
|
|||||||
namespace Content.Shared.Pulling.Components
|
namespace Content.Shared.Pulling.Components
|
||||||
{
|
{
|
||||||
[NetworkedComponent()]
|
[NetworkedComponent()]
|
||||||
public abstract class SharedPullableComponent : Component, IRelayMoveInput
|
public abstract class SharedPullableComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "Pullable";
|
public override string Name => "Pullable";
|
||||||
|
|
||||||
@@ -348,14 +344,6 @@ namespace Content.Shared.Pulling.Components
|
|||||||
|
|
||||||
base.OnRemove();
|
base.OnRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need a component bus relay so all entities can use this and not just players
|
|
||||||
void IRelayMoveInput.MoveInputPressed(ICommonSession session)
|
|
||||||
{
|
|
||||||
var entity = session.AttachedEntity;
|
|
||||||
if (entity == null || !EntitySystem.Get<ActionBlockerSystem>().CanMove(entity)) return;
|
|
||||||
TryStopPull();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
26
Content.Shared/Pulling/Systems/SharedPullableSystem.cs
Normal file
26
Content.Shared/Pulling/Systems/SharedPullableSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Content.Shared.ActionBlocker;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Content.Shared.Pulling.Components;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
|
namespace Content.Shared.Pulling.Systems
|
||||||
|
{
|
||||||
|
public class SharedPullableSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<SharedPullableComponent, RelayMoveInputEvent>(OnRelayMoveInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args)
|
||||||
|
{
|
||||||
|
var entity = args.Session.AttachedEntity;
|
||||||
|
if (entity == null || !_blocker.CanMove(entity)) return;
|
||||||
|
component.TryStopPull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user