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

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -10,7 +11,6 @@ using Content.Shared.Audio;
using Content.Shared.Body.Part;
using Content.Shared.Hands.Components;
using Content.Shared.Notification.Managers;
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -19,9 +19,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Players;
namespace Content.Server.Hands.Components
{
@@ -35,48 +33,6 @@ namespace Content.Server.Hands.Components
int IDisarmedAct.Priority => int.MaxValue; // We want this to be the last disarm act to run.
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PullAttemptMessage msg:
AttemptPull(msg);
break;
case PullStartedMessage:
StartPulling();
break;
case PullStoppedMessage:
StopPulling();
break;
}
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, channel, session);
switch (message)
{
case ClientChangedHandMsg msg:
ActiveHand = msg.HandName;
break;
case ClientAttackByInHandMsg msg:
InteractHandWithActiveHand(msg.HandName);
break;
case UseInHandMsg:
UseActiveHeldEntity();
break;
case ActivateInHandMsg msg:
ActivateHeldEntity(msg.HandName);
break;
case MoveItemFromHandMsg msg:
TryMoveHeldEntityToActiveHand(msg.HandName);
break;
}
}
protected override void OnHeldEntityRemovedFromHand(IEntity heldEntity, HandState handState)
{
if (heldEntity.TryGetComponent(out ItemComponent? item))
@@ -141,7 +97,8 @@ namespace Content.Server.Hands.Components
if (pickupDirection == initialPosition.ToMapPos(Owner.EntityManager))
return;
SendNetworkMessage(new PickupAnimationMessage(entity.Uid, pickupDirection, initialPosition));
Owner.EntityManager.EntityNetManager!.SendSystemNetworkMessage(
new PickupAnimationMessage(entity.Uid, pickupDirection, initialPosition));
}
#region Pull/Disarm
@@ -151,9 +108,17 @@ namespace Content.Server.Hands.Components
if (args.Part.PartType != BodyPartType.Hand)
return;
var handLocation = ReadOnlyHands.Count == 0 ? HandLocation.Right : HandLocation.Left; //TODO: make hand body part have a handlocation?
// If this annoys you, which it should.
// Ping Smugleaf.
var location = args.Part.Symmetry switch
{
BodyPartSymmetry.None => HandLocation.Middle,
BodyPartSymmetry.Left => HandLocation.Left,
BodyPartSymmetry.Right => HandLocation.Right,
_ => throw new ArgumentOutOfRangeException()
};
AddHand(args.Slot, handLocation);
AddHand(args.Slot, location);
}
void IBodyPartRemoved.BodyPartRemoved(BodyPartRemovedEventArgs args)
@@ -205,41 +170,13 @@ namespace Content.Server.Hands.Components
return pullable.TryStopPull();
}
private void AttemptPull(PullAttemptMessage msg)
{
if (!ReadOnlyHands.Any(hand => hand.Enabled))
{
msg.Cancelled = true;
}
}
private void StartPulling()
{
var firstFreeHand = Hands.FirstOrDefault(hand => hand.Enabled);
if (firstFreeHand == null)
return;
DisableHand(firstFreeHand);
}
private void StopPulling()
{
var firstOccupiedHand = Hands.FirstOrDefault(hand => !hand.Enabled);
if (firstOccupiedHand == null)
return;
EnableHand(firstOccupiedHand);
}
#endregion
#region Old public methods
public IEnumerable<string> HandNames => ReadOnlyHands.Select(h => h.Name);
public IEnumerable<string> HandNames => Hands.Select(h => h.Name);
public int Count => ReadOnlyHands.Count;
public int Count => Hands.Count;
/// <summary>
/// Returns a list of all hand names, with the active hand being first.
@@ -249,9 +186,9 @@ namespace Content.Server.Hands.Components
if (ActiveHand != null)
yield return ActiveHand;
foreach (var hand in ReadOnlyHands)
foreach (var hand in Hands)
{
if (hand.Name == ActiveHand || !hand.Enabled)
if (hand.Name == ActiveHand)
continue;
yield return hand.Name;