Files
tbd-station-14/Content.Shared/Body/Part/BodyPartComponent.cs
2023-10-01 13:33:18 -07:00

115 lines
3.1 KiB
C#

using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedBodySystem))]
public sealed partial class BodyPartComponent : Component
{
// Need to set this on container changes as it may be several transform parents up the hierarchy.
/// <summary>
/// Parent body for this part.
/// </summary>
[DataField, AutoNetworkedField]
public EntityUid? Body;
[DataField, AutoNetworkedField]
public BodyPartType PartType = BodyPartType.Other;
// TODO BODY Replace with a simulation of organs
/// <summary>
/// Whether or not the owning <see cref="Body"/> will die if all
/// <see cref="BodyComponent"/>s of this type are removed from it.
/// </summary>
[DataField("vital"), AutoNetworkedField]
public bool IsVital;
[DataField, AutoNetworkedField]
public BodyPartSymmetry Symmetry = BodyPartSymmetry.None;
/// <summary>
/// Child body parts attached to this body part.
/// </summary>
[DataField, AutoNetworkedField]
public Dictionary<string, BodyPartSlot> Children = new();
/// <summary>
/// Organs attached to this body part.
/// </summary>
[DataField, AutoNetworkedField]
public Dictionary<string, OrganSlot> Organs = new();
/// <summary>
/// These are only for VV/Debug do not use these for gameplay/systems
/// </summary>
[ViewVariables]
private List<ContainerSlot> BodyPartSlotsVV
{
get
{
List<ContainerSlot> temp = new();
var containerSystem = IoCManager.Resolve<IEntityManager>().System<SharedContainerSystem>();
foreach (var slotId in Children.Keys)
{
temp.Add((ContainerSlot) containerSystem.GetContainer(Owner, SharedBodySystem.PartSlotContainerIdPrefix+slotId));
}
return temp;
}
}
[ViewVariables]
private List<ContainerSlot> OrganSlotsVV
{
get
{
List<ContainerSlot> temp = new();
var containerSystem = IoCManager.Resolve<IEntityManager>().System<SharedContainerSystem>();
foreach (var slotId in Organs.Keys)
{
temp.Add((ContainerSlot) containerSystem.GetContainer(Owner, SharedBodySystem.OrganSlotContainerIdPrefix+slotId));
}
return temp;
}
}
}
/// <summary>
/// Contains metadata about a body part in relation to its slot.
/// </summary>
[NetSerializable, Serializable]
[DataRecord]
public partial struct BodyPartSlot
{
public string Id;
public BodyPartType Type;
public BodyPartSlot(string id, BodyPartType type)
{
Id = id;
Type = type;
}
};
/// <summary>
/// Contains metadata about an organ part in relation to its slot.
/// </summary>
[NetSerializable, Serializable]
[DataRecord]
public partial struct OrganSlot
{
public string Id;
public OrganSlot(string id)
{
Id = id;
}
};