Add body part and body manager interfaces (#1939)
* Add body part and body manager interfaces * Merge fixes
This commit is contained in:
@@ -87,7 +87,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
|
|||||||
var slot = part.GetHashCode().ToString();
|
var slot = part.GetHashCode().ToString();
|
||||||
|
|
||||||
body.Template.Slots.Add(slot, BodyPartType.Hand);
|
body.Template.Slots.Add(slot, BodyPartType.Hand);
|
||||||
body.InstallBodyPart(part, slot);
|
body.TryAddPart(slot, part, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace Content.Server.Body
|
|||||||
var slot = part.GetHashCode().ToString();
|
var slot = part.GetHashCode().ToString();
|
||||||
|
|
||||||
body.Template.Slots.Add(slot, BodyPartType.Hand);
|
body.Template.Slots.Add(slot, BodyPartType.Hand);
|
||||||
body.InstallBodyPart(part, slot);
|
body.TryAddPart(slot, part, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,11 @@ using Content.Shared.Damage.DamageContainer;
|
|||||||
using Content.Shared.Damage.ResistanceSet;
|
using Content.Shared.Damage.ResistanceSet;
|
||||||
using Content.Shared.GameObjects.Components.Body;
|
using Content.Shared.GameObjects.Components.Body;
|
||||||
using Content.Shared.GameObjects.Components.Damage;
|
using Content.Shared.GameObjects.Components.Damage;
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Reflection;
|
using Robust.Shared.Interfaces.Reflection;
|
||||||
using Robust.Shared.Interfaces.Serialization;
|
using Robust.Shared.Interfaces.Serialization;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
@@ -34,19 +32,10 @@ namespace Content.Server.Body
|
|||||||
/// which coordinates functions between BodyParts, or a
|
/// which coordinates functions between BodyParts, or a
|
||||||
/// <see cref="DroppedBodyPartComponent"/>.
|
/// <see cref="DroppedBodyPartComponent"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BodyPart
|
public class BodyPart : IBodyPart
|
||||||
{
|
{
|
||||||
/// <summary>
|
private IBodyManagerComponent? _body;
|
||||||
/// The body that this body part is in, if any.
|
|
||||||
/// </summary>
|
|
||||||
private BodyManagerComponent? _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>();
|
private readonly HashSet<Mechanism> _mechanisms = new HashSet<Mechanism>();
|
||||||
|
|
||||||
public BodyPart(BodyPartPrototype data)
|
public BodyPart(BodyPartPrototype data)
|
||||||
@@ -64,11 +53,8 @@ namespace Content.Server.Body
|
|||||||
LoadFromPrototype(data);
|
LoadFromPrototype(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The body that this body part is in, if any.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public BodyManagerComponent? Body
|
public IBodyManagerComponent? Body
|
||||||
{
|
{
|
||||||
get => _body;
|
get => _body;
|
||||||
set
|
set
|
||||||
@@ -111,91 +97,48 @@ namespace Content.Server.Body
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private HashSet<IExposeData> Properties { get; }
|
private HashSet<IExposeData> Properties { get; }
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public string Name { get; private set; }
|
||||||
/// 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; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public string Plural { get; private set; }
|
||||||
/// Plural version of this <see cref="BodyPart"/> name.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public string Plural { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public string RSIPath { get; private set; }
|
||||||
/// Path to the RSI that represents this <see cref="BodyPart"/>.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public string RSIPath { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public string RSIState { get; private set; }
|
||||||
/// RSI state that represents this <see cref="BodyPart"/>.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public string RSIState { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public Enum? RSIMap { get; set; }
|
||||||
/// RSI map keys that this body part changes on the sprite.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public Enum? RSIMap { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// RSI color of this body part.
|
|
||||||
/// </summary>
|
|
||||||
// TODO: SpriteComponent rework
|
// TODO: SpriteComponent rework
|
||||||
public Color? RSIColor { get; set; }
|
[ViewVariables] public Color? RSIColor { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public BodyPartType PartType { get; private set; }
|
||||||
/// <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; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public int Size { get; private set; }
|
||||||
/// 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; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public int MaxDurability { get; private set; }
|
||||||
/// Max HP of this <see cref="BodyPart"/>.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public int MaxDurability { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables] public int CurrentDurability => MaxDurability - Damage.TotalDamage;
|
||||||
/// Current HP of this <see cref="BodyPart"/> based on sum of all damage types.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public int CurrentDurability => MaxDurability - Damage.TotalDamage;
|
|
||||||
|
|
||||||
// TODO: Individual body part damage
|
// TODO: Individual body part damage
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current damage dealt to this <see cref="BodyPart"/>.
|
/// Current damage dealt to this <see cref="IBodyPart"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public DamageContainer Damage { get; private set; }
|
public DamageContainer Damage { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Armor of this <see cref="BodyPart"/> against damages.
|
/// Armor of this <see cref="IBodyPart"/> against damages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public ResistanceSet Resistances { get; private set; }
|
public ResistanceSet Resistances { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// At what HP this <see cref="BodyPart"/> destroyed.
|
/// At what HP this <see cref="IBodyPart"/> destroyed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public int DestroyThreshold { get; private set; }
|
public int DestroyThreshold { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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
|
/// For the most part, most limbs aren't universal and require extra work to
|
||||||
/// attach between types.
|
/// attach between types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -204,14 +147,15 @@ namespace Content.Server.Body
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set of all <see cref="Mechanism"/> currently inside this
|
/// Set of all <see cref="Mechanism"/> currently inside this
|
||||||
/// <see cref="BodyPart"/>.
|
/// <see cref="IBodyPart"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public IReadOnlyCollection<Mechanism> Mechanisms => _mechanisms;
|
public IReadOnlyCollection<Mechanism> Mechanisms => _mechanisms;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called by <see cref="BodyManagerComponent.Update"/>
|
/// This method is called by
|
||||||
/// before <see cref="MetabolismComponent.Update"/> is called.
|
/// <see cref="IBodyManagerComponent.PreMetabolism"/> before
|
||||||
|
/// <see cref="MetabolismComponent.Update"/> is called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PreMetabolism(float frameTime)
|
public void PreMetabolism(float frameTime)
|
||||||
{
|
{
|
||||||
@@ -222,8 +166,9 @@ namespace Content.Server.Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called by <see cref="BodyManagerComponent.Update"/>
|
/// This method is called by
|
||||||
/// after <see cref="MetabolismComponent.Update"/> is called.
|
/// <see cref="IBodyManagerComponent.PostMetabolism"/> after
|
||||||
|
/// <see cref="MetabolismComponent.Update"/> is called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PostMetabolism(float frameTime)
|
public void PostMetabolism(float frameTime)
|
||||||
{
|
{
|
||||||
@@ -258,9 +203,10 @@ namespace Content.Server.Body
|
|||||||
/// <param name="property">The property if found, null otherwise.</param>
|
/// <param name="property">The property if found, null otherwise.</param>
|
||||||
/// <typeparam name="T">The type of the property to find.</typeparam>
|
/// <typeparam name="T">The type of the property to find.</typeparam>
|
||||||
/// <returns>True if successful, false otherwise.</returns>
|
/// <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;
|
return property != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,20 +215,21 @@ namespace Content.Server.Body
|
|||||||
/// The resulting <see cref="BodyPartProperty"/> will be null if unsuccessful.
|
/// The resulting <see cref="BodyPartProperty"/> will be null if unsuccessful.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>True if successful, false otherwise.</returns>
|
/// <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;
|
return property != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <typeparam name="T">
|
/// <typeparam name="T">
|
||||||
/// The subtype of <see cref="BodyPartProperty"/> to look for.
|
/// The subtype of <see cref="BodyPartProperty"/> to look for.
|
||||||
/// </typeparam>
|
/// </typeparam>
|
||||||
/// <returns>
|
/// <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.
|
/// <see cref="T"/>, false otherwise.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool HasProperty<T>() where T : BodyPartProperty
|
public bool HasProperty<T>() where T : BodyPartProperty
|
||||||
@@ -292,13 +239,13 @@ namespace Content.Server.Body
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if a subtype of <see cref="BodyPartProperty"/> is on this
|
/// Checks if a subtype of <see cref="BodyPartProperty"/> is on this
|
||||||
/// <see cref="BodyPart"/>.
|
/// <see cref="IBodyPart"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="propertyType">
|
/// <param name="propertyType">
|
||||||
/// The subtype of <see cref="BodyPartProperty"/> to look for.
|
/// The subtype of <see cref="BodyPartProperty"/> to look for.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <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.
|
/// <see cref="propertyType"/>, false otherwise.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool HasProperty(Type propertyType)
|
public bool HasProperty(Type propertyType)
|
||||||
@@ -306,21 +253,11 @@ namespace Content.Server.Body
|
|||||||
return Properties.Count(x => x.GetType() == propertyType) > 0;
|
return Properties.Count(x => x.GetType() == propertyType) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public bool CanAttachPart(IBodyPart part)
|
||||||
/// 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)
|
|
||||||
{
|
{
|
||||||
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)
|
public bool CanInstallMechanism(Mechanism mechanism)
|
||||||
{
|
{
|
||||||
return SizeUsed + mechanism.Size <= Size &&
|
return SizeUsed + mechanism.Size <= Size &&
|
||||||
@@ -336,7 +273,7 @@ namespace Content.Server.Body
|
|||||||
/// <param name="mechanism">The mechanism to try to install.</param>
|
/// <param name="mechanism">The mechanism to try to install.</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// True if successful, false if there was an error
|
/// 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>
|
/// </returns>
|
||||||
private bool TryInstallMechanism(Mechanism mechanism)
|
private bool TryInstallMechanism(Mechanism mechanism)
|
||||||
{
|
{
|
||||||
@@ -352,7 +289,7 @@ namespace Content.Server.Body
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to install a <see cref="DroppedMechanismComponent"/> into this
|
/// 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"/>.
|
/// <see cref="IEntity"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="droppedMechanism">The mechanism to install.</param>
|
/// <param name="droppedMechanism">The mechanism to install.</param>
|
||||||
@@ -364,21 +301,13 @@ namespace Content.Server.Body
|
|||||||
{
|
{
|
||||||
if (!TryInstallMechanism(droppedMechanism.ContainedMechanism))
|
if (!TryInstallMechanism(droppedMechanism.ContainedMechanism))
|
||||||
{
|
{
|
||||||
return false; //Installing the mechanism failed for some reason.
|
return false; // Installing the mechanism failed for some reason.
|
||||||
}
|
}
|
||||||
|
|
||||||
droppedMechanism.Owner.Delete();
|
droppedMechanism.Owner.Delete();
|
||||||
return true;
|
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,
|
public bool TryDropMechanism(IEntity dropLocation, Mechanism mechanismTarget,
|
||||||
[NotNullWhen(true)] out DroppedMechanismComponent dropped)
|
[NotNullWhen(true)] out DroppedMechanismComponent dropped)
|
||||||
{
|
{
|
||||||
@@ -403,11 +332,11 @@ namespace Content.Server.Body
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to destroy the given <see cref="Mechanism"/> in this
|
/// 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>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to destroy the given <see cref="Mechanism"/> in this
|
/// Tries to destroy the given <see cref="Mechanism"/> in this
|
||||||
/// <see cref="BodyPart"/>.
|
/// <see cref="IBodyPart"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mechanismTarget">The mechanism to destroy.</param>
|
/// <param name="mechanismTarget">The mechanism to destroy.</param>
|
||||||
/// <returns>True if successful, false otherwise.</returns>
|
/// <returns>True if successful, false otherwise.</returns>
|
||||||
@@ -421,18 +350,13 @@ namespace Content.Server.Body
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public bool SurgeryCheck(SurgeryType surgery)
|
||||||
/// 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)
|
|
||||||
{
|
{
|
||||||
return SurgeryData.CheckSurgery(toolType);
|
return SurgeryData.CheckSurgery(surgery);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// tool.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>True if successful, false if there was an error.</returns>
|
/// <returns>True if successful, false if there was an error.</returns>
|
||||||
@@ -474,7 +398,7 @@ namespace Content.Server.Body
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to remove the given <see cref="mechanism"/> from this
|
/// Tries to remove the given <see cref="mechanism"/> from this
|
||||||
/// <see cref="BodyPart"/>.
|
/// <see cref="IBodyPart"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mechanism">The mechanism to remove.</param>
|
/// <param name="mechanism">The mechanism to remove.</param>
|
||||||
/// <returns>True if it was removed, false otherwise.</returns>
|
/// <returns>True if it was removed, false otherwise.</returns>
|
||||||
@@ -515,7 +439,7 @@ namespace Content.Server.Body
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the given <see cref="BodyPartPrototype"/>.
|
/// 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>
|
/// </summary>
|
||||||
protected virtual void LoadFromPrototype(BodyPartPrototype data)
|
protected virtual void LoadFromPrototype(BodyPartPrototype data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Content.Server.Body
|
|||||||
[ViewVariables] public string Name { get; private set; }
|
[ViewVariables] public string Name { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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".
|
/// fill it. E.g. "right arm" : "BodyPart.arm.basic_human".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
|
|||||||
131
Content.Server/Body/IBodyPart.cs
Normal file
131
Content.Server/Body/IBodyPart.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,11 +7,11 @@ namespace Content.Server.Body
|
|||||||
/// Making a class inherit from this interface allows you to do many things with
|
/// Making a class inherit from this interface allows you to do many things with
|
||||||
/// it in the <see cref="SurgeryData"/> class.
|
/// it in the <see cref="SurgeryData"/> class.
|
||||||
/// This includes passing it as an argument to a
|
/// This includes passing it as an argument to a
|
||||||
/// <see cref="SurgeryData.SurgeryAction"/> delegate, as to later typecast it back
|
/// <see cref="SurgeryData.SurgeryAction"/> delegate, as to later typecast
|
||||||
/// to the original class type.
|
/// it back to the original class type.
|
||||||
/// Every BodyPart also needs an <see cref="IBodyPartContainer"/> to be its parent
|
/// Every BodyPart also needs an <see cref="IBodyPartContainer"/> to be
|
||||||
/// (i.e. the <see cref="BodyManagerComponent"/> holds many <see cref="BodyPart"/>,
|
/// its parent (i.e. the <see cref="BodyManagerComponent"/> holds many
|
||||||
/// each of which have an upward reference to it).
|
/// <see cref="IBodyPart"/>, each of which have an upward reference to it).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IBodyPartContainer
|
public interface IBodyPartContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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"/>.
|
/// <see cref="BodyManagerComponent"/>.
|
||||||
/// For instance, attaching a head to a body will call this on the brain inside.
|
/// For instance, attaching a head to a body will call this on the brain inside.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -82,7 +82,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
|
/// 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.
|
/// For instance, putting a brain into an empty head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void InstalledIntoPart()
|
public void InstalledIntoPart()
|
||||||
@@ -92,22 +92,22 @@ namespace Content.Server.Body.Mechanisms.Behaviors
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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"/>.
|
/// <see cref="BodyManagerComponent"/>.
|
||||||
/// For instance, cutting off ones head will call this on the brain inside.
|
/// For instance, cutting off ones head will call this on the brain inside.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemovedFromBody(BodyManagerComponent old)
|
public void RemovedFromBody(IBodyManagerComponent old)
|
||||||
{
|
{
|
||||||
OnRemovedFromBody(old);
|
OnRemovedFromBody(old);
|
||||||
TryRemoveNetwork(old);
|
TryRemoveNetwork(old);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is removed from a
|
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
|
||||||
/// <see cref="BodyPart"/>.
|
/// removed from a <see cref="IBodyPart"/>.
|
||||||
/// For instance, taking a brain out of ones head.
|
/// For instance, taking a brain out of ones head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemovedFromPart(BodyPart old)
|
public void RemovedFromPart(IBodyPart old)
|
||||||
{
|
{
|
||||||
OnRemovedFromPart(old);
|
OnRemovedFromPart(old);
|
||||||
TryRemoveNetwork(old.Body);
|
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)
|
if (Network != null)
|
||||||
{
|
{
|
||||||
@@ -137,7 +137,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors
|
|||||||
protected virtual void OnRemove() { }
|
protected virtual void OnRemove() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <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"/>.
|
/// <see cref="BodyManagerComponent"/>.
|
||||||
/// For instance, attaching a head to a body will call this on the brain inside.
|
/// For instance, attaching a head to a body will call this on the brain inside.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -145,24 +145,24 @@ namespace Content.Server.Body.Mechanisms.Behaviors
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
|
/// 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.
|
/// For instance, putting a brain into an empty head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnInstalledIntoPart() { }
|
protected virtual void OnInstalledIntoPart() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <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"/>.
|
/// <see cref="BodyManagerComponent"/>.
|
||||||
/// For instance, cutting off ones head will call this on the brain inside.
|
/// For instance, cutting off ones head will call this on the brain inside.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnRemovedFromBody(BodyManagerComponent old) { }
|
protected virtual void OnRemovedFromBody(IBodyManagerComponent old) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is removed from a
|
/// Called when the parent <see cref="Mechanisms.Mechanism"/> is
|
||||||
/// <see cref="BodyPart"/>.
|
/// removed from a <see cref="IBodyPart"/>.
|
||||||
/// For instance, taking a brain out of ones head.
|
/// For instance, taking a brain out of ones head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnRemovedFromPart(BodyPart old) { }
|
protected virtual void OnRemovedFromPart(IBodyPart old) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called every update when this behavior is connected to a
|
/// Called every update when this behavior is connected to a
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.Body.Mechanisms
|
namespace Content.Server.Body.Mechanisms
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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,
|
/// This includes livers, eyes, cameras, brains, explosive implants,
|
||||||
/// binary communicators, and other things.
|
/// binary communicators, and other things.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Mechanism
|
public class Mechanism
|
||||||
{
|
{
|
||||||
private BodyPart? _part;
|
private IBodyPart? _part;
|
||||||
|
|
||||||
public Mechanism(MechanismPrototype data)
|
public Mechanism(MechanismPrototype data)
|
||||||
{
|
{
|
||||||
@@ -91,13 +91,13 @@ namespace Content.Server.Body.Mechanisms
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines a handful of things - mostly whether this
|
/// 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>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public int Size { get; set; }
|
public int Size { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// easily installed into.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
@@ -109,9 +109,9 @@ namespace Content.Server.Body.Mechanisms
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private List<MechanismBehavior> Behaviors { get; }
|
private List<MechanismBehavior> Behaviors { get; }
|
||||||
|
|
||||||
public BodyManagerComponent? Body => Part?.Body;
|
public IBodyManagerComponent? Body => Part?.Body;
|
||||||
|
|
||||||
public BodyPart? Part
|
public IBodyPart? Part
|
||||||
{
|
{
|
||||||
get => _part;
|
get => _part;
|
||||||
set
|
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)
|
foreach (var behavior in Behaviors)
|
||||||
{
|
{
|
||||||
@@ -211,7 +211,7 @@ namespace Content.Server.Body.Mechanisms
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// <see cref="MetabolismComponent.Update"/> is called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PreMetabolism(float frameTime)
|
public void PreMetabolism(float frameTime)
|
||||||
@@ -223,7 +223,7 @@ namespace Content.Server.Body.Mechanisms
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// <see cref="MetabolismComponent.Update"/> is called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PostMetabolism(float frameTime)
|
public void PostMetabolism(float frameTime)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Content.Server.Body.Surgery
|
|||||||
private bool _skinRetracted;
|
private bool _skinRetracted;
|
||||||
private bool _vesselsClamped;
|
private bool _vesselsClamped;
|
||||||
|
|
||||||
public BiologicalSurgeryData(BodyPart parent) : base(parent) { }
|
public BiologicalSurgeryData(IBodyPart parent) : base(parent) { }
|
||||||
|
|
||||||
protected override SurgeryAction? GetSurgeryStep(SurgeryType toolType)
|
protected override SurgeryAction? GetSurgeryStep(SurgeryType toolType)
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ namespace Content.Server.Body.Surgery
|
|||||||
return _skinOpened && _vesselsClamped && _skinRetracted;
|
return _skinOpened && _vesselsClamped && _skinRetracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanAttachBodyPart(BodyPart part)
|
public override bool CanAttachBodyPart(IBodyPart part)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
// TODO: if a bodypart is disconnected, you should have to do some surgery to allow another bodypart to be attached.
|
// 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,
|
private void RemoveOrganSurgeryCallback(Mechanism target, IBodyPartContainer container, ISurgeon surgeon,
|
||||||
ISurgeon surgeon,
|
|
||||||
IEntity performer)
|
IEntity performer)
|
||||||
{
|
{
|
||||||
if (target == null || !Parent.Mechanisms.Contains(target))
|
if (target == null || !Parent.Mechanisms.Contains(target))
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
|||||||
namespace Content.Server.Body.Surgery
|
namespace Content.Server.Body.Surgery
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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.
|
/// whether there's an incision on it, whether the bone is broken, etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class SurgeryData
|
public abstract class SurgeryData
|
||||||
@@ -14,40 +14,40 @@ namespace Content.Server.Body.Surgery
|
|||||||
protected delegate void SurgeryAction(IBodyPartContainer container, ISurgeon surgeon, IEntity performer);
|
protected delegate void SurgeryAction(IBodyPartContainer container, ISurgeon surgeon, IEntity performer);
|
||||||
|
|
||||||
/// <summary>
|
/// <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
|
/// 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.
|
/// is null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly BodyPart Parent;
|
protected readonly IBodyPart Parent;
|
||||||
|
|
||||||
protected SurgeryData(BodyPart parent)
|
protected SurgeryData(IBodyPart parent)
|
||||||
{
|
{
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="BodyPartType"/> of the parent <see cref="BodyPart"/>.
|
/// The <see cref="BodyPartType"/> of the parent <see cref="IBodyPart"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected BodyPartType ParentType => Parent.PartType;
|
protected BodyPartType ParentType => Parent.PartType;
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// upon observing the given entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract string GetDescription(IEntity target);
|
public abstract string GetDescription(IEntity target);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether a <see cref="Mechanism"/> can be installed into the
|
/// 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>
|
/// </summary>
|
||||||
public abstract bool CanInstallMechanism(Mechanism mechanism);
|
public abstract bool CanInstallMechanism(Mechanism mechanism);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether the given <see cref="BodyPart"/> can be connected to the
|
/// Returns whether the given <see cref="IBodyPart"/> can be connected to the
|
||||||
/// <see cref="BodyPart"/> this <see cref="SurgeryData"/> represents.
|
/// <see cref="IBodyPart"/> this <see cref="SurgeryData"/> represents.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract bool CanAttachBodyPart(BodyPart part);
|
public abstract bool CanAttachBodyPart(IBodyPart part);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the delegate corresponding to the surgery step using the given
|
/// Gets the delegate corresponding to the surgery step using the given
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using Content.Server.Body.Network;
|
|||||||
using Content.Server.GameObjects.Components.Metabolism;
|
using Content.Server.GameObjects.Components.Metabolism;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||||
using Content.Server.Mobs;
|
|
||||||
using Content.Server.Observer;
|
using Content.Server.Observer;
|
||||||
using Content.Shared.Body.Part;
|
using Content.Shared.Body.Part;
|
||||||
using Content.Shared.Body.Part.Properties.Movement;
|
using Content.Shared.Body.Part.Properties.Movement;
|
||||||
@@ -34,13 +33,14 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Body
|
namespace Content.Server.GameObjects.Components.Body
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Component representing a collection of <see cref="BodyPart"></see>
|
/// Component representing a collection of <see cref="IBodyPart"></see>
|
||||||
/// attached to each other.
|
/// attached to each other.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(IDamageableComponent))]
|
[ComponentReference(typeof(IDamageableComponent))]
|
||||||
[ComponentReference(typeof(ISharedBodyManagerComponent))]
|
[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 IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IBodyNetworkFactory _bodyNetworkFactory = default!;
|
[Dependency] private readonly IBodyNetworkFactory _bodyNetworkFactory = default!;
|
||||||
@@ -48,38 +48,28 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
|
|
||||||
[ViewVariables] private string _presetName = default!;
|
[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>();
|
[ViewVariables] private readonly Dictionary<Type, BodyNetwork> _networks = new Dictionary<Type, BodyNetwork>();
|
||||||
|
|
||||||
/// <summary>
|
/// <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
|
/// that are currently affecting move speed, mapped to how big that leg
|
||||||
/// they're on is.
|
/// they're on is.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[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>
|
/// <summary>
|
||||||
/// The <see cref="BodyTemplate"/> that this <see cref="BodyManagerComponent"/>
|
/// Maps <see cref="BodyTemplate"/> slot name to the <see cref="IBodyPart"/>
|
||||||
/// 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"/>
|
|
||||||
/// object filling it (if there is one).
|
/// object filling it (if there is one).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public IReadOnlyDictionary<string, BodyPart> Parts => _parts;
|
public IReadOnlyDictionary<string, IBodyPart> Parts => _parts;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of all slots in this body, taken from the keys of
|
/// 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
|
// Add a new BodyPart with the BodyPartPrototype as a baseline to our
|
||||||
// BodyComponent.
|
// BodyComponent.
|
||||||
var addedPart = new BodyPart(newPartData);
|
var addedPart = new BodyPart(newPartData);
|
||||||
AddBodyPart(addedPart, slotName);
|
TryAddPart(slotName, addedPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnBodyChanged(); // TODO: Duplicate code
|
OnBodyChanged(); // TODO: Duplicate code
|
||||||
@@ -180,8 +170,8 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Changes the current <see cref="BodyTemplate"/> to the given
|
/// Changes the current <see cref="BodyTemplate"/> to the given
|
||||||
/// <see cref="BodyTemplate"/>.
|
/// <see cref="BodyTemplate"/>.
|
||||||
/// Attempts to keep previous <see cref="BodyPart"/> if there is a slot for
|
/// Attempts to keep previous <see cref="IBodyPart"/> if there is a
|
||||||
/// them in both <see cref="BodyTemplate"/>.
|
/// slot for them in both <see cref="BodyTemplate"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ChangeBodyTemplate(BodyTemplatePrototype newTemplate)
|
public void ChangeBodyTemplate(BodyTemplatePrototype newTemplate)
|
||||||
{
|
{
|
||||||
@@ -280,10 +270,10 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
|
|
||||||
foreach (var (key, value) in _activeLegs)
|
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))
|
// 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>
|
/// <summary>
|
||||||
/// Recursively searches for if <see cref="target"/> is connected to
|
/// 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
|
/// 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>
|
/// </summary>
|
||||||
/// <param name="target">The body part to find the center for.</param>
|
/// <param name="target">The body part to find the center for.</param>
|
||||||
/// <returns>True if it is connected to the center, false otherwise.</returns>
|
/// <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>();
|
var searchedSlots = new List<string>();
|
||||||
|
|
||||||
@@ -335,9 +325,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
|
|
||||||
private bool ConnectedToCenterPartRecursion(ICollection<string> searchedSlots, string slotName)
|
private bool ConnectedToCenterPartRecursion(ICollection<string> searchedSlots, string slotName)
|
||||||
{
|
{
|
||||||
TryGetBodyPart(slotName, out var part);
|
if (!TryGetBodyPart(slotName, out var part))
|
||||||
|
|
||||||
if (part == null)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -367,14 +355,14 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// the <see cref="BodyTemplate"/>. For humans, this is the torso.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The <see cref="BodyPart"/> if one exists, null otherwise.</returns>
|
/// <returns>The <see cref="BodyPart"/> if one exists, null otherwise.</returns>
|
||||||
private BodyPart? GetCenterBodyPart()
|
private IBodyPart? GetCenterBodyPart()
|
||||||
{
|
{
|
||||||
Parts.TryGetValue(Template.CenterSlot, out var center);
|
Parts.TryGetValue(Template.CenterSlot, out var center);
|
||||||
return center!;
|
return center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -387,29 +375,31 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// one exists.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slotName">The slot to search in.</param>
|
/// <param name="slotName">The slot to search in.</param>
|
||||||
/// <param name="result">The body part in that slot, if any.</param>
|
/// <param name="result">The body part in that slot, if any.</param>
|
||||||
/// <returns>True if found, false otherwise.</returns>
|
/// <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!);
|
return Parts.TryGetValue(slotName, out result!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the slotName that the given <see cref="BodyPart"/> resides in.
|
/// Finds the slotName that the given <see cref="IBodyPart"/> resides in.
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="result">The slot found, if any.</param>
|
||||||
/// <returns>True if a slot was found, false otherwise</returns>
|
/// <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,
|
// 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.
|
// so we can iterate through the dictionary values to get the key from there.
|
||||||
result = Parts.FirstOrDefault(x => x.Value == part).Key;
|
var pair = Parts.FirstOrDefault(x => x.Value == part);
|
||||||
return result != null;
|
result = pair.Key;
|
||||||
|
|
||||||
|
return !pair.Equals(default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -448,7 +438,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
/// True if successful, false if there was an error or no connected
|
/// True if successful, false if there was an error or no connected
|
||||||
/// <see cref="BodyPart"/>s were found.
|
/// <see cref="BodyPart"/>s were found.
|
||||||
/// </returns>
|
/// </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!;
|
result = null!;
|
||||||
|
|
||||||
@@ -457,7 +447,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var toReturn = new List<BodyPart>();
|
var toReturn = new List<IBodyPart>();
|
||||||
foreach (var connection in connections)
|
foreach (var connection in connections)
|
||||||
{
|
{
|
||||||
if (TryGetBodyPart(connection, out var bodyPartResult))
|
if (TryGetBodyPart(connection, out var bodyPartResult))
|
||||||
@@ -481,9 +471,9 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// True if successful, false if there was an error or no connected
|
/// 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>
|
/// </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!;
|
result = null!;
|
||||||
|
|
||||||
@@ -492,11 +482,11 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </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)
|
foreach (var part in Parts.Values)
|
||||||
{
|
{
|
||||||
@@ -509,32 +499,6 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
return toReturn;
|
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>
|
/// <summary>
|
||||||
/// Installs the given <see cref="DroppedBodyPartComponent"/> into the
|
/// Installs the given <see cref="DroppedBodyPartComponent"/> into the
|
||||||
/// given slot, deleting the <see cref="IEntity"/> afterwards.
|
/// given slot, deleting the <see cref="IEntity"/> afterwards.
|
||||||
@@ -544,7 +508,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
{
|
{
|
||||||
DebugTools.AssertNotNull(part);
|
DebugTools.AssertNotNull(part);
|
||||||
|
|
||||||
if (!InstallBodyPart(part.ContainedBodyPart, slotName))
|
if (!TryAddPart(slotName, part.ContainedBodyPart))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -554,15 +518,15 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnects the given <see cref="BodyPart"/> reference, potentially
|
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
|
||||||
/// dropping other <see cref="BodyPart">BodyParts</see> if they were hanging
|
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
|
||||||
/// off of it.
|
/// off of it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="IEntity"/> representing the dropped
|
/// 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>
|
/// </returns>
|
||||||
public IEntity? DropPart(BodyPart part)
|
public IEntity? DropPart(IBodyPart part)
|
||||||
{
|
{
|
||||||
DebugTools.AssertNotNull(part);
|
DebugTools.AssertNotNull(part);
|
||||||
|
|
||||||
@@ -596,11 +560,11 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnects the given <see cref="BodyPart"/> reference, potentially
|
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
|
||||||
/// dropping other <see cref="BodyPart">BodyParts</see> if they were hanging
|
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
|
||||||
/// off of it.
|
/// off of it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DisconnectBodyPart(BodyPart part, bool dropEntity)
|
public void DisconnectBodyPart(IBodyPart part, bool dropEntity)
|
||||||
{
|
{
|
||||||
DebugTools.AssertNotNull(part);
|
DebugTools.AssertNotNull(part);
|
||||||
|
|
||||||
@@ -640,12 +604,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
{
|
{
|
||||||
DebugTools.AssertNotNull(slotName);
|
DebugTools.AssertNotNull(slotName);
|
||||||
|
|
||||||
if (!TryGetBodyPart(slotName, out var part))
|
if (!HasPart(slotName))
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part == null)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -666,27 +625,47 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
OnBodyChanged();
|
OnBodyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddBodyPart(BodyPart part, string slotName)
|
public bool TryAddPart(string slot, IBodyPart part, bool force = false)
|
||||||
{
|
{
|
||||||
DebugTools.AssertNotNull(part);
|
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;
|
part.Body = this;
|
||||||
|
|
||||||
var argsAdded = new BodyPartAddedEventArgs(part, slotName);
|
var argsAdded = new BodyPartAddedEventArgs(part, slot);
|
||||||
|
|
||||||
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray())
|
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray())
|
||||||
{
|
{
|
||||||
component.BodyPartAdded(argsAdded);
|
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))
|
!_reflectionManager.TryParseEnumReference(partMap, out var partEnum))
|
||||||
{
|
{
|
||||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {partMap} for body part {part.Name}.");
|
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {partMap} for body part {part.Name}.");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
part.RSIMap = partEnum;
|
part.RSIMap = partEnum;
|
||||||
@@ -712,6 +691,13 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
|
|
||||||
SendNetworkMessage(mechanismMessage);
|
SendNetworkMessage(mechanismMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasPart(string slot)
|
||||||
|
{
|
||||||
|
return _parts.ContainsKey(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -720,7 +706,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slotName">The slot to remove it from.</param>
|
/// <param name="slotName">The slot to remove it from.</param>
|
||||||
/// <param name="drop">
|
/// <param name="drop">
|
||||||
/// Whether or not to drop the removed <see cref="BodyPart"/>.
|
/// Whether or not to drop the removed <see cref="IBodyPart"/>.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private bool RemoveBodyPart(string slotName, bool drop)
|
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="part">The part to remove from this body.</param>
|
||||||
/// <param name="slotName">The slot that the part was in, if any.</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>
|
/// <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);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slotName = pair.Key;
|
||||||
|
|
||||||
return RemoveBodyPart(slotName, false);
|
return RemoveBodyPart(slotName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,13 +793,13 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
|
|
||||||
if (_networks.ContainsKey(network.GetType()))
|
if (_networks.ContainsKey(network.GetType()))
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_networks.Add(network.GetType(), network);
|
_networks.Add(network.GetType(), network);
|
||||||
network.OnAdd(Owner);
|
network.OnAdd(Owner);
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -844,62 +833,21 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
return EnsureNetwork(typeof(T));
|
return EnsureNetwork(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void RemoveNetwork(Type networkType)
|
||||||
/// 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)
|
|
||||||
{
|
{
|
||||||
DebugTools.AssertNotNull(networkName);
|
DebugTools.AssertNotNull(networkType);
|
||||||
|
|
||||||
var network = _bodyNetworkFactory.GetNetwork(networkName);
|
if (_networks.Remove(networkType, out var network))
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
network.OnRemove();
|
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
|
public void RemoveNetwork<T>() where T : BodyNetwork
|
||||||
{
|
{
|
||||||
RemoveNetwork(typeof(T));
|
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>
|
/// <summary>
|
||||||
/// Attempts to get the <see cref="BodyNetwork"/> of the given type in this body.
|
/// Attempts to get the <see cref="BodyNetwork"/> of the given type in this body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -924,7 +872,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
/// a foot node from the given node. It can
|
/// a foot node from the given node. It can
|
||||||
/// only search through BodyParts with <see cref="ExtensionProperty"/>.
|
/// only search through BodyParts with <see cref="ExtensionProperty"/>.
|
||||||
/// </summary>
|
/// </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))
|
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>());
|
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)
|
ICollection<BodyPart> searchedParts)
|
||||||
{
|
{
|
||||||
if (!current.TryGetProperty<ExtensionProperty>(out var extProperty))
|
if (!current.TryGetProperty<ExtensionProperty>(out var extProperty))
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy BodyTemplate and BodyPart data into a common data class that the client can read.
|
/// Copy BodyTemplate and BodyPart data into a common data class that the client can read.
|
||||||
/// </summary>
|
/// </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>();
|
var partsData = new Dictionary<string, BodyScannerBodyPartData>();
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Body
|
|||||||
|
|
||||||
foreach (var connectedPart in parts)
|
foreach (var connectedPart in parts)
|
||||||
{
|
{
|
||||||
if (!connectedPart.CanAttachBodyPart(ContainedBodyPart))
|
if (!connectedPart.CanAttachPart(ContainedBodyPart))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Body;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.GameObjects.Components.Body;
|
using Content.Shared.GameObjects.Components.Body;
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
|
|||||||
|
|
||||||
public class BodyPartAddedEventArgs : EventArgs
|
public class BodyPartAddedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public BodyPartAddedEventArgs(BodyPart part, string slotName)
|
public BodyPartAddedEventArgs(IBodyPart part, string slotName)
|
||||||
{
|
{
|
||||||
Part = part;
|
Part = part;
|
||||||
SlotName = slotName;
|
SlotName = slotName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BodyPart Part { get; }
|
public IBodyPart Part { get; }
|
||||||
|
|
||||||
public string SlotName { get; }
|
public string SlotName { get; }
|
||||||
}
|
}
|
||||||
@@ -36,13 +36,13 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
|
|||||||
|
|
||||||
public class BodyPartRemovedEventArgs : EventArgs
|
public class BodyPartRemovedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public BodyPartRemovedEventArgs(BodyPart part, string slotName)
|
public BodyPartRemovedEventArgs(IBodyPart part, string slotName)
|
||||||
{
|
{
|
||||||
Part = part;
|
Part = part;
|
||||||
SlotName = slotName;
|
SlotName = slotName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BodyPart Part { get; }
|
public IBodyPart Part { get; }
|
||||||
|
|
||||||
public string SlotName { get; }
|
public string SlotName { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user