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;
|
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-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
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;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Player;
|
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
|
2022-02-26 18:24:08 +13:00
|
|
|
public sealed class HandsComponent : SharedHandsComponent, IBodyPartAdded, IBodyPartRemoved
|
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-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
|
|
|
}
|
|
|
|
|
|
2022-02-26 18:24:08 +13:00
|
|
|
public bool BreakPulls()
|
2020-12-13 14:28:20 -08:00
|
|
|
{
|
2021-06-21 02:21:20 -07:00
|
|
|
// What is this API??
|
2022-02-26 18:24:08 +13:00
|
|
|
// I just wanted to do actions not deal with this shit...
|
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>
|
2021-12-30 22:56:10 +01:00
|
|
|
public SharedItemComponent? 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-30 22:56:10 +01:00
|
|
|
_entities.TryGetComponent(heldEntity, out SharedItemComponent? 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>
|
2021-12-30 22:56:10 +01:00
|
|
|
public bool TryGetItem(string handName, [NotNullWhen(true)] out SharedItemComponent? 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>
|
2022-01-21 01:38:35 -08:00
|
|
|
public SharedItemComponent? GetActiveHandItem
|
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-30 22:56:10 +01:00
|
|
|
_entities.TryGetComponent(heldEntity, out SharedItemComponent? item);
|
2021-06-21 02:21:20 -07:00
|
|
|
return item;
|
2020-07-25 15:11:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
public IEnumerable<SharedItemComponent> 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-30 22:56:10 +01:00
|
|
|
if (_entities.TryGetComponent(entity, out SharedItemComponent? item))
|
2021-06-21 02:21:20 -07:00
|
|
|
yield return item;
|
2020-07-25 15:11:16 +02: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
|
|
|
|