Merge branch 'master' into replace-sounds-with-sound-specifier

# Conflicts:
#	Content.Server/Hands/Components/HandsComponent.cs
#	Content.Server/Light/Components/ExpendableLightComponent.cs
#	Content.Shared/Light/Component/SharedExpendableLightComponent.cs
This commit is contained in:
Galactic Chimp
2021-07-31 13:16:03 +02:00
105 changed files with 1483 additions and 1319 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 Content.Shared.Sound;
using Robust.Server.GameObjects;
@@ -20,9 +20,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;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Hands.Components
@@ -39,48 +37,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))
@@ -145,7 +101,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
@@ -155,9 +112,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)
@@ -209,41 +174,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.
@@ -253,9 +190,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;

View File

@@ -0,0 +1,57 @@
using Content.Server.Pulling;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Hands
{
[UsedImplicitly]
public sealed class HandVirtualPullSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HandVirtualPullComponent, DroppedEvent>(HandlePullerDropped);
SubscribeLocalEvent<HandVirtualPullComponent, UnequippedHandEvent>(HandlePullerUnequipped);
SubscribeLocalEvent<HandVirtualPullComponent, BeforeInteractEvent>(HandleBeforeInteract);
}
private static void HandleBeforeInteract(
EntityUid uid,
HandVirtualPullComponent component,
BeforeInteractEvent args)
{
// No interactions with a virtual pull, please.
args.Handled = true;
}
// If the virtual pull gets removed from the hands for any reason, cancel the pull and delete it.
private void HandlePullerUnequipped(EntityUid uid, HandVirtualPullComponent component, UnequippedHandEvent args)
{
MaybeDelete(component, args.User);
}
private void HandlePullerDropped(EntityUid uid, HandVirtualPullComponent component, DroppedEvent args)
{
MaybeDelete(component, args.User);
}
private void MaybeDelete(HandVirtualPullComponent comp, IEntity? user)
{
var pulled = comp.PulledEntity;
if (!ComponentManager.TryGetComponent(pulled, out PullableComponent? pullable))
return;
if (pullable.Puller != user)
return;
pullable.TryStopPull(user);
comp.Owner.QueueDelete();
}
}
}

View File

