Add body part and body manager interfaces (#1939)

* Add body part and body manager interfaces

* Merge fixes
This commit is contained in:
DrSmugleaf
2020-08-30 11:26:52 +02:00
committed by GitHub
parent a8aa088058
commit 827eab17d0
16 changed files with 393 additions and 322 deletions

View File

@@ -87,7 +87,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
var slot = part.GetHashCode().ToString();
body.Template.Slots.Add(slot, BodyPartType.Hand);
body.InstallBodyPart(part, slot);
body.TryAddPart(slot, part, true);
}
}
}

View File

@@ -48,7 +48,7 @@ namespace Content.Server.Body
var slot = part.GetHashCode().ToString();
body.Template.Slots.Add(slot, BodyPartType.Hand);
body.InstallBodyPart(part, slot);
body.TryAddPart(slot, part, true);
}
}

View File

@@ -14,13 +14,11 @@ using Content.Shared.Damage.DamageContainer;
using Content.Shared.Damage.ResistanceSet;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Damage;
using Robust.Server.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
@@ -34,19 +32,10 @@ namespace Content.Server.Body
/// which coordinates functions between BodyParts, or a
/// <see cref="DroppedBodyPartComponent"/>.
/// </summary>
public class BodyPart
public class BodyPart : IBodyPart
{
/// <summary>
/// The body that this body part is in, if any.
/// </summary>
private BodyManagerComponent? _body;
private IBodyManagerComponent? _body;
/// <summary>
/// Set of all <see cref="Mechanism"/> currently inside this
/// <see cref="BodyPart"/>.
/// To add and remove from this list see <see cref="AddMechanism"/> and
/// <see cref="RemoveMechanism"/>
/// </summary>
private readonly HashSet<Mechanism> _mechanisms = new HashSet<Mechanism>();
public BodyPart(BodyPartPrototype data)
@@ -64,11 +53,8 @@ namespace Content.Server.Body
LoadFromPrototype(data);
}
/// <summary>
/// The body that this body part is in, if any.
/// </summary>
[ViewVariables]
public BodyManagerComponent? Body
public IBodyManagerComponent? Body
{
get => _body;
set
@@ -111,91 +97,48 @@ namespace Content.Server.Body
[ViewVariables]
private HashSet<IExposeData> Properties { get; }
/// <summary>
/// The name of this <see cref="BodyPart"/>, often displayed to the user.
/// For example, it could be named "advanced robotic arm".
/// </summary>
[ViewVariables]
public string Name { get; private set; }
[ViewVariables] public string Name { get; private set; }
/// <summary>
/// Plural version of this <see cref="BodyPart"/> name.
/// </summary>
[ViewVariables]
public string Plural { get; private set; }
[ViewVariables] public string Plural { get; private set; }
/// <summary>
/// Path to the RSI that represents this <see cref="BodyPart"/>.
/// </summary>
[ViewVariables]
public string RSIPath { get; private set; }
[ViewVariables] public string RSIPath { get; private set; }
/// <summary>
/// RSI state that represents this <see cref="BodyPart"/>.
/// </summary>
[ViewVariables]
public string RSIState { get; private set; }
[ViewVariables] public string RSIState { get; private set; }
/// <summary>
/// RSI map keys that this body part changes on the sprite.
/// </summary>
[ViewVariables]
public Enum? RSIMap { get; set; }
[ViewVariables] public Enum? RSIMap { get; set; }
/// <summary>
/// RSI color of this body part.
/// </summary>
// TODO: SpriteComponent rework
public Color? RSIColor { get; set; }
[ViewVariables] public Color? RSIColor { get; set; }
/// <summary>
/// <see cref="BodyPartType"/> that this <see cref="BodyPart"/> is considered
/// to be.
/// For example, <see cref="BodyPartType.Arm"/>.
/// </summary>
[ViewVariables]
public BodyPartType PartType { get; private set; }
[ViewVariables] public BodyPartType PartType { get; private set; }
/// <summary>
/// Determines many things: how many mechanisms can be fit inside this
/// <see cref="BodyPart"/>, whether a body can fit through tiny crevices, etc.
/// </summary>
[ViewVariables]
private int Size { get; set; }
[ViewVariables] public int Size { get; private set; }
/// <summary>
/// Max HP of this <see cref="BodyPart"/>.
/// </summary>
[ViewVariables]
public int MaxDurability { get; private set; }
[ViewVariables] public int MaxDurability { get; private set; }
/// <summary>
/// Current HP of this <see cref="BodyPart"/> based on sum of all damage types.
/// </summary>
[ViewVariables]
public int CurrentDurability => MaxDurability - Damage.TotalDamage;
[ViewVariables] public int CurrentDurability => MaxDurability - Damage.TotalDamage;
// TODO: Individual body part damage
/// <summary>
/// Current damage dealt to this <see cref="BodyPart"/>.
/// Current damage dealt to this <see cref="IBodyPart"/>.
/// </summary>
[ViewVariables]
public DamageContainer Damage { get; private set; }
/// <summary>
/// Armor of this <see cref="BodyPart"/> against damages.
/// Armor of this <see cref="IBodyPart"/> against damages.
/// </summary>
[ViewVariables]
public ResistanceSet Resistances { get; private set; }
/// <summary>
/// At what HP this <see cref="BodyPart"/> destroyed.
/// At what HP this <see cref="IBodyPart"/> destroyed.
/// </summary>
[ViewVariables]
public int DestroyThreshold { get; private set; }
/// <summary>
/// What types of BodyParts this <see cref="BodyPart"/> can easily attach to.
/// What types of BodyParts this <see cref="IBodyPart"/> can easily attach to.
/// For the most part, most limbs aren't universal and require extra work to
/// attach between types.
/// </summary>
@@ -204,14 +147,15 @@ namespace Content.Server.Body
/// <summary>
/// Set of all <see cref="Mechanism"/> currently inside this
/// <see cref="BodyPart"/>.
/// <see cref="IBodyPart"/>.
/// </summary>
[ViewVariables]
public IReadOnlyCollection<Mechanism> Mechanisms => _mechanisms;
/// <summary>
/// This method is called by <see cref="BodyManagerComponent.Update"/>
/// before <see cref="MetabolismComponent.Update"/> is called.
/// This method is called by
/// <see cref="IBodyManagerComponent.PreMetabolism"/> before
/// <see cref="MetabolismComponent.Update"/> is called.
/// </summary>
public void PreMetabolism(float frameTime)
{
@@ -222,8 +166,9 @@ namespace Content.Server.Body
}
/// <summary>
/// This method is called by <see cref="BodyManagerComponent.Update"/>
/// after <see cref="MetabolismComponent.Update"/> is called.
/// This method is called by
/// <see cref="IBodyManagerComponent.PostMetabolism"/> after
/// <see cref="MetabolismComponent.Update"/> is called.
/// </summary>
public void PostMetabolism(float frameTime)
{
@@ -258,9 +203,10 @@ namespace Content.Server.Body
/// <param name="property">The property if found, null otherwise.</param>
/// <typeparam name="T">The type of the property to find.</typeparam>
/// <returns>True if successful, false otherwise.</returns>
public bool TryGetProperty<T>(out T property)
public bool TryGetProperty<T>([NotNullWhen(true)] out T? property) where T : BodyPartProperty
{
property = (T) Properties.First(x => x.GetType() == typeof(T));
property = (T?) Properties.FirstOrDefault(x => x.GetType() == typeof(T));
return property != null;
}
@@ -269,20 +215,21 @@ namespace Content.Server.Body
/// The resulting <see cref="BodyPartProperty"/> will be null if unsuccessful.
/// </summary>
/// <returns>True if successful, false otherwise.</returns>
public bool TryGetProperty(Type propertyType, out BodyPartProperty property)
public bool TryGetProperty(Type propertyType, [NotNullWhen(true)] out BodyPartProperty? property)
{
property = (BodyPartProperty) Properties.First(x => x.GetType() == propertyType);
property = (BodyPartProperty?) Properties.First(x => x.GetType() == propertyType);
return property != null;
}
/// <summary>
/// Checks if the given type <see cref="T"/> is on this <see cref="BodyPart"/>.
/// Checks if the given type <see cref="T"/> is on this <see cref="IBodyPart"/>.
/// </summary>
/// <typeparam name="T">
/// The subtype of <see cref="BodyPartProperty"/> to look for.
/// </typeparam>
/// <returns>
/// True if this <see cref="BodyPart"/> has a property of type
/// True if this <see cref="IBodyPart"/> has a property of type
/// <see cref="T"/>, false otherwise.
/// </returns>
public bool HasProperty<T>() where T : BodyPartProperty
@@ -292,13 +239,13 @@ namespace Content.Server.Body
/// <summary>
/// Checks if a subtype of <see cref="BodyPartProperty"/> is on this
/// <see cref="BodyPart"/>.
/// <see cref="IBodyPart"/>.
/// </summary>
/// <param name="propertyType">
/// The subtype of <see cref="BodyPartProperty"/> to look for.
/// </param>
/// <returns>
/// True if this <see cref="BodyPart"/> has a property of type
/// True if this <see cref="IBodyPart"/> has a property of type
/// <see cref="propertyType"/>, false otherwise.
/// </returns>
public bool HasProperty(Type propertyType)
@@ -306,21 +253,11 @@ namespace Content.Server.Body
return Properties.Count(x => x.GetType() == propertyType) > 0;
}
/// <summary>
/// Checks if another <see cref="BodyPart"/> can be connected to this one.
/// </summary>
/// <param name="toBeConnected">The part to connect.</param>
/// <returns>True if it can be connected, false otherwise.</returns>
public bool CanAttachBodyPart(BodyPart toBeConnected)
public bool CanAttachPart(IBodyPart part)
{
return SurgeryData.CanAttachBodyPart(toBeConnected);
return SurgeryData.CanAttachBodyPart(part);
}
/// <summary>
/// Checks if a <see cref="Mechanism"/> can be installed on this
/// <see cref="BodyPart"/>.
/// </summary>
/// <returns>True if it can be installed, false otherwise.</returns>
public bool CanInstallMechanism(Mechanism mechanism)
{
return SizeUsed + mechanism.Size <= Size &&
@@ -336,7 +273,7 @@ namespace Content.Server.Body
/// <param name="mechanism">The mechanism to try to install.</param>
/// <returns>
/// True if successful, false if there was an error
/// (e.g. not enough room in <see cref="BodyPart"/>).
/// (e.g. not enough room in <see cref="IBodyPart"/>).
/// </returns>
private bool TryInstallMechanism(Mechanism mechanism)
{
@@ -352,7 +289,7 @@ namespace Content.Server.Body
/// <summary>
/// Tries to install a <see cref="DroppedMechanismComponent"/> into this
/// <see cref="BodyPart"/>, potentially deleting the dropped
/// <see cref="IBodyPart"/>, potentially deleting the dropped
/// <see cref="IEntity"/>.
/// </summary>
/// <param name="droppedMechanism">The mechanism to install.</param>
@@ -371,14 +308,6 @@ namespace Content.Server.Body
return true;
}
/// <summary>
/// Tries to remove the given <see cref="Mechanism"/> reference from
/// this <see cref="BodyPart"/>.
/// </summary>
/// <returns>
/// The newly spawned <see cref="DroppedMechanismComponent"/>, or null
/// if there was an error in spawning the entity or removing the mechanism.
/// </returns>
public bool TryDropMechanism(IEntity dropLocation, Mechanism mechanismTarget,
[NotNullWhen(true)] out DroppedMechanismComponent dropped)
{
@@ -403,11 +332,11 @@ namespace Content.Server.Body
/// <summary>
/// Tries to destroy the given <see cref="Mechanism"/> in this
/// <see cref="BodyPart"/>. Does NOT spawn a dropped entity.
/// <see cref="IBodyPart"/>. Does NOT spawn a dropped entity.
/// </summary>
/// <summary>
/// Tries to destroy the given <see cref="Mechanism"/> in this
/// <see cref="BodyPart"/>.
/// <see cref="IBodyPart"/>.
/// </summary>
/// <param name="mechanismTarget">The mechanism to destroy.</param>
/// <returns>True if successful, false otherwise.</returns>
@@ -421,18 +350,13 @@ namespace Content.Server.Body
return true;
}
/// <summary>
/// Checks if the given <see cref="SurgeryType"/> can be used on
/// the current state of this <see cref="BodyPart"/>.
/// </summary>
/// <returns>True if it can be used, false otherwise.</returns>
public bool SurgeryCheck(SurgeryType toolType)
public bool SurgeryCheck(SurgeryType surgery)
{
return SurgeryData.CheckSurgery(toolType);
return SurgeryData.CheckSurgery(surgery);
}
/// <summary>
/// Attempts to perform surgery on this <see cref="BodyPart"/> with the given
/// Attempts to perform surgery on this <see cref="IBodyPart"/> with the given
/// tool.
/// </summary>
/// <returns>True if successful, false if there was an error.</returns>
@@ -474,7 +398,7 @@ namespace Content.Server.Body
/// <summary>
/// Tries to remove the given <see cref="mechanism"/> from this
/// <see cref="BodyPart"/>.
/// <see cref="IBodyPart"/>.
/// </summary>
/// <param name="mechanism">The mechanism to remove.</param>
/// <returns>True if it was removed, false otherwise.</returns>
@@ -515,7 +439,7 @@ namespace Content.Server.Body
/// <summary>
/// Loads the given <see cref="BodyPartPrototype"/>.
/// Current data on this <see cref="BodyPart"/> will be overwritten!
/// Current data on this <see cref="IBodyPart"/> will be overwritten!
/// </summary>
protected virtual void LoadFromPrototype(BodyPartPrototype data)
{

View File

@@ -21,7 +21,7 @@ namespace Content.Server.Body
[ViewVariables] public string Name { get; private set; }
/// <summary>
/// Maps a template slot to the ID of the <see cref="BodyPart"/> that should
/// Maps a template slot to the ID of the <see cref="IBodyPart"/> that should
/// fill it. E.g. "right arm" : "BodyPart.arm.basic_human".
/// </summary>
[ViewVariables]

View File

@@ -0,0 +1,131 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Body.Mechanisms;
using Content.Server.GameObjects.Components.Body;
using Content.Shared.Body.Part.Properties;
using Content.Shared.GameObjects.Components.Body;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
namespace Content.Server.Body
{
public interface IBodyPart
{
/// <summary>
/// The body that this body part is currently in, if any.
/// </summary>
IBodyManagerComponent? Body { get; set; }
/// <summary>
/// <see cref="BodyPartType"/> that this <see cref="IBodyPart"/> is considered
/// to be.
/// For example, <see cref="BodyPartType.Arm"/>.
/// </summary>
BodyPartType PartType { get; }
/// <summary>
/// The name of this <see cref="IBodyPart"/>, often displayed to the user.
/// For example, it could be named "advanced robotic arm".
/// </summary>
public string Name { get; }
/// <summary>
/// Plural version of this <see cref="IBodyPart"/> name.
/// </summary>
public string Plural { get; }
/// <summary>
/// Determines many things: how many mechanisms can be fit inside this
/// <see cref="IBodyPart"/>, whether a body can fit through tiny crevices,
/// etc.
/// </summary>
int Size { get; }
/// <summary>
/// Max HP of this <see cref="IBodyPart"/>.
/// </summary>
int MaxDurability { get; }
/// <summary>
/// Current HP of this <see cref="IBodyPart"/> based on sum of all damage types.
/// </summary>
int CurrentDurability { get; }
/// <summary>
/// Collection of all <see cref="Mechanism"/>s currently inside this
/// <see cref="IBodyPart"/>.
/// To add and remove from this list see <see cref="AddMechanism"/> and
/// <see cref="RemoveMechanism"/>
/// </summary>
IReadOnlyCollection<Mechanism> Mechanisms { get; }
/// <summary>
/// Path to the RSI that represents this <see cref="IBodyPart"/>.
/// </summary>
public string RSIPath { get; }
/// <summary>
/// RSI state that represents this <see cref="IBodyPart"/>.
/// </summary>
public string RSIState { get; }
/// <summary>
/// RSI map keys that this body part changes on the sprite.
/// </summary>
public Enum? RSIMap { get; set; }
/// <summary>
/// RSI color of this body part.
/// </summary>
// TODO: SpriteComponent rework
public Color? RSIColor { get; set; }
bool HasProperty<T>() where T : BodyPartProperty;
bool HasProperty(Type type);
bool TryGetProperty<T>([NotNullWhen(true)] out T? property) where T : BodyPartProperty;
void PreMetabolism(float frameTime);
void PostMetabolism(float frameTime);
bool SpawnDropped([NotNullWhen(true)] out IEntity? dropped);
/// <summary>
/// Checks if the given <see cref="SurgeryType"/> can be used on
/// the current state of this <see cref="IBodyPart"/>.
/// </summary>
/// <returns>True if it can be used, false otherwise.</returns>
bool SurgeryCheck(SurgeryType surgery);
/// <summary>
/// Checks if another <see cref="IBodyPart"/> can be connected to this one.
/// </summary>
/// <param name="part">The part to connect.</param>
/// <returns>True if it can be connected, false otherwise.</returns>
bool CanAttachPart(IBodyPart part);
/// <summary>
/// Checks if a <see cref="Mechanism"/> can be installed on this
/// <see cref="IBodyPart"/>.
/// </summary>
/// <returns>True if it can be installed, false otherwise.</returns>
bool CanInstallMechanism(Mechanism mechanism);
/// <summary>
/// Tries to remove the given <see cref="Mechanism"/> reference from
/// this <see cref="IBodyPart"/>.
/// </summary>
/// <returns>
/// The newly spawned <see cref="DroppedMechanismComponent"/>, or null
/// if there was an error in spawning the entity or removing the mechanism.
/// </returns>
bool TryDropMechanism(IEntity dropLocation, Mechanism mechanismTarget,
[NotNullWhen(true)] out DroppedMechanismComponent dropped);
bool DestroyMechanism(Mechanism mechanism);
}
}

View File

@@ -7,11 +7,11 @@ namespace Content.Server.Body
/// Making a class inherit from this interface allows you to do many things with
/// it in the <see cref="SurgeryData"/> class.
/// This includes passing it as an argument to a
/// <see cref="SurgeryData.SurgeryAction"/> delegate, as to later typecast it back
/// to the original class type.
/// Every BodyPart also needs an <see cref="IBodyPartContainer"/> to be its parent
/// (i.e. the <see cref="BodyManagerComponent"/> holds many <see cref="BodyPart"/>,
/// each of which have an upward reference to it).
/// <see cref="SurgeryData.SurgeryAction"/> delegate, as to later typecast
/// it back to the original class type.
/// Every BodyPart also needs an <see cref="IBodyPartContainer"/> to be
/// its parent (i.e. the <see cref="BodyManagerComponent"/> holds many
/// <see cref="IBodyPart"/>, each of which have an upward reference to it).
/// </summary>
public interface IBodyPartContainer
{

View File

@@ -70,7 +70,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
}
/// <summary>
/// Called when the containing <see cref="BodyPart"/> is attached to a
/// Called when the containing <see cref="IBodyPart"/> is attached to a
/// <see cref="BodyManagerComponent"/>.
/// For instance, attaching a head to a body will call this on the brain inside.
/// </summary>
@@ -82,7 +82,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
/// <summary>
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
/// installed into a <see cref="BodyPart"/>.
/// installed into a <see cref="IBodyPart"/>.
/// For instance, putting a brain into an empty head.
/// </summary>
public void InstalledIntoPart()
@@ -92,22 +92,22 @@ namespace Content.Server.Body.Mechanisms.Behaviors
}
/// <summary>
/// Called when the containing <see cref="BodyPart"/> is removed from a
/// Called when the containing <see cref="IBodyPart"/> is removed from a
/// <see cref="BodyManagerComponent"/>.
/// For instance, cutting off ones head will call this on the brain inside.
/// </summary>
public void RemovedFromBody(BodyManagerComponent old)
public void RemovedFromBody(IBodyManagerComponent old)
{
OnRemovedFromBody(old);
TryRemoveNetwork(old);
}
/// <summary>
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is removed from a
/// <see cref="BodyPart"/>.
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
/// removed from a <see cref="IBodyPart"/>.
/// For instance, taking a brain out of ones head.
/// </summary>
public void RemovedFromPart(BodyPart old)
public void RemovedFromPart(IBodyPart old)
{
OnRemovedFromPart(old);
TryRemoveNetwork(old.Body);
@@ -121,7 +121,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
}
}
private void TryRemoveNetwork(BodyManagerComponent? body)
private void TryRemoveNetwork(IBodyManagerComponent? body)
{
if (Network != null)
{
@@ -137,7 +137,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
protected virtual void OnRemove() { }
/// <summary>
/// Called when the containing <see cref="BodyPart"/> is attached to a
/// Called when the containing <see cref="IBodyPart"/> is attached to a
/// <see cref="BodyManagerComponent"/>.
/// For instance, attaching a head to a body will call this on the brain inside.
/// </summary>
@@ -145,24 +145,24 @@ namespace Content.Server.Body.Mechanisms.Behaviors
/// <summary>
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
/// installed into a <see cref="BodyPart"/>.
/// installed into a <see cref="IBodyPart"/>.
/// For instance, putting a brain into an empty head.
/// </summary>
protected virtual void OnInstalledIntoPart() { }
/// <summary>
/// Called when the containing <see cref="BodyPart"/> is removed from a
/// Called when the containing <see cref="IBodyPart"/> is removed from a
/// <see cref="BodyManagerComponent"/>.
/// For instance, cutting off ones head will call this on the brain inside.
/// </summary>
protected virtual void OnRemovedFromBody(BodyManagerComponent old) { }
protected virtual void OnRemovedFromBody(IBodyManagerComponent old) { }
/// <summary>
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is removed from a
/// <see cref="BodyPart"/>.
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
/// removed from a <see cref="IBodyPart"/>.
/// For instance, taking a brain out of ones head.
/// </summary>
protected virtual void OnRemovedFromPart(BodyPart old) { }
protected virtual void OnRemovedFromPart(IBodyPart old) { }
/// <summary>
/// Called every update when this behavior is connected to a

View File

@@ -12,13 +12,13 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Mechanisms
{
/// <summary>
/// Data class representing a persistent item inside a <see cref="BodyPart"/>.
/// Data class representing a persistent item inside a <see cref="IBodyPart"/>.
/// This includes livers, eyes, cameras, brains, explosive implants,
/// binary communicators, and other things.
/// </summary>
public class Mechanism
{
private BodyPart? _part;
private IBodyPart? _part;
public Mechanism(MechanismPrototype data)
{
@@ -91,13 +91,13 @@ namespace Content.Server.Body.Mechanisms
/// <summary>
/// Determines a handful of things - mostly whether this
/// <see cref="Mechanism"/> can fit into a <see cref="BodyPart"/>.
/// <see cref="Mechanism"/> can fit into a <see cref="IBodyPart"/>.
/// </summary>
[ViewVariables]
public int Size { get; set; }
/// <summary>
/// What kind of <see cref="BodyPart"/> this <see cref="Mechanism"/> can be
/// What kind of <see cref="IBodyPart"/> this <see cref="Mechanism"/> can be
/// easily installed into.
/// </summary>
[ViewVariables]
@@ -109,9 +109,9 @@ namespace Content.Server.Body.Mechanisms
[ViewVariables]
private List<MechanismBehavior> Behaviors { get; }
public BodyManagerComponent? Body => Part?.Body;
public IBodyManagerComponent? Body => Part?.Body;
public BodyPart? Part
public IBodyPart? Part
{
get => _part;
set
@@ -202,7 +202,7 @@ namespace Content.Server.Body.Mechanisms
}
}
public void RemovedFromBody(BodyManagerComponent old)
public void RemovedFromBody(IBodyManagerComponent old)
{
foreach (var behavior in Behaviors)
{
@@ -211,7 +211,7 @@ namespace Content.Server.Body.Mechanisms
}
/// <summary>
/// This method is called by <see cref="BodyPart.PreMetabolism"/> before
/// This method is called by <see cref="IBodyPart.PreMetabolism"/> before
/// <see cref="MetabolismComponent.Update"/> is called.
/// </summary>
public void PreMetabolism(float frameTime)
@@ -223,7 +223,7 @@ namespace Content.Server.Body.Mechanisms
}
/// <summary>
/// This method is called by <see cref="BodyPart.PostMetabolism"/> after
/// This method is called by <see cref="IBodyPart.PostMetabolism"/> after
/// <see cref="MetabolismComponent.Update"/> is called.
/// </summary>
public void PostMetabolism(float frameTime)

View File

@@ -23,7 +23,7 @@ namespace Content.Server.Body.Surgery
private bool _skinRetracted;
private bool _vesselsClamped;
public BiologicalSurgeryData(BodyPart parent) : base(parent) { }
public BiologicalSurgeryData(IBodyPart parent) : base(parent) { }
protected override SurgeryAction? GetSurgeryStep(SurgeryType toolType)
{
@@ -123,7 +123,7 @@ namespace Content.Server.Body.Surgery
return _skinOpened && _vesselsClamped && _skinRetracted;
}
public override bool CanAttachBodyPart(BodyPart part)
public override bool CanAttachBodyPart(IBodyPart part)
{
return true;
// TODO: if a bodypart is disconnected, you should have to do some surgery to allow another bodypart to be attached.
@@ -216,8 +216,7 @@ namespace Content.Server.Body.Surgery
}
}
private void RemoveOrganSurgeryCallback(Mechanism target, IBodyPartContainer container,
ISurgeon surgeon,
private void RemoveOrganSurgeryCallback(Mechanism target, IBodyPartContainer container, ISurgeon surgeon,
IEntity performer)
{
if (target == null || !Parent.Mechanisms.Contains(target))

View File

@@ -6,7 +6,7 @@ using Robust.Shared.Interfaces.GameObjects;
namespace Content.Server.Body.Surgery
{
/// <summary>
/// This data class represents the state of a <see cref="BodyPart"/> in regards to everything surgery related -
/// This data class represents the state of a <see cref="IBodyPart"/> in regards to everything surgery related -
/// whether there's an incision on it, whether the bone is broken, etc.
/// </summary>
public abstract class SurgeryData
@@ -14,40 +14,40 @@ namespace Content.Server.Body.Surgery
protected delegate void SurgeryAction(IBodyPartContainer container, ISurgeon surgeon, IEntity performer);
/// <summary>
/// The <see cref="BodyPart"/> this surgeryData is attached to.
/// The <see cref="IBodyPart"/> this surgeryData is attached to.
/// The <see cref="SurgeryData"/> class should not exist without a
/// <see cref="BodyPart"/> that it represents, and will throw errors if it
/// <see cref="IBodyPart"/> that it represents, and will throw errors if it
/// is null.
/// </summary>
protected readonly BodyPart Parent;
protected readonly IBodyPart Parent;
protected SurgeryData(BodyPart parent)
protected SurgeryData(IBodyPart parent)
{
Parent = parent;
}
/// <summary>
/// The <see cref="BodyPartType"/> of the parent <see cref="BodyPart"/>.
/// The <see cref="BodyPartType"/> of the parent <see cref="IBodyPart"/>.
/// </summary>
protected BodyPartType ParentType => Parent.PartType;
/// <summary>
/// Returns the description of this current <see cref="BodyPart"/> to be shown
/// Returns the description of this current <see cref="IBodyPart"/> 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 <see cref="SurgeryData"/> represents.
/// <see cref="IBodyPart"/> this <see cref="SurgeryData"/> represents.
/// </summary>
public abstract bool CanInstallMechanism(Mechanism mechanism);
/// <summary>
/// Returns whether the given <see cref="BodyPart"/> can be connected to the
/// <see cref="BodyPart"/> this <see cref="SurgeryData"/> represents.
/// Returns whether the given <see cref="IBodyPart"/> can be connected to the
/// <see cref="IBodyPart"/> this <see cref="SurgeryData"/> represents.
/// </summary>
public abstract bool CanAttachBodyPart(BodyPart part);
public abstract bool CanAttachBodyPart(IBodyPart part);
/// <summary>
/// Gets the delegate corresponding to the surgery step using the given

View File

@@ -8,7 +8,6 @@ using Content.Server.Body.Network;
using Content.Server.GameObjects.Components.Metabolism;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Server.Mobs;
using Content.Server.Observer;
using Content.Shared.Body.Part;
using Content.Shared.Body.Part.Properties.Movement;
@@ -34,13 +33,14 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Body
{
/// <summary>
/// Component representing a collection of <see cref="BodyPart"></see>
/// Component representing a collection of <see cref="IBodyPart"></see>
/// attached to each other.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(IDamageableComponent))]
[ComponentReference(typeof(ISharedBodyManagerComponent))]
public class BodyManagerComponent : SharedBodyManagerComponent, IBodyPartContainer, IRelayMoveInput
[ComponentReference(typeof(IBodyManagerComponent))]
public class BodyManagerComponent : SharedBodyManagerComponent, IBodyPartContainer, IRelayMoveInput, IBodyManagerComponent
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IBodyNetworkFactory _bodyNetworkFactory = default!;
@@ -48,38 +48,28 @@ namespace Content.Server.GameObjects.Components.Body
[ViewVariables] private string _presetName = default!;
private readonly Dictionary<string, BodyPart> _parts = new Dictionary<string, BodyPart>();
private readonly Dictionary<string, IBodyPart> _parts = new Dictionary<string, IBodyPart>();
[ViewVariables] private readonly Dictionary<Type, BodyNetwork> _networks = new Dictionary<Type, BodyNetwork>();
/// <summary>
/// All <see cref="BodyPart"></see> with <see cref="LegProperty"></see>
/// All <see cref="IBodyPart"></see> with <see cref="LegProperty"></see>
/// that are currently affecting move speed, mapped to how big that leg
/// they're on is.
/// </summary>
[ViewVariables]
private readonly Dictionary<BodyPart, float> _activeLegs = new Dictionary<BodyPart, float>();
private readonly Dictionary<IBodyPart, float> _activeLegs = new Dictionary<IBodyPart, float>();
[ViewVariables] public BodyTemplate Template { get; private set; } = default!;
[ViewVariables] public BodyPreset Preset { get; private set; } = default!;
/// <summary>
/// The <see cref="BodyTemplate"/> that this <see cref="BodyManagerComponent"/>
/// is adhering to.
/// </summary>
[ViewVariables]
public BodyTemplate Template { get; private set; } = default!;
/// <summary>
/// The <see cref="BodyPreset"/> that this <see cref="BodyManagerComponent"/>
/// is adhering to.
/// </summary>
[ViewVariables]
public BodyPreset Preset { get; private set; } = default!;
/// <summary>
/// Maps <see cref="BodyTemplate"/> slot name to the <see cref="BodyPart"/>
/// Maps <see cref="BodyTemplate"/> slot name to the <see cref="IBodyPart"/>
/// object filling it (if there is one).
/// </summary>
[ViewVariables]
public IReadOnlyDictionary<string, BodyPart> Parts => _parts;
public IReadOnlyDictionary<string, IBodyPart> Parts => _parts;
/// <summary>
/// List of all slots in this body, taken from the keys of
@@ -171,7 +161,7 @@ namespace Content.Server.GameObjects.Components.Body
// Add a new BodyPart with the BodyPartPrototype as a baseline to our
// BodyComponent.
var addedPart = new BodyPart(newPartData);
AddBodyPart(addedPart, slotName);
TryAddPart(slotName, addedPart);
}
OnBodyChanged(); // TODO: Duplicate code
@@ -180,8 +170,8 @@ namespace Content.Server.GameObjects.Components.Body
/// <summary>
/// Changes the current <see cref="BodyTemplate"/> to the given
/// <see cref="BodyTemplate"/>.
/// Attempts to keep previous <see cref="BodyPart"/> if there is a slot for
/// them in both <see cref="BodyTemplate"/>.
/// Attempts to keep previous <see cref="IBodyPart"/> if there is a
/// slot for them in both <see cref="BodyTemplate"/>.
/// </summary>
public void ChangeBodyTemplate(BodyTemplatePrototype newTemplate)
{
@@ -280,10 +270,10 @@ namespace Content.Server.GameObjects.Components.Body
foreach (var (key, value) in _activeLegs)
{
if (key.TryGetProperty(out LegProperty legProperty))
if (key.TryGetProperty(out LegProperty? leg))
{
// Speed of a leg = base speed * (1+log1024(leg length))
speedSum += legProperty.Speed * (1 + (float) Math.Log(value, 1024.0));
speedSum += leg.Speed * (1 + (float) Math.Log(value, 1024.0));
}
}
@@ -321,11 +311,11 @@ namespace Content.Server.GameObjects.Components.Body
/// <summary>
/// Recursively searches for if <see cref="target"/> is connected to
/// the center. Not efficient (O(n^2)), but most bodies don't have a ton
/// of <see cref="BodyPart"/>s.
/// of <see cref="IBodyPart"/>s.
/// </summary>
/// <param name="target">The body part to find the center for.</param>
/// <returns>True if it is connected to the center, false otherwise.</returns>
private bool ConnectedToCenterPart(BodyPart target)
private bool ConnectedToCenterPart(IBodyPart target)
{
var searchedSlots = new List<string>();
@@ -335,9 +325,7 @@ namespace Content.Server.GameObjects.Components.Body
private bool ConnectedToCenterPartRecursion(ICollection<string> searchedSlots, string slotName)
{
TryGetBodyPart(slotName, out var part);
if (part == null)
if (!TryGetBodyPart(slotName, out var part))
{
return false;
}
@@ -367,14 +355,14 @@ namespace Content.Server.GameObjects.Components.Body
}
/// <summary>
/// Finds the central <see cref="BodyPart"/>, if any, of this body based on
/// Finds the central <see cref="IBodyPart"/>, if any, of this body based on
/// the <see cref="BodyTemplate"/>. For humans, this is the torso.
/// </summary>
/// <returns>The <see cref="BodyPart"/> if one exists, null otherwise.</returns>
private BodyPart? GetCenterBodyPart()
private IBodyPart? GetCenterBodyPart()
{
Parts.TryGetValue(Template.CenterSlot, out var center);
return center!;
return center;
}
/// <summary>
@@ -387,29 +375,31 @@ namespace Content.Server.GameObjects.Components.Body
}
/// <summary>
/// Finds the <see cref="BodyPart"/> in the given <see cref="slotName"/> if
/// Finds the <see cref="IBodyPart"/> in the given <see cref="slotName"/> if
/// one exists.
/// </summary>
/// <param name="slotName">The slot to search in.</param>
/// <param name="result">The body part in that slot, if any.</param>
/// <returns>True if found, false otherwise.</returns>
private bool TryGetBodyPart(string slotName, [NotNullWhen(true)] out BodyPart result)
private bool TryGetBodyPart(string slotName, [NotNullWhen(true)] out IBodyPart? result)
{
return Parts.TryGetValue(slotName, out result!);
}
/// <summary>
/// Finds the slotName that the given <see cref="BodyPart"/> resides in.
/// Finds the slotName that the given <see cref="IBodyPart"/> resides in.
/// </summary>
/// <param name="part">The <see cref="BodyPart"/> to find the slot for.</param>
/// <param name="part">The <see cref="IBodyPart"/> to find the slot for.</param>
/// <param name="result">The slot found, if any.</param>
/// <returns>True if a slot was found, false otherwise</returns>
private bool TryGetSlotName(BodyPart part, [NotNullWhen(true)] out string result)
private bool TryGetSlotName(IBodyPart part, [NotNullWhen(true)] out string result)
{
// We enforce that there is only one of each value in the dictionary,
// so we can iterate through the dictionary values to get the key from there.
result = Parts.FirstOrDefault(x => x.Value == part).Key;
return result != null;
var pair = Parts.FirstOrDefault(x => x.Value == part);
result = pair.Key;
return !pair.Equals(default);
}
/// <summary>
@@ -448,7 +438,7 @@ namespace Content.Server.GameObjects.Components.Body
/// True if successful, false if there was an error or no connected
/// <see cref="BodyPart"/>s were found.
/// </returns>
public bool TryGetBodyPartConnections(string slotName, [NotNullWhen(true)] out List<BodyPart> result)
public bool TryGetBodyPartConnections(string slotName, [NotNullWhen(true)] out List<IBodyPart> result)
{
result = null!;
@@ -457,7 +447,7 @@ namespace Content.Server.GameObjects.Components.Body
return false;
}
var toReturn = new List<BodyPart>();
var toReturn = new List<IBodyPart>();
foreach (var connection in connections)
{
if (TryGetBodyPart(connection, out var bodyPartResult))
@@ -481,9 +471,9 @@ namespace Content.Server.GameObjects.Components.Body
/// </summary>
/// <returns>
/// True if successful, false if there was an error or no connected
/// <see cref="BodyPart"/>s were found.
/// <see cref="IBodyPart"/>s were found.
/// </returns>
private bool TryGetBodyPartConnections(BodyPart part, [NotNullWhen(true)] out List<BodyPart> result)
private bool TryGetBodyPartConnections(IBodyPart part, [NotNullWhen(true)] out List<IBodyPart> result)
{
result = null!;
@@ -492,11 +482,11 @@ namespace Content.Server.GameObjects.Components.Body
}
/// <summary>
/// Grabs all <see cref="BodyPart"/> of the given type in this body.
/// Grabs all <see cref="IBodyPart"/> of the given type in this body.
/// </summary>
public List<BodyPart> GetBodyPartsOfType(BodyPartType type)
public List<IBodyPart> GetBodyPartsOfType(BodyPartType type)
{
var toReturn = new List<BodyPart>();
var toReturn = new List<IBodyPart>();
foreach (var part in Parts.Values)
{
@@ -509,32 +499,6 @@ namespace Content.Server.GameObjects.Components.Body
return toReturn;
}
/// <summary>
/// Installs the given <see cref="BodyPart"/> into the given slot.
/// </summary>
/// <returns>True if successful, false otherwise.</returns>
public bool InstallBodyPart(BodyPart part, string slotName)
{
DebugTools.AssertNotNull(part);
// Make sure the given slot exists
if (!SlotExists(slotName))
{
return false;
}
// And that nothing is in it
if (TryGetBodyPart(slotName, out _))
{
return false;
}
AddBodyPart(part, slotName); // TODO: Sort this duplicate out
OnBodyChanged();
return true;
}
/// <summary>
/// Installs the given <see cref="DroppedBodyPartComponent"/> into the
/// given slot, deleting the <see cref="IEntity"/> afterwards.
@@ -544,7 +508,7 @@ namespace Content.Server.GameObjects.Components.Body
{
DebugTools.AssertNotNull(part);
if (!InstallBodyPart(part.ContainedBodyPart, slotName))
if (!TryAddPart(slotName, part.ContainedBodyPart))
{
return false;
}
@@ -554,15 +518,15 @@ namespace Content.Server.GameObjects.Components.Body
}
/// <summary>
/// Disconnects the given <see cref="BodyPart"/> reference, potentially
/// dropping other <see cref="BodyPart">BodyParts</see> if they were hanging
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
/// off of it.
/// </summary>
/// <returns>
/// The <see cref="IEntity"/> representing the dropped
/// <see cref="BodyPart"/>, or null if none was dropped.
/// <see cref="IBodyPart"/>, or null if none was dropped.
/// </returns>
public IEntity? DropPart(BodyPart part)
public IEntity? DropPart(IBodyPart part)
{
DebugTools.AssertNotNull(part);
@@ -596,11 +560,11 @@ namespace Content.Server.GameObjects.Components.Body
}
/// <summary>
/// Disconnects the given <see cref="BodyPart"/> reference, potentially
/// dropping other <see cref="BodyPart">BodyParts</see> if they were hanging
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
/// off of it.
/// </summary>
public void DisconnectBodyPart(BodyPart part, bool dropEntity)
public void DisconnectBodyPart(IBodyPart part, bool dropEntity)
{
DebugTools.AssertNotNull(part);
@@ -640,12 +604,7 @@ namespace Content.Server.GameObjects.Components.Body
{
DebugTools.AssertNotNull(slotName);
if (!TryGetBodyPart(slotName, out var part))
{
return;
}
if (part == null)
if (!HasPart(slotName))
{
return;
}
@@ -666,27 +625,47 @@ namespace Content.Server.GameObjects.Components.Body
OnBodyChanged();
}
private void AddBodyPart(BodyPart part, string slotName)
public bool TryAddPart(string slot, IBodyPart part, bool force = false)
{
DebugTools.AssertNotNull(part);
DebugTools.AssertNotNull(slotName);
DebugTools.AssertNotNull(slot);
_parts.Add(slotName, part);
// Make sure the given slot exists
if (!force)
{
if (!SlotExists(slot))
{
return false;
}
// And that nothing is in it
if (!_parts.TryAdd(slot, part))
{
return false;
}
}
else
{
_parts[slot] = part;
}
part.Body = this;
var argsAdded = new BodyPartAddedEventArgs(part, slotName);
var argsAdded = new BodyPartAddedEventArgs(part, slot);
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray())
{
component.BodyPartAdded(argsAdded);
}
if (!Template.Layers.TryGetValue(slotName, out var partMap) ||
// TODO: Sort this duplicate out
OnBodyChanged();
if (!Template.Layers.TryGetValue(slot, out var partMap) ||
!_reflectionManager.TryParseEnumReference(partMap, out var partEnum))
{
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {partMap} for body part {part.Name}.");
return;
return false;
}
part.RSIMap = partEnum;
@@ -712,6 +691,13 @@ namespace Content.Server.GameObjects.Components.Body
SendNetworkMessage(mechanismMessage);
}
return true;
}
public bool HasPart(string slot)
{
return _parts.ContainsKey(slot);
}
/// <summary>
@@ -720,7 +706,7 @@ namespace Content.Server.GameObjects.Components.Body
/// </summary>
/// <param name="slotName">The slot to remove it from.</param>
/// <param name="drop">
/// Whether or not to drop the removed <see cref="BodyPart"/>.
/// Whether or not to drop the removed <see cref="IBodyPart"/>.
/// </param>
/// <returns></returns>
private bool RemoveBodyPart(string slotName, bool drop)
@@ -780,17 +766,20 @@ namespace Content.Server.GameObjects.Components.Body
/// <param name="part">The part to remove from this body.</param>
/// <param name="slotName">The slot that the part was in, if any.</param>
/// <returns>True if <see cref="part"/> was removed, false otherwise.</returns>
private bool RemoveBodyPart(BodyPart part, [NotNullWhen(true)] out string slotName)
private bool RemoveBodyPart(IBodyPart part, [NotNullWhen(true)] out string? slotName)
{
DebugTools.AssertNotNull(part);
slotName = _parts.FirstOrDefault(pair => pair.Value == part).Key;
var pair = _parts.FirstOrDefault(kvPair => kvPair.Value == part);
if (slotName == null)
if (pair.Equals(default))
{
slotName = null;
return false;
}
slotName = pair.Key;
return RemoveBodyPart(slotName, false);
}
@@ -804,13 +793,13 @@ namespace Content.Server.GameObjects.Components.Body
if (_networks.ContainsKey(network.GetType()))
{
return false;
return true;
}
_networks.Add(network.GetType(), network);
network.OnAdd(Owner);
return true;
return false;
}
/// <summary>
@@ -844,62 +833,21 @@ namespace Content.Server.GameObjects.Components.Body
return EnsureNetwork(typeof(T));
}
/// <summary>
/// Attempts to add a <see cref="BodyNetwork"/> of the given name to
/// this body.
/// </summary>
/// <returns>
/// True if successful, false if there was an error
/// (such as passing in an invalid type or a network of that type already
/// existing).
/// </returns>
private bool EnsureNetwork(string networkName)
public void RemoveNetwork(Type networkType)
{
DebugTools.AssertNotNull(networkName);
DebugTools.AssertNotNull(networkType);
var network = _bodyNetworkFactory.GetNetwork(networkName);
return EnsureNetwork(network);
}
/// <summary>
/// Removes the <see cref="BodyNetwork"/> of the given type in this body,
/// if there is one.
/// </summary>
/// <param name="type">The type of the network to remove.</param>
public void RemoveNetwork(Type type)
{
DebugTools.AssertNotNull(type);
if (_networks.Remove(type, out var network))
if (_networks.Remove(networkType, out var network))
{
network.OnRemove();
}
}
/// <summary>
/// Removes the <see cref="BodyNetwork"/> of the given type in this body,
/// if one exists.
/// </summary>
/// <typeparam name="T">The type of the network to remove.</typeparam>
public void RemoveNetwork<T>() where T : BodyNetwork
{
RemoveNetwork(typeof(T));
}
/// <summary>
/// Removes the <see cref="BodyNetwork"/> with the given name in this body,
/// if there is one.
/// </summary>
private void RemoveNetwork(string networkName)
{
var type = _bodyNetworkFactory.GetNetwork(networkName).GetType();
if (_networks.Remove(type, out var network))
{
network.OnRemove();
}
}
/// <summary>
/// Attempts to get the <see cref="BodyNetwork"/> of the given type in this body.
/// </summary>
@@ -924,7 +872,7 @@ namespace Content.Server.GameObjects.Components.Body
/// a foot node from the given node. It can
/// only search through BodyParts with <see cref="ExtensionProperty"/>.
/// </summary>
private static float DistanceToNearestFoot(BodyManagerComponent body, BodyPart source)
private static float DistanceToNearestFoot(BodyManagerComponent body, IBodyPart source)
{
if (source.HasProperty<FootProperty>() && source.TryGetProperty<ExtensionProperty>(out var property))
{
@@ -934,7 +882,8 @@ namespace Content.Server.GameObjects.Components.Body
return LookForFootRecursion(body, source, new List<BodyPart>());
}
private static float LookForFootRecursion(BodyManagerComponent body, BodyPart current,
// TODO: Make this not static and not keep me up at night
private static float LookForFootRecursion(BodyManagerComponent body, IBodyPart current,
ICollection<BodyPart> searchedParts)
{
if (!current.TryGetProperty<ExtensionProperty>(out var extProperty))

View File

@@ -56,7 +56,7 @@ namespace Content.Server.GameObjects.Components.Body
/// <summary>
/// Copy BodyTemplate and BodyPart data into a common data class that the client can read.
/// </summary>
private BodyScannerInterfaceState InterfaceState(BodyTemplate template, IReadOnlyDictionary<string, BodyPart> bodyParts)
private BodyScannerInterfaceState InterfaceState(BodyTemplate template, IReadOnlyDictionary<string, IBodyPart> bodyParts)
{
var partsData = new Dictionary<string, BodyScannerBodyPartData>();

View File

@@ -101,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Body
foreach (var connectedPart in parts)
{
if (!connectedPart.CanAttachBodyPart(ContainedBodyPart))
if (!connectedPart.CanAttachPart(ContainedBodyPart))
{
continue;
}

View File

@@ -0,0 +1,67 @@
using System;
using Content.Server.Body;
using Content.Server.Body.Network;
using Content.Shared.GameObjects.Components.Body;
namespace Content.Server.GameObjects.Components.Body
{
// TODO: Merge with ISharedBodyManagerComponent
public interface IBodyManagerComponent : ISharedBodyManagerComponent
{
/// <summary>
/// The <see cref="BodyTemplate"/> that this <see cref="BodyManagerComponent"/>
/// is adhering to.
/// </summary>
public BodyTemplate Template { get; }
/// <summary>
/// The <see cref="BodyPreset"/> that this <see cref="BodyManagerComponent"/>
/// is adhering to.
/// </summary>
public BodyPreset Preset { get; }
/// <summary>
/// Installs the given <see cref="IBodyPart"/> into the given slot.
/// </summary>
/// <returns>True if successful, false otherwise.</returns>
bool TryAddPart(string slot, IBodyPart part, bool force = false);
bool HasPart(string slot);
/// <summary>
/// Ensures that this body has the specified network.
/// </summary>
/// <typeparam name="T">The type of the network to ensure.</typeparam>
/// <returns>
/// True if the network already existed, false if it had to be created.
/// </returns>
bool EnsureNetwork<T>() where T : BodyNetwork;
/// <summary>
/// Ensures that this body has the specified network.
/// </summary>
/// <param name="networkType">The type of the network to ensure.</param>
/// <returns>
/// True if the network already existed, false if it had to be created.
/// </returns>
bool EnsureNetwork(Type networkType);
/// <summary>
/// Removes the <see cref="BodyNetwork"/> of the given type in this body,
/// if one exists.
/// </summary>
/// <typeparam name="T">The type of the network to remove.</typeparam>
void RemoveNetwork<T>() where T : BodyNetwork;
/// <summary>
/// Removes the <see cref="BodyNetwork"/> of the given type in this body,
/// if there is one.
/// </summary>
/// <param name="networkType">The type of the network to remove.</param>
void RemoveNetwork(Type networkType);
void PreMetabolism(float frameTime);
void PostMetabolism(float frameTime);
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Body;
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Body;

View File

@@ -14,13 +14,13 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
public class BodyPartAddedEventArgs : EventArgs
{
public BodyPartAddedEventArgs(BodyPart part, string slotName)
public BodyPartAddedEventArgs(IBodyPart part, string slotName)
{
Part = part;
SlotName = slotName;
}
public BodyPart Part { get; }
public IBodyPart Part { get; }
public string SlotName { get; }
}
@@ -36,13 +36,13 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
public class BodyPartRemovedEventArgs : EventArgs
{
public BodyPartRemovedEventArgs(BodyPart part, string slotName)
public BodyPartRemovedEventArgs(IBodyPart part, string slotName)
{
Part = part;
SlotName = slotName;
}
public BodyPart Part { get; }
public IBodyPart Part { get; }
public string SlotName { get; }
}