2021-12-16 23:42:02 +13:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
2021-12-16 23:42:02 +13:00
|
|
|
using Content.Shared.Access.Components;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Inventory;
|
2021-12-16 23:42:02 +13:00
|
|
|
using Content.Shared.PDA;
|
2021-03-13 03:22:51 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-03-13 03:22:51 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.PDA
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
|
|
|
|
public static class PdaExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the id that a player is holding in their hands or inventory.
|
|
|
|
|
/// Order: Hands > ID slot > PDA in ID slot
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player">The player to check in.</param>
|
|
|
|
|
/// <returns>The id card component.</returns>
|
2021-12-04 14:14:22 +01:00
|
|
|
public static IdCardComponent? GetHeldId(this EntityUid player)
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
IdCardComponent? foundPDAId = null;
|
2021-03-13 03:22:51 +01:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
|
|
|
if (entMan.TryGetComponent(player, out HandsComponent? hands))
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
|
|
|
|
foreach (var item in hands.GetAllHeldItems())
|
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
if (entMan.TryGetComponent(item.Owner, out PDAComponent? pda) &&
|
2021-03-13 03:22:51 +01:00
|
|
|
pda.ContainedID != null)
|
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
foundPDAId = pda.ContainedID;
|
2021-03-13 03:22:51 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (entMan.TryGetComponent(item.Owner, out IdCardComponent? card))
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (foundPDAId != null) return foundPDAId;
|
2021-03-13 03:22:51 +01:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
var invSystem = EntitySystem.Get<InventorySystem>();
|
2021-03-13 03:22:51 +01:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (invSystem.TryGetContainerSlotEnumerator(player, out var enumerator))
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
while (enumerator.MoveNext(out var containerSlot))
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
if(!containerSlot.ContainedEntity.HasValue) continue;
|
|
|
|
|
|
|
|
|
|
if (entMan.TryGetComponent(containerSlot.ContainedEntity.Value, out PDAComponent? pda) &&
|
2021-03-13 03:22:51 +01:00
|
|
|
pda.ContainedID != null)
|
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
foundPDAId = pda.ContainedID;
|
2021-03-13 03:22:51 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (entMan.TryGetComponent(containerSlot.ContainedEntity.Value, out IdCardComponent? card))
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (foundPDAId != null) return foundPDAId;
|
|
|
|
|
|
|
|
|
|
return null;
|
2021-03-13 03:22:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the id that a player is holding in their hands or inventory.
|
|
|
|
|
/// Order: Hands > ID slot > PDA in ID slot
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player">The player to check in.</param>
|
|
|
|
|
/// <param name="id">The id card component.</param>
|
|
|
|
|
/// <returns>true if found, false otherwise.</returns>
|
2021-12-04 14:14:22 +01:00
|
|
|
public static bool TryGetHeldId(this EntityUid player, [NotNullWhen(true)] out IdCardComponent? id)
|
2021-03-13 03:22:51 +01:00
|
|
|
{
|
|
|
|
|
return (id = player.GetHeldId()) != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|