@@ -13,9 +13,9 @@ using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Notification.Managers;
using Content.Shared.Physics.Pull;
using JetBrains.Annotations;
using Robust.Server.Player;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
@@ -23,6 +23,7 @@ using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Utility;
using static Content.Shared.Inventory.EquipmentSlotDefines;
namespace Content.Server.Hands
@@ -38,15 +39,126 @@ namespace Content.Server.Hands
base.Initialize();
SubscribeLocalEvent<HandsComponent, ExaminedEvent>(HandleExamined);
SubscribeNetworkEvent<ActivateInHandMsg>(HandleActivateInHand);
SubscribeNetworkEvent<ClientInteractUsingInHandMsg>(HandleInteractUsingInHand);
SubscribeNetworkEvent<UseInHandMsg>(HandleUseInHand);
SubscribeNetworkEvent<MoveItemFromHandMsg>(HandleMoveItemFromHand);
SubscribeLocalEvent<HandsComponent, PullAttemptMessage>(HandlePullAttempt);
SubscribeLocalEvent<HandsComponent, PullStartedMessage>(HandlePullStarted);
SubscribeLocalEvent<HandsComponent, PullStoppedMessage>(HandlePullStopped);
CommandBinds.Builder
.Bind(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem))
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
.Bind(ContentKeyFunctions.SmartEquipBackpack, InputCmdHandler.FromDelegate(HandleSmartEquipBackpack))
.Bind(ContentKeyFunctions.SmartEquipBelt, InputCmdHandler.FromDelegate(HandleSmartEquipBelt))
.Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(SwapHandsPressed, handle: false))
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
.Register<HandsSystem>();
}
private static void HandlePullAttempt(EntityUid uid, HandsComponent component, PullAttemptMessage args)
{
// Cancel pull if all hands full.
if (component.Hands.All(hand => !hand.IsEmpty))
args.Cancelled = true;
}
private void HandlePullStarted(EntityUid uid, HandsComponent component, PullStartedMessage args)
{
foreach (var handName in component.ActivePriorityEnumerable())
{
var hand = component.GetHand(handName);
if (!hand.IsEmpty)
continue;
var pos = component.Owner.Transform.Coordinates;
var virtualPull = EntityManager.SpawnEntity("HandVirtualPull", pos);
var virtualPullComp = virtualPull.GetComponent<HandVirtualPullComponent>();
virtualPullComp.PulledEntity = args.Pulled.Owner.Uid;
component.PutEntityIntoHand(hand, virtualPull);
return;
}
DebugTools.Assert("Unable to find available hand when starting pulling??");
}
private void HandlePullStopped(EntityUid uid, HandsComponent component, PullStoppedMessage args)
{
// Try find hand that is doing this pull.
// and clear it.
foreach (var hand in component.Hands)
{
if (hand.HeldEntity == null
|| !hand.HeldEntity.TryGetComponent(out HandVirtualPullComponent? virtualPull)
|| virtualPull.PulledEntity != args.Pulled.Owner.Uid)
continue;
hand.HeldEntity.Delete();
break;
}
}
private void SwapHandsPressed(ICommonSession? session)
{
var player = session?.AttachedEntity;
if (player == null)
return;
if (!player.TryGetComponent(out SharedHandsComponent? hands))
return;
if (!hands.TryGetSwapHandsResult(out var nextHand))
return;
hands.ActiveHand = nextHand;
}
private bool DropPressed(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
var player = session?.AttachedEntity;
if (player == null)
return false;
if (!player.TryGetComponent(out SharedHandsComponent? hands))
return false;
var activeHand = hands.ActiveHand;
if (activeHand == null)
return false;
hands.TryDropHand(activeHand, coords);
return false;
}
private void HandleMoveItemFromHand(MoveItemFromHandMsg msg, EntitySessionEventArgs args)
{
if (!TryGetHandsComp(args.SenderSession, out var hands))
return;
hands.TryMoveHeldEntityToActiveHand(msg.HandName);
}
private void HandleUseInHand(UseInHandMsg msg, EntitySessionEventArgs args)
{
if (!TryGetHandsComp(args.SenderSession, out var hands))
return;
hands.UseActiveHeldEntity();
}
private void HandleInteractUsingInHand(ClientInteractUsingInHandMsg msg, EntitySessionEventArgs args)
{
if (!TryGetHandsComp(args.SenderSession, out var hands))
return;
hands.InteractHandWithActiveHand(msg.HandName);
}
public override void Shutdown()
{
base.Shutdown();
@@ -54,6 +166,14 @@ namespace Content.Server.Hands
CommandBinds.Unregister<HandsSystem>();
}
private void HandleActivateInHand(ActivateInHandMsg msg, EntitySessionEventArgs args)
{
if (!TryGetHandsComp(args.SenderSession, out var hands))
return;
hands.ActivateHeldEntity(msg.HandName);
}
protected override void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
{
base.DropAllItemsInHands(entity, doMobChecks);
@@ -75,25 +195,21 @@ namespace Content.Server.Hands
}
}
protected override void HandleContainerModified(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args)
{
component.Dirty();
}
private bool TryGetHandsComp(ICommonSession? session, [NotNullWhen(true)] out SharedHandsComponent? hands)
private static bool TryGetHandsComp(
ICommonSession? session,
[NotNullWhen(true)] out SharedHandsComponent? hands)
{
hands = default;
if (session is not IPlayerSession playerSession)
return false;
var playerEnt = playerSession?.AttachedEntity;
var playerEnt = playerSession.AttachedEntity;
if (playerEnt == null || !playerEnt.IsValid())
return false;
playerEnt.TryGetComponent(out hands);
return hands != null;
return playerEnt.TryGetComponent(out hands);
}
private void HandleActivateItem(ICommonSession? session)