Improve hands & pulling (#4389)

This commit is contained in:
Pieter-Jan Briers
2021-07-31 03:14:00 +02:00
committed by GitHub
parent 73e4946e27
commit 632e72b817
33 changed files with 945 additions and 612 deletions

View File

@@ -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();

View File

@@ -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;
}
}
}
}

View 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; }
}
}

View 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;
}
}
}

View 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)
{
}
}
}

View 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)
{
}
}
}

View 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);
}
}
}

View File

@@ -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);