Improve hands & pulling (#4389)
This commit is contained in:
committed by
GitHub
parent
73e4946e27
commit
632e72b817
@@ -50,6 +50,8 @@ namespace Content.Shared.Pulling.Components
|
||||
return;
|
||||
}
|
||||
|
||||
var eventBus = Owner.EntityManager.EventBus;
|
||||
|
||||
// New value. Abandon being pulled by any existing object.
|
||||
if (_puller != null)
|
||||
{
|
||||
@@ -64,10 +66,9 @@ namespace Content.Shared.Pulling.Components
|
||||
{
|
||||
var message = new PullStoppedMessage(oldPullerPhysics, _physics);
|
||||
|
||||
oldPuller.SendMessage(null, message);
|
||||
Owner.SendMessage(null, message);
|
||||
eventBus.RaiseLocalEvent(oldPuller.Uid, message, broadcast: false);
|
||||
eventBus.RaiseLocalEvent(Owner.Uid, message);
|
||||
|
||||
oldPuller.EntityManager.EventBus.RaiseEvent(EventSource.Local, message);
|
||||
_physics.WakeBody();
|
||||
}
|
||||
// else-branch warning is handled below
|
||||
@@ -125,14 +126,14 @@ namespace Content.Shared.Pulling.Components
|
||||
|
||||
var pullAttempt = new PullAttemptMessage(pullerPhysics, _physics);
|
||||
|
||||
value.SendMessage(null, pullAttempt);
|
||||
eventBus.RaiseLocalEvent(value.Uid, pullAttempt, broadcast: false);
|
||||
|
||||
if (pullAttempt.Cancelled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.SendMessage(null, pullAttempt);
|
||||
eventBus.RaiseLocalEvent(Owner.Uid, pullAttempt);
|
||||
|
||||
if (pullAttempt.Cancelled)
|
||||
{
|
||||
@@ -147,10 +148,8 @@ namespace Content.Shared.Pulling.Components
|
||||
|
||||
var message = new PullStartedMessage(PullerPhysics, _physics);
|
||||
|
||||
_puller.SendMessage(null, message);
|
||||
Owner.SendMessage(null, message);
|
||||
|
||||
_puller.EntityManager.EventBus.RaiseEvent(EventSource.Local, message);
|
||||
eventBus.RaiseLocalEvent(_puller.Uid, message, broadcast: false);
|
||||
eventBus.RaiseLocalEvent(Owner.Uid, message);
|
||||
|
||||
var union = PullerPhysics.GetWorldAABB().Union(_physics.GetWorldAABB());
|
||||
var length = Math.Max(union.Size.X, union.Size.Y) * 0.75f;
|
||||
@@ -335,29 +334,6 @@ namespace Content.Shared.Pulling.Components
|
||||
Puller = entity;
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
if (message is not PullMessage pullMessage ||
|
||||
pullMessage.Pulled.Owner != Owner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pulledStatus = Owner.GetComponentOrNull<SharedAlertsComponent>();
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case PullStartedMessage:
|
||||
pulledStatus?.ShowAlert(AlertType.Pulled);
|
||||
break;
|
||||
case PullStoppedMessage:
|
||||
pulledStatus?.ClearAlert(AlertType.Pulled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnRemove()
|
||||
{
|
||||
TryStopPull();
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Component = Robust.Shared.GameObjects.Component;
|
||||
|
||||
@@ -46,30 +44,5 @@ namespace Content.Shared.Pulling.Components
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
if (message is not PullMessage pullMessage ||
|
||||
pullMessage.Puller.Owner != Owner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SharedAlertsComponent? ownerStatus = Owner.GetComponentOrNull<SharedAlertsComponent>();
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case PullStartedMessage msg:
|
||||
Pulling = msg.Pulled.Owner;
|
||||
ownerStatus?.ShowAlert(AlertType.Pulling);
|
||||
break;
|
||||
case PullStoppedMessage _:
|
||||
Pulling = null;
|
||||
ownerStatus?.ClearAlert(AlertType.Pulling);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Content.Shared/Pulling/Events/PullAttemptMessage.cs
Normal file
11
Content.Shared/Pulling/Events/PullAttemptMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Shared.Physics.Pull
|
||||
{
|
||||
public class PullAttemptMessage : PullMessage
|
||||
{
|
||||
public PullAttemptMessage(IPhysBody puller, IPhysBody pulled) : base(puller, pulled) { }
|
||||
|
||||
public bool Cancelled { get; set; }
|
||||
}
|
||||
}
|
||||
17
Content.Shared/Pulling/Events/PullMessage.cs
Normal file
17
Content.Shared/Pulling/Events/PullMessage.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Shared.Physics.Pull
|
||||
{
|
||||
public class PullMessage : EntityEventArgs
|
||||
{
|
||||
public readonly IPhysBody Puller;
|
||||
public readonly IPhysBody Pulled;
|
||||
|
||||
protected PullMessage(IPhysBody puller, IPhysBody pulled)
|
||||
{
|
||||
Puller = puller;
|
||||
Pulled = pulled;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Content.Shared/Pulling/Events/PullStartedMessage.cs
Normal file
12
Content.Shared/Pulling/Events/PullStartedMessage.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Shared.Physics.Pull
|
||||
{
|
||||
public class PullStartedMessage : PullMessage
|
||||
{
|
||||
public PullStartedMessage(IPhysBody puller, IPhysBody pulled) :
|
||||
base(puller, pulled)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Content.Shared/Pulling/Events/PullStoppedMessage.cs
Normal file
11
Content.Shared/Pulling/Events/PullStoppedMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Shared.Physics.Pull
|
||||
{
|
||||
public class PullStoppedMessage : PullMessage
|
||||
{
|
||||
public PullStoppedMessage(IPhysBody puller, IPhysBody pulled) : base(puller, pulled)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Content.Shared/Pulling/Systems/SharedPullerSystem.cs
Normal file
44
Content.Shared/Pulling/Systems/SharedPullerSystem.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Pulling
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SharedPullerSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedPullerComponent, PullStartedMessage>(PullerHandlePullStarted);
|
||||
SubscribeLocalEvent<SharedPullerComponent, PullStoppedMessage>(PullerHandlePullStopped);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Physics.Pull;
|
||||
@@ -56,12 +57,34 @@ namespace Content.Shared.Pulling
|
||||
SubscribeLocalEvent<MoveEvent>(PullerMoved);
|
||||
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleContainerInsert);
|
||||
|
||||
SubscribeLocalEvent<SharedPullableComponent, PullStartedMessage>(PullableHandlePullStarted);
|
||||
SubscribeLocalEvent<SharedPullableComponent, PullStoppedMessage>(PullableHandlePullStopped);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.MovePulledObject, new PointerInputCmdHandler(HandleMovePulledObject))
|
||||
.Bind(ContentKeyFunctions.ReleasePulledObject, InputCmdHandler.FromDelegate(HandleReleasePulledObject))
|
||||
.Register<SharedPullingSystem>();
|
||||
}
|
||||
|
||||
// Raise a "you are being pulled" alert if the pulled entity has alerts.
|
||||
private static void PullableHandlePullStarted(EntityUid uid, SharedPullableComponent component, PullStartedMessage args)
|
||||
{
|
||||
if (args.Pulled.Owner.Uid != uid)
|
||||
return;
|
||||
|
||||
if (component.Owner.TryGetComponent(out SharedAlertsComponent? alerts))
|
||||
alerts.ShowAlert(AlertType.Pulled);
|
||||
}
|
||||
|
||||
private static void PullableHandlePullStopped(EntityUid uid, SharedPullableComponent component, PullStoppedMessage args)
|
||||
{
|
||||
if (args.Pulled.Owner.Uid != uid)
|
||||
return;
|
||||
|
||||
if (component.Owner.TryGetComponent(out SharedAlertsComponent? alerts))
|
||||
alerts.ClearAlert(AlertType.Pulled);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
Reference in New Issue
Block a user