#nullable enable
using Content.Shared.GameObjects.Components.Body.Mechanism;
using Content.Shared.GameObjects.Components.Body.Part;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Body.Surgery
{
///
/// This data class represents the state of a in
/// regards to everything surgery related - whether there's an incision on
/// it, whether the bone is broken, etc.
///
public abstract class SurgeryDataComponent : Component
{
protected delegate void SurgeryAction(IBodyPartContainer container, ISurgeon surgeon, IEntity performer);
///
/// The this
/// is attached to.
///
protected IBodyPart? Parent => Owner.GetComponentOrNull();
///
/// The of the parent
/// .
///
protected BodyPartType? ParentType => Parent?.PartType;
///
/// Returns the description of this current to
/// be shown upon observing the given entity.
///
public abstract string GetDescription(IEntity target);
///
/// Returns whether a can be added into the
/// this
/// represents.
///
public abstract bool CanAddMechanism(IMechanism mechanism);
///
/// Returns whether the given can be connected
/// to the this
/// represents.
///
public abstract bool CanAttachBodyPart(IBodyPart part);
///
/// Gets the delegate corresponding to the surgery step using the given
/// .
///
///
/// The corresponding surgery action or null if no step can be
/// performed.
///
protected abstract SurgeryAction? GetSurgeryStep(SurgeryType toolType);
///
/// Returns whether the given can be used to
/// perform a surgery on the this
/// represents.
///
public bool CheckSurgery(SurgeryType toolType)
{
return GetSurgeryStep(toolType) != null;
}
///
/// Attempts to perform surgery of the given .
///
///
/// The used for this surgery.
///
///
/// The container where the surgery is being done.
///
///
/// The entity being used to perform the surgery.
///
/// The entity performing the surgery.
/// True if successful, false otherwise.
public bool PerformSurgery(SurgeryType surgeryType, IBodyPartContainer container, ISurgeon surgeon,
IEntity performer)
{
var step = GetSurgeryStep(surgeryType);
if (step == null)
{
return false;
}
step(container, surgeon, performer);
return true;
}
}
}