BodySystem stuff 2: overused boogaloo (#1174)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
GlassEclipse
2020-07-02 13:51:14 -05:00
committed by GitHub
parent 7d346ede28
commit 610ab8bf50
30 changed files with 1493 additions and 688 deletions

View File

@@ -15,8 +15,8 @@ namespace Content.Server.BodySystem
/// <summary>
/// Data class representing a singular limb such as an arm or a leg. Typically held within a BodyManagerComponent,
/// which coordinates functions between BodyParts.
/// Data class representing a singular limb such as an arm or a leg. Typically held within either a <see cref="BodyManagerComponent"/>,
/// which coordinates functions between BodyParts, or a <see cref="DroppedBodyPartComponent"/>.
/// </summary>
public class BodyPart
{
@@ -31,13 +31,13 @@ namespace Content.Server.BodySystem
private int _sizeUsed = 0;
/// <summary>
/// Body part name.
/// The name of this BodyPart, often displayed to the user. For example, it could be named "advanced robotic arm".
/// </summary>
[ViewVariables]
public string Name { get; set; }
/// <summary>
/// Plural version of this body part's name.
/// Plural version of this BodyPart name.
/// </summary>
[ViewVariables]
public string Plural { get; set; }
@@ -55,19 +55,19 @@ namespace Content.Server.BodySystem
public string RSIState { get; set; }
/// <summary>
/// BodyPartType that this body part is considered.
/// <see cref="BodyPartType"/> that this BodyPart is considered to be. For example, BodyPartType.Arm.
/// </summary>
[ViewVariables]
public BodyPartType PartType { get; set; }
/// <summary>
/// Max HP of this body part.
/// Max HP of this BodyPart.
/// </summary>
[ViewVariables]
public int MaxDurability { get; set; }
/// <summary>
/// Current HP of this body part based on sum of all damage types.
/// Current HP of this BodyPart based on sum of all damage types.
/// </summary>
[ViewVariables]
public int CurrentDurability => MaxDurability - CurrentDamages.Damage;
@@ -79,42 +79,42 @@ namespace Content.Server.BodySystem
public AbstractDamageContainer CurrentDamages { get; set; }
/// <summary>
/// At what HP this body part is completely destroyed.
/// At what HP this BodyPartis completely destroyed.
/// </summary>
[ViewVariables]
public int DestroyThreshold { get; set; }
/// <summary>
/// Armor of the body part against attacks.
/// Armor of this BodyPart against attacks.
/// </summary>
[ViewVariables]
public float Resistance { get; set; }
/// <summary>
/// Determines many things: how many mechanisms can be fit inside a body part, fitting through tiny crevices, etc.
/// Determines many things: how many mechanisms can be fit inside this BodyPart, whether a body can fit through tiny crevices, etc.
/// </summary>
[ViewVariables]
public int Size { get; set; }
/// <summary>
/// What types of body parts this body part can attach to. For the most part, most limbs aren't universal and require extra work to attach between types.
/// What types of BodyParts this BodyPart can easily attach to. For the most part, most limbs aren't universal and require extra work to attach between types.
/// </summary>
[ViewVariables]
public BodyPartCompatibility Compatibility { get; set; }
/// <summary>
/// List of IExposeData properties, allowing for additional data classes to be attached to a limb, such as a "length" class to an arm.
/// List of <see cref="IExposeData"/> properties, allowing for additional data classes to be attached to a limb, such as a "length" class to an arm.
/// </summary>
[ViewVariables]
public List<IExposeData> Properties { get; set; }
/// <summary>
/// List of all Mechanisms currently inside this BodyPart.
/// List of all <see cref="Mechanism">Mechanisms</see> currently inside this BodyPart.
/// </summary>
[ViewVariables]
public List<Mechanism> Mechanisms => _mechanisms;
public BodyPart(){}
public BodyPart() { }
public BodyPart(BodyPartPrototype data)
{
@@ -124,32 +124,55 @@ namespace Content.Server.BodySystem
public bool CanAttachBodyPart(BodyPart toBeConnected)
{
return _surgeryData.CanAttachBodyPart(toBeConnected);
}
/// <summary>
/// Attempts to add a Mechanism. Returns true if successful, false if there was an error (e.g. not enough room in BodyPart). Use InstallDroppedMechanism if you want to easily install an IEntity with a DroppedMechanismComponent.
/// Returns whether the given <see cref="Mechanism"/> can be installed on this BodyPart.
/// </summary>
public bool InstallMechanism(Mechanism mechanism)
public bool CanInstallMechanism(Mechanism mechanism)
{
if (_sizeUsed + mechanism.Size > Size)
return false; //No space
_mechanisms.Add(mechanism);
_sizeUsed += mechanism.Size;
return true;
return _surgeryData.CanInstallMechanism(mechanism);
}
/// <summary>
/// Attempts to install a DroppedMechanismComponent into the given limb, potentially deleting the dropped IEntity. Returns true if successful, false if there was an error (e.g. not enough room in BodyPart).
/// Attempts to add a <see cref="Mechanism"/>. Returns true if successful, false if there was an error (e.g. not enough room in BodyPart). Call InstallDroppedMechanism instead if you want to easily install an IEntity with a DroppedMechanismComponent.
/// </summary>
public bool InstallDroppedMechanism(DroppedMechanismComponent droppedMechanism)
public bool TryInstallMechanism(Mechanism mechanism)
{
if (_sizeUsed + droppedMechanism.ContainedMechanism.Size > Size)
return false; //No space
InstallMechanism(droppedMechanism.ContainedMechanism);
if (CanInstallMechanism(mechanism))
{
_mechanisms.Add(mechanism);
_sizeUsed += mechanism.Size;
return true;
}
return false;
}
/// <summary>
/// Attempts to install a <see cref="DroppedMechanismComponent"/> into the given limb, potentially deleting the dropped <see cref="IEntity"/>. Returns true if successful, false if there was an error (e.g. not enough room in BodyPart).
/// </summary>
public bool TryInstallDroppedMechanism(DroppedMechanismComponent droppedMechanism)
{
if (!TryInstallMechanism(droppedMechanism.ContainedMechanism))
return false; //Installing the mechanism failed for some reason.
droppedMechanism.Owner.Delete();
return true;
}
/// <summary>
/// Tries to remove the given Mechanism reference from the given BodyPart reference. Returns null if there was an error in spawning the entity or removing the mechanism, otherwise returns a reference to the DroppedMechanismComponent on the newly spawned entity.
/// Tries to remove the given <see cref="Mechanism"/> reference from this BodyPart. Returns null if there was an error in spawning the entity or removing the mechanism, otherwise returns a reference to the <see cref="DroppedMechanismComponent"/> on the newly spawned entity.
/// </summary>
public DroppedMechanismComponent DropMechanism(IEntity dropLocation, Mechanism mechanismTarget)
{
@@ -165,7 +188,7 @@ namespace Content.Server.BodySystem
}
/// <summary>
/// Tries to destroy the given Mechanism in the given BodyPart. Returns false if there was an error, true otherwise. Does NOT spawn a dropped entity.
/// Tries to destroy the given <see cref="Mechanism"/> in the given BodyPart. Returns false if there was an error, true otherwise. Does NOT spawn a dropped entity.
/// </summary>
public bool DestroyMechanism(BodyPart bodyPartTarget, Mechanism mechanismTarget)
{
@@ -176,10 +199,14 @@ namespace Content.Server.BodySystem
return true;
}
/// <summary>
/// Returns whether the given SurgertToolType can be used on the current state of this BodyPart (e.g.
/// Returns whether the given <see cref="SurgeryType"/> can be used on the current state of this BodyPart.
/// </summary>
public bool SurgeryCheck(SurgeryToolType toolType)
public bool SurgeryCheck(SurgeryType toolType)
{
return _surgeryData.CheckSurgery(toolType);
}
@@ -187,13 +214,17 @@ namespace Content.Server.BodySystem
/// <summary>
/// Attempts to perform surgery on this BodyPart with the given tool. Returns false if there was an error, true if successful.
/// </summary>
public bool AttemptSurgery(SurgeryToolType toolType, BodyManagerComponent target, IEntity performer)
public bool AttemptSurgery(SurgeryType toolType, IBodyPartContainer target, ISurgeon surgeon, IEntity performer)
{
return _surgeryData.PerformSurgery(toolType, target, performer);
return _surgeryData.PerformSurgery(toolType, target, surgeon, performer);
}
/// <summary>
/// Loads the given BodyPartPrototype - current data on this BodyPart will be overwritten!
/// Loads the given <see cref="BodyPartPrototype"/> - current data on this <see cref="BodyPart"/> will be overwritten!
/// </summary>
public virtual void LoadFromPrototype(BodyPartPrototype data)
{