2020-05-13 14:48:49 -05:00
using System ;
using System.Collections.Generic ;
using Content.Shared.BodySystem ;
using Robust.Shared.Interfaces.GameObjects ;
using Robust.Shared.Interfaces.Serialization ;
using Robust.Shared.Prototypes ;
using Robust.Shared.Serialization ;
using Robust.Shared.ViewVariables ;
using YamlDotNet.RepresentationModel ;
2020-07-02 13:51:14 -05:00
namespace Content.Server.BodySystem
{
2020-05-13 14:48:49 -05:00
/// <summary>
2020-07-02 13:51:14 -05:00
/// This data class represents the state of a <see cref="BodyPart"/> in regards to everything surgery related - whether there's an incision on it, whether the bone is broken, etc.
2020-05-13 14:48:49 -05:00
/// </summary>
2020-07-02 13:51:14 -05:00
public abstract class ISurgeryData
{
2020-05-13 14:48:49 -05:00
/// <summary>
2020-07-02 13:51:14 -05:00
/// The <see cref="BodyPart"/> this surgeryData is attached to. The ISurgeryData class should not exist without a <see cref="BodyPart"/> that it
/// represents, and will throw errors if it is null.
2020-05-13 14:48:49 -05:00
/// </summary>
protected BodyPart _parent ;
2020-07-02 13:51:14 -05:00
2020-05-13 14:48:49 -05:00
/// <summary>
2020-07-02 13:51:14 -05:00
/// The <see cref="BodyPartType"/> of the parent <see cref="BodyPart"/>.
2020-05-13 14:48:49 -05:00
/// </summary>
protected BodyPartType _parentType = > _parent . PartType ;
2020-07-02 13:51:14 -05:00
public delegate void SurgeryAction ( IBodyPartContainer container , ISurgeon surgeon , IEntity performer ) ;
2020-05-13 14:48:49 -05:00
public ISurgeryData ( BodyPart parent )
{
_parent = parent ;
}
/// <summary>
2020-07-02 13:51:14 -05:00
/// Returns the description of this current <see cref="BodyPart"/> to be shown upon observing the given entity.
/// </summary>
public abstract string GetDescription ( IEntity target ) ;
/// <summary>
/// Returns whether a <see cref="Mechanism"/> can be installed into the <see cref="BodyPart"/> this ISurgeryData represents.
/// </summary>
public abstract bool CanInstallMechanism ( Mechanism toBeInstalled ) ;
/// <summary>
/// Returns whether the given <see cref="BodyPart"/> can be connected to the <see cref="BodyPart"/> this ISurgeryData represents.
/// </summary>
public abstract bool CanAttachBodyPart ( BodyPart toBeConnected ) ;
/// <summary>
/// Gets the delegate corresponding to the surgery step using the given <see cref="SurgeryType"/>. Returns null if no surgery step can be performed.
2020-05-13 14:48:49 -05:00
/// </summary>
2020-07-02 13:51:14 -05:00
public abstract SurgeryAction GetSurgeryStep ( SurgeryType toolType ) ;
2020-05-13 14:48:49 -05:00
/// <summary>
2020-07-02 13:51:14 -05:00
/// Returns whether the given <see cref="SurgeryType"/> can be used to perform a surgery on the BodyPart this <see cref="ISurgeryData"/> represents.
2020-05-13 14:48:49 -05:00
/// </summary>
2020-07-02 13:51:14 -05:00
public bool CheckSurgery ( SurgeryType toolType )
2020-05-13 14:48:49 -05:00
{
return GetSurgeryStep ( toolType ) ! = null ;
}
/// <summary>
2020-07-02 13:51:14 -05:00
/// Attempts to perform surgery of the given <see cref="SurgeryType"/>. Returns whether the operation was successful.
2020-05-13 14:48:49 -05:00
/// </summary>
2020-07-02 13:51:14 -05:00
/// <param name="surgeryType">The <see cref="SurgeryType"/> used for this surgery.</param>
/// <param name="performer">The entity performing the surgery.</param>
public bool PerformSurgery ( SurgeryType surgeryType , IBodyPartContainer container , ISurgeon surgeon , IEntity performer )
2020-05-13 14:48:49 -05:00
{
2020-07-02 13:51:14 -05:00
SurgeryAction step = GetSurgeryStep ( surgeryType ) ;
2020-05-13 14:48:49 -05:00
if ( step = = null )
return false ;
2020-07-02 13:51:14 -05:00
step ( container , surgeon , performer ) ;
2020-05-13 14:48:49 -05:00
return true ;
}
}
}