2021-07-31 03:14:00 +02:00
|
|
|
using System;
|
2018-03-03 18:07:09 -08:00
|
|
|
using System.Collections.Generic;
|
2020-07-25 15:11:16 +02:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-06-18 19:26:55 +02:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Act;
|
|
|
|
|
using Content.Server.Interaction;
|
|
|
|
|
using Content.Server.Items;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Server.Popups;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Pulling;
|
2021-01-09 20:31:34 +01:00
|
|
|
using Content.Shared.Audio;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Body.Part;
|
|
|
|
|
using Content.Shared.Hands.Components;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Pulling.Components;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Server.GameObjects;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-01-09 20:31:34 +01:00
|
|
|
using Robust.Shared.Localization;
|
2021-02-16 20:14:21 +01:00
|
|
|
using Robust.Shared.Map;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Player;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2017-09-24 21:09:26 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Hands.Components
|
2017-09-24 21:09:26 +02:00
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2020-12-13 14:28:20 -08:00
|
|
|
[ComponentReference(typeof(SharedHandsComponent))]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2021-11-08 15:08:24 +01:00
|
|
|
public class HandsComponent : SharedHandsComponent, IBodyPartAdded, IBodyPartRemoved, IDisarmedAct
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2017-09-24 21:09:26 +02:00
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
2021-12-05 21:02:04 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
2019-04-20 16:18:16 -07:00
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
[DataField("disarmedSound")] SoundSpecifier _disarmedSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
int IDisarmedAct.Priority => int.MaxValue; // We want this to be the last disarm act to run.
|
2018-03-03 18:07:09 -08:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
protected override void OnHeldEntityRemovedFromHand(EntityUid heldEntity, HandState handState)
|
2019-03-27 12:29:43 +00:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
if (_entities.TryGetComponent(heldEntity, out ItemComponent? item))
|
2019-03-27 12:29:43 +00:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
item.RemovedFromSlot();
|
|
|
|
|
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedHandInteraction(Owner, heldEntity, handState);
|
|
|
|
|
}
|
2021-12-05 21:02:04 +01:00
|
|
|
if (_entities.TryGetComponent(heldEntity, out SpriteComponent? sprite))
|
2021-06-21 02:21:20 -07:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
sprite.RenderOrder = _entities.CurrentTick.Value;
|
2019-03-27 12:29:43 +00:00
|
|
|
}
|
2017-09-24 23:19:47 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
protected override void HandlePickupAnimation(EntityUid entity)
|
2017-09-24 23:19:47 +02:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
var initialPosition = EntityCoordinates.FromMap(_entities.GetComponent<TransformComponent>(Owner).Parent?.Owner ?? Owner, _entities.GetComponent<TransformComponent>(entity).MapPosition);
|
2020-08-16 16:30:52 +02:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
var finalPosition = _entities.GetComponent<TransformComponent>(Owner).LocalPosition;
|
2017-09-24 23:19:47 +02:00
|
|
|
|
2021-08-06 19:20:27 +02:00
|
|
|
if (finalPosition.EqualsApprox(initialPosition.Position))
|
2021-06-21 02:21:20 -07:00
|
|
|
return;
|
2020-10-28 10:16:40 +01:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
_entities.EntityNetManager!.SendSystemNetworkMessage(
|
2021-12-03 15:53:09 +01:00
|
|
|
new PickupAnimationMessage(entity, finalPosition, initialPosition));
|
2017-09-24 23:19:47 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
#region Pull/Disarm
|
2020-08-09 20:52:52 +02:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
void IBodyPartAdded.BodyPartAdded(BodyPartAddedEventArgs args)
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (args.Part.PartType != BodyPartType.Hand)
|
|
|
|
|
return;
|
2020-07-25 15:11:16 +02:00
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
// 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()
|
|
|
|
|
};
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
AddHand(args.Slot, location);
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
void IBodyPartRemoved.BodyPartRemoved(BodyPartRemovedEventArgs args)
|
2017-09-24 23:19:47 +02:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (args.Part.PartType != BodyPartType.Hand)
|
|
|
|
|
return;
|
2020-08-15 20:33:42 +02:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
RemoveHand(args.Slot);
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-10 12:47:26 +02:00
|
|
|
bool IDisarmedAct.Disarmed(DisarmedActEvent @event)
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (BreakPulls())
|
2018-11-21 20:58:11 +01:00
|
|
|
return false;
|
|
|
|
|
|
2021-10-10 12:47:26 +02:00
|
|
|
var source = @event.Source;
|
|
|
|
|
var target = @event.Target;
|
2020-09-10 04:46:56 -07:00
|
|
|
|
2021-12-20 15:20:27 +01:00
|
|
|
if (source != null)
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(source), _disarmedSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-12-20 15:20:27 +01:00
|
|
|
if (target != null)
|
2021-06-21 02:21:20 -07:00
|
|
|
{
|
|
|
|
|
if (ActiveHand != null && Drop(ActiveHand, false))
|
|
|
|
|
{
|
2021-12-20 15:20:27 +01:00
|
|
|
source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
|
|
|
|
|
source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
|
2021-06-21 02:21:20 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-20 15:20:27 +01:00
|
|
|
source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
|
|
|
|
|
source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
|
2021-06-21 02:21:20 -07:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
2018-08-22 01:19:47 -07:00
|
|
|
|
2018-04-25 06:42:35 -05:00
|
|
|
return true;
|
2017-09-24 23:19:47 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
private bool BreakPulls()
|
2020-12-13 14:28:20 -08:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
// What is this API??
|
2021-12-05 21:02:04 +01:00
|
|
|
if (!_entities.TryGetComponent(Owner, out SharedPullerComponent? puller)
|
|
|
|
|
|| puller.Pulling is not {Valid: true} pulling || !_entities.TryGetComponent(puller.Pulling.Value, out SharedPullableComponent? pullable))
|
2021-06-21 02:21:20 -07:00
|
|
|
return false;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
2021-10-04 16:10:54 +01:00
|
|
|
return _entitySystemManager.GetEntitySystem<PullingSystem>().TryStopPull(pullable);
|
2020-12-13 14:28:20 -08:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
#endregion
|
2020-07-25 15:11:16 +02:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
#region Old public methods
|
2020-07-25 15:11:16 +02:00
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
public IEnumerable<string> HandNames => Hands.Select(h => h.Name);
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
public int Count => Hands.Count;
|
2020-08-15 20:33:42 +02:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a list of all hand names, with the active hand being first.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IEnumerable<string> ActivePriorityEnumerable()
|
2017-09-25 20:52:39 +02:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (ActiveHand != null)
|
|
|
|
|
yield return ActiveHand;
|
2017-09-29 18:38:27 +02:00
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
foreach (var hand in Hands)
|
2017-09-29 18:38:27 +02:00
|
|
|
{
|
2021-07-31 03:14:00 +02:00
|
|
|
if (hand.Name == ActiveHand)
|
2021-06-21 02:21:20 -07:00
|
|
|
continue;
|
2020-07-25 15:11:16 +02:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
yield return hand.Name;
|
2017-09-26 21:27:48 +02:00
|
|
|
}
|
2020-12-13 14:28:20 -08:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to get the ItemComponent on the entity held by a hand.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ItemComponent? GetItem(string handName)
|
2020-10-28 10:16:40 +01:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (!TryGetHeldEntity(handName, out var heldEntity))
|
|
|
|
|
return null;
|
2020-10-28 10:16:40 +01:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
_entities.TryGetComponent(heldEntity, out ItemComponent? item);
|
2021-06-21 02:21:20 -07:00
|
|
|
return item;
|
2020-10-28 10:16:40 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to get the ItemComponent on the entity held by a hand.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item)
|
2017-09-30 16:56:19 +02:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
item = null;
|
2018-03-03 18:07:09 -08:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
if (!TryGetHeldEntity(handName, out var heldEntity))
|
|
|
|
|
return false;
|
2020-01-17 18:41:47 -08:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
return _entities.TryGetComponent(heldEntity, out item);
|
2017-09-30 16:56:19 +02:00
|
|
|
}
|
2019-05-05 13:09:21 +02:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to get the ItemComponent off the entity in the active hand.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ItemComponent? GetActiveHand
|
2019-05-05 13:09:21 +02:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
get
|
2019-05-05 13:09:21 +02:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (!TryGetActiveHeldEntity(out var heldEntity))
|
|
|
|
|
return null;
|
2019-05-05 13:09:21 +02:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
_entities.TryGetComponent(heldEntity, out ItemComponent? item);
|
2021-06-21 02:21:20 -07:00
|
|
|
return item;
|
2020-07-25 15:11:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
public IEnumerable<ItemComponent> GetAllHeldItems()
|
2020-07-25 15:11:16 +02:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
foreach (var entity in GetAllHeldEntities())
|
2020-07-25 15:11:16 +02:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
if (_entities.TryGetComponent(entity, out ItemComponent? item))
|
2021-06-21 02:21:20 -07:00
|
|
|
yield return item;
|
2020-07-25 15:11:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-09 20:31:34 +01:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if any hand can pick up an item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool CanPutInHand(ItemComponent item, bool mobCheck = true)
|
2021-01-09 20:31:34 +01:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
var entity = item.Owner;
|
2021-03-16 15:50:20 +01:00
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
if (mobCheck && !PlayerCanPickup())
|
2021-01-09 20:31:34 +01:00
|
|
|
return false;
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
foreach (var hand in Hands)
|
2020-10-28 10:16:40 +01:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
if (CanInsertEntityIntoHand(hand, entity))
|
|
|
|
|
return true;
|
2020-10-28 10:16:40 +01:00
|
|
|
}
|
2021-06-21 02:21:20 -07:00
|
|
|
return false;
|
2020-10-28 10:16:40 +01:00
|
|
|
}
|
2021-06-21 02:21:20 -07:00
|
|
|
#endregion
|
2020-08-27 10:33:10 -04:00
|
|
|
}
|
2017-09-24 21:09:26 +02:00
|
|
|
}
|
2021-06-21 02:21:20 -07:00
|
|
|
|