Kill bobby 2.0 (#6023)

This commit is contained in:
mirrorcult
2022-01-04 02:17:39 -07:00
committed by GitHub
parent 0a626353ab
commit 5249ea057a
44 changed files with 69 additions and 1848 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Content.Shared.Body.Events;
using Content.Shared.Body.Events;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -8,16 +7,13 @@ using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Body.Components
{
public abstract class SharedMechanismComponent : Component, ISerializationHooks
[RegisterComponent]
public class MechanismComponent : Component, ISerializationHooks
{
[Dependency] private readonly IEntityManager _entMan = default!;
public override string Name => "Mechanism";
protected readonly Dictionary<int, object> OptionsCache = new();
protected SharedBodyComponent? BodyCache;
protected int IdHash;
protected EntityUid? PerformerCache;
private SharedBodyPartComponent? _part;
public SharedBodyComponent? Body => Part?.Body;
@@ -74,13 +70,13 @@ namespace Content.Shared.Body.Components
// TODO BODY OnSizeChanged
/// <summary>
/// Determines whether this
/// <see cref="SharedMechanismComponent"/> can fit into a <see cref="SharedBodyPartComponent"/>.
/// <see cref="MechanismComponent"/> can fit into a <see cref="SharedBodyPartComponent"/>.
/// </summary>
[DataField("size")] public int Size { get; set; } = 1;
/// <summary>
/// What kind of <see cref="SharedBodyPartComponent"/> this
/// <see cref="SharedMechanismComponent"/> can be easily installed into.
/// <see cref="MechanismComponent"/> can be easily installed into.
/// </summary>
[DataField("compatibility")]
public BodyPartCompatibility Compatibility { get; set; } = BodyPartCompatibility.Universal;

View File

@@ -22,7 +22,7 @@ namespace Content.Shared.Body.Components
// TODO BODY Damage methods for collections of IDamageableComponents
[NetworkedComponent()]
public abstract class SharedBodyComponent : Component, IBodyPartContainer, ISerializationHooks
public abstract class SharedBodyComponent : Component, ISerializationHooks
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
@@ -58,9 +58,6 @@ namespace Content.Shared.Body.Components
[ViewVariables]
public IEnumerable<KeyValuePair<SharedBodyPartComponent, BodyPartSlot>> Parts => SlotParts;
[ViewVariables]
public IEnumerable<BodyPartSlot> EmptySlots => Slots.Where(slot => slot.Part == null);
public BodyPartSlot? CenterSlot =>
Template?.CenterSlot is { } centerSlot
? SlotIds.GetValueOrDefault(centerSlot)
@@ -223,14 +220,6 @@ namespace Content.Shared.Body.Components
slot.SetPart(part);
}
public bool HasPart(string slotId)
{
DebugTools.AssertNotNull(slotId);
return SlotIds.TryGetValue(slotId, out var slot) &&
slot.Part != null;
}
public bool HasPart(SharedBodyPartComponent part)
{
DebugTools.AssertNotNull(part);
@@ -246,34 +235,6 @@ namespace Content.Shared.Body.Components
slot.RemovePart();
}
public bool RemovePart(string slotId)
{
DebugTools.AssertNotNull(slotId);
return SlotIds.TryGetValue(slotId, out var slot) &&
slot.RemovePart();
}
public bool RemovePart(SharedBodyPartComponent part, [NotNullWhen(true)] out BodyPartSlot? slotId)
{
DebugTools.AssertNotNull(part);
if (!SlotParts.TryGetValue(part, out var slot))
{
slotId = null;
return false;
}
if (!slot.RemovePart())
{
slotId = null;
return false;
}
slotId = slot;
return true;
}
public bool TryDropPart(BodyPartSlot slot, [NotNullWhen(true)] out Dictionary<BodyPartSlot, SharedBodyPartComponent>? dropped)
{
DebugTools.AssertNotNull(slot);
@@ -333,86 +294,16 @@ namespace Content.Shared.Body.Components
return false;
}
public bool HasSlot(string slot)
{
return SlotIds.ContainsKey(slot);
}
public IEnumerable<SharedBodyPartComponent> GetParts()
{
foreach (var slot in SlotIds.Values)
{
if (slot.Part != null)
{
yield return slot.Part;
}
}
}
public bool TryGetPart(string slotId, [NotNullWhen(true)] out SharedBodyPartComponent? result)
{
result = null;
return SlotIds.TryGetValue(slotId, out var slot) &&
(result = slot.Part) != null;
}
public BodyPartSlot? GetSlot(string id)
{
return SlotIds.GetValueOrDefault(id);
}
public BodyPartSlot? GetSlot(SharedBodyPartComponent part)
{
return SlotParts.GetValueOrDefault(part);
}
public bool TryGetSlot(string slotId, [NotNullWhen(true)] out BodyPartSlot? slot)
{
return (slot = GetSlot(slotId)) != null;
}
public bool TryGetSlot(SharedBodyPartComponent part, [NotNullWhen(true)] out BodyPartSlot? slot)
{
return (slot = GetSlot(part)) != null;
}
public bool TryGetPartConnections(string slotId, [NotNullWhen(true)] out List<SharedBodyPartComponent>? connections)
{
if (!SlotIds.TryGetValue(slotId, out var slot))
{
connections = null;
return false;
}
connections = new List<SharedBodyPartComponent>();
foreach (var connection in slot.Connections)
{
if (connection.Part != null)
{
connections.Add(connection.Part);
}
}
if (connections.Count <= 0)
{
connections = null;
return false;
}
return true;
}
public bool HasSlotOfType(BodyPartType type)
{
foreach (var _ in GetSlotsOfType(type))
{
return true;
}
return false;
}
public IEnumerable<BodyPartSlot> GetSlotsOfType(BodyPartType type)
{
foreach (var slot in SlotIds.Values)

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using Content.Shared.Body.Events;
using Content.Shared.Body.Part;
using Content.Shared.Body.Surgery;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
@@ -16,7 +15,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Shared.Body.Components
{
[NetworkedComponent()]
public abstract class SharedBodyPartComponent : Component, IBodyPartContainer
public abstract class SharedBodyPartComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
@@ -30,7 +29,7 @@ namespace Content.Shared.Body.Components
public IReadOnlyList<string> MechanismIds => _mechanismIds;
[ViewVariables]
private readonly HashSet<SharedMechanismComponent> _mechanisms = new();
private readonly HashSet<MechanismComponent> _mechanisms = new();
[ViewVariables]
public SharedBodyComponent? Body
@@ -58,12 +57,6 @@ namespace Content.Shared.Body.Components
}
}
/// <summary>
/// The string to show when displaying this part's name to players.
/// </summary>
[ViewVariables]
public string DisplayName => Name;
/// <summary>
/// <see cref="BodyPartType"/> that this <see cref="IBodyPart"/> is considered
/// to be.
@@ -91,11 +84,11 @@ namespace Content.Shared.Body.Components
/// </summary>
[ViewVariables]
[DataField("compatibility")]
public BodyPartCompatibility Compatibility { get; private set; } = BodyPartCompatibility.Universal;
public BodyPartCompatibility Compatibility = BodyPartCompatibility.Universal;
// TODO BODY Mechanisms occupying different parts at the body level
[ViewVariables]
public IReadOnlyCollection<SharedMechanismComponent> Mechanisms => _mechanisms;
public IReadOnlyCollection<MechanismComponent> Mechanisms => _mechanisms;
// TODO BODY Replace with a simulation of organs
/// <summary>
@@ -104,16 +97,13 @@ namespace Content.Shared.Body.Components
/// </summary>
[ViewVariables]
[DataField("vital")]
public bool IsVital { get; private set; } = false;
public bool IsVital = false;
[ViewVariables]
[DataField("symmetry")]
public BodyPartSymmetry Symmetry { get; private set; } = BodyPartSymmetry.None;
public BodyPartSymmetry Symmetry = BodyPartSymmetry.None;
[ViewVariables]
public ISurgeryData? SurgeryDataComponent => _entMan.GetComponentOrNull<ISurgeryData>(Owner);
protected virtual void OnAddMechanism(SharedMechanismComponent mechanism)
protected virtual void OnAddMechanism(MechanismComponent mechanism)
{
var prototypeId = _entMan.GetComponent<MetaDataComponent>(mechanism.Owner).EntityPrototype!.ID;
@@ -128,7 +118,7 @@ namespace Content.Shared.Body.Components
Dirty();
}
protected virtual void OnRemoveMechanism(SharedMechanismComponent mechanism)
protected virtual void OnRemoveMechanism(MechanismComponent mechanism)
{
_mechanismIds.Remove(_entMan.GetComponent<MetaDataComponent>(mechanism.Owner).EntityPrototype!.ID);
mechanism.Part = null;
@@ -179,39 +169,13 @@ namespace Content.Shared.Body.Components
}
}
public bool SurgeryCheck(SurgeryType surgery)
public virtual bool CanAddMechanism(MechanismComponent mechanism)
{
return SurgeryDataComponent?.CheckSurgery(surgery) ?? false;
}
public bool AttemptSurgery(SurgeryType toolType, IBodyPartContainer target, ISurgeon surgeon, EntityUid performer)
{
DebugTools.AssertNotNull(toolType);
DebugTools.AssertNotNull(target);
DebugTools.AssertNotNull(surgeon);
DebugTools.AssertNotNull(performer);
return SurgeryDataComponent?.PerformSurgery(toolType, target, surgeon, performer) ?? false;
}
public bool CanAttachPart(SharedBodyPartComponent part)
{
DebugTools.AssertNotNull(part);
return SurgeryDataComponent?.CanAttachBodyPart(part) ?? false;
}
public virtual bool CanAddMechanism(SharedMechanismComponent mechanism)
{
DebugTools.AssertNotNull(mechanism);
return SurgeryDataComponent != null &&
SizeUsed + mechanism.Size <= Size &&
SurgeryDataComponent.CanAddMechanism(mechanism);
return SizeUsed + mechanism.Size <= Size;
}
/// <summary>
/// Tries to add a <see cref="SharedMechanismComponent"/> to this part.
/// Tries to add a <see cref="MechanismComponent"/> to this part.
/// </summary>
/// <param name="mechanism">The mechanism to add.</param>
/// <param name="force">
@@ -220,7 +184,7 @@ namespace Content.Shared.Body.Components
/// it was already added before.
/// </param>
/// <returns>true if added, false otherwise even if it was already added.</returns>
public bool TryAddMechanism(SharedMechanismComponent mechanism, bool force = false)
public bool TryAddMechanism(MechanismComponent mechanism, bool force = false)
{
DebugTools.AssertNotNull(mechanism);
@@ -244,7 +208,7 @@ namespace Content.Shared.Body.Components
/// </summary>
/// <param name="mechanism">The mechanism to remove.</param>
/// <returns>True if it was removed, false otherwise.</returns>
public bool RemoveMechanism(SharedMechanismComponent mechanism)
public bool RemoveMechanism(MechanismComponent mechanism)
{
DebugTools.AssertNotNull(mechanism);
@@ -265,7 +229,7 @@ namespace Content.Shared.Body.Components
/// <param name="mechanism">The mechanism to remove.</param>
/// <param name="coordinates">The coordinates to drop it at.</param>
/// <returns>True if it was removed, false otherwise.</returns>
public bool RemoveMechanism(SharedMechanismComponent mechanism, EntityCoordinates coordinates)
public bool RemoveMechanism(MechanismComponent mechanism, EntityCoordinates coordinates)
{
if (RemoveMechanism(mechanism))
{
@@ -277,7 +241,7 @@ namespace Content.Shared.Body.Components
}
/// <summary>
/// Tries to destroy the given <see cref="SharedMechanismComponent"/> from
/// Tries to destroy the given <see cref="MechanismComponent"/> from
/// this part.
/// The mechanism won't be deleted if it is not in this body part.
/// </summary>
@@ -285,7 +249,7 @@ namespace Content.Shared.Body.Components
/// True if the mechanism was in this body part and destroyed,
/// false otherwise.
/// </returns>
public bool DeleteMechanism(SharedMechanismComponent mechanism)
public bool DeleteMechanism(MechanismComponent mechanism)
{
DebugTools.AssertNotNull(mechanism);
@@ -344,7 +308,7 @@ namespace Content.Shared.Body.Components
[Serializable, NetSerializable]
public class BodyPartComponentState : ComponentState
{
[NonSerialized] private List<SharedMechanismComponent>? _mechanisms;
[NonSerialized] private List<MechanismComponent>? _mechanisms;
public readonly EntityUid[] MechanismIds;
@@ -353,7 +317,7 @@ namespace Content.Shared.Body.Components
MechanismIds = mechanismIds;
}
public List<SharedMechanismComponent> Mechanisms(IEntityManager? entityManager = null)
public List<MechanismComponent> Mechanisms(IEntityManager? entityManager = null)
{
if (_mechanisms != null)
{
@@ -362,7 +326,7 @@ namespace Content.Shared.Body.Components
IoCManager.Resolve(ref entityManager);
var mechanisms = new List<SharedMechanismComponent>(MechanismIds.Length);
var mechanisms = new List<MechanismComponent>(MechanismIds.Length);
foreach (var id in MechanismIds)
{
@@ -371,7 +335,7 @@ namespace Content.Shared.Body.Components
continue;
}
if (!entityManager.TryGetComponent(id, out SharedMechanismComponent? mechanism))
if (!entityManager.TryGetComponent(id, out MechanismComponent? mechanism))
{
continue;
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Body.Part

View File

@@ -1,12 +0,0 @@

namespace Content.Shared.Body.Part
{
/// <summary>
/// Defines a component as being capable of containing parts.
/// Used during surgery.
/// </summary>
// TODO BODY Remove
public interface IBodyPartContainer
{
}
}

View File

@@ -1,34 +0,0 @@
using System.Collections.Generic;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Surgery
{
/// <summary>
/// Interface representing an entity capable of performing surgery,
/// such as a circular saw.
/// </summary>
public interface ISurgeon
{
public delegate void MechanismRequestCallback(
SharedMechanismComponent target,
IBodyPartContainer container,
ISurgeon surgeon,
EntityUid performer);
/// <summary>
/// How long it takes to perform a single surgery step in seconds.
/// </summary>
public float BaseOperationTime { get; set; }
/// <summary>
/// When performing a surgery, the <see cref="SurgeryDataComponent"/>
/// may sometimes require selecting from a set of
/// <see cref="SharedMechanismComponent"/>s to operate on.
/// This function is called in that scenario, and it is expected that you call
/// the callback with one <see cref="SharedMechanismComponent"/> from the provided list.
/// </summary>
public void RequestMechanism(IEnumerable<SharedMechanismComponent> options, MechanismRequestCallback callback);
}
}

View File

@@ -1,83 +0,0 @@
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Surgery
{
/// <summary>
/// Represents the current surgery state of a <see cref="SharedBodyPartComponent"/>.
/// </summary>
public interface ISurgeryData : IComponent
{
public delegate void SurgeryAction(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer);
/// <summary>
/// The <see cref="SharedBodyPartComponent"/> this
/// <see cref="ISurgeryData"/> is attached to.
/// </summary>
public SharedBodyPartComponent? Parent { get; }
/// <summary>
/// The <see cref="BodyPartType"/> of the parent
/// <see cref="SharedBodyPartComponent"/>.
/// </summary>
public BodyPartType? ParentType { get; }
/// <summary>
/// Returns a description of this entity.
/// </summary>
/// <returns>The description shown upon observing this entity.</returns>
public string GetDescription();
/// <summary>
/// Returns whether a <see cref="SharedMechanismComponent"/> can be added into the
/// <see cref="SharedBodyPartComponent"/> this <see cref="ISurgeryData"/>
/// represents.
/// </summary>
public bool CanAddMechanism(SharedMechanismComponent mechanism);
/// <summary>
/// Returns whether the given <see cref="SharedBodyPartComponent"/> can be connected
/// to the <see cref="SharedBodyPartComponent"/> this <see cref="ISurgeryData"/>
/// represents.
/// </summary>
public bool CanAttachBodyPart(SharedBodyPartComponent part);
/// <summary>
/// Gets the delegate corresponding to the surgery step using the given
/// <see cref="SurgeryType"/>.
/// </summary>
/// <returns>
/// The corresponding surgery action or null if no step can be
/// performed.
/// </returns>
public SurgeryAction? GetSurgeryStep(SurgeryType toolType);
/// <summary>
/// Returns whether the given <see cref="SurgeryType"/> can be used to
/// perform a surgery on the <see cref="SharedBodyPartComponent"/> this
/// <see cref="ISurgeryData"/> represents.
/// </summary>
public bool CheckSurgery(SurgeryType toolType)
{
return GetSurgeryStep(toolType) != null;
}
/// <summary>
/// Attempts to perform surgery of the given <see cref="SurgeryType"/>.
/// </summary>
/// <param name="surgeryType">
/// The <see cref="SurgeryType"/> used for this surgery.
/// </param>
/// <param name="container">
/// The container where the surgery is being done.
/// </param>
/// <param name="surgeon">
/// The entity being used to perform the surgery.
/// </param>
/// <param name="performer">The entity performing the surgery.</param>
/// <returns>True if successful, false otherwise.</returns>
public bool PerformSurgery(SurgeryType surgeryType, IBodyPartContainer container, ISurgeon surgeon,
EntityUid performer);
}
}

View File

@@ -1,21 +0,0 @@
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Surgery
{
/// <summary>
/// Types of surgery operations that can be performed.
/// </summary>
// TODO BODY Move this to YAML?
[Serializable, NetSerializable]
public enum SurgeryType
{
None = 0,
Incision,
Retraction,
Cauterization,
VesselCompression,
Drilling,
Amputation
}
}

View File

@@ -1,11 +0,0 @@
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Surgery
{
[Serializable, NetSerializable]
public enum SurgeryUIKey
{
Key
}
}

View File

@@ -1,73 +0,0 @@
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Surgery
{
[Serializable, NetSerializable]
public class RequestBodyPartSurgeryUIMessage : BoundUserInterfaceMessage
{
public Dictionary<string, int> Targets;
public RequestBodyPartSurgeryUIMessage(Dictionary<string, int> targets)
{
Targets = targets;
}
}
[Serializable, NetSerializable]
public class RequestMechanismSurgeryUIMessage : BoundUserInterfaceMessage
{
public Dictionary<string, int> Targets;
public RequestMechanismSurgeryUIMessage(Dictionary<string, int> targets)
{
Targets = targets;
}
}
[Serializable, NetSerializable]
public class RequestBodyPartSlotSurgeryUIMessage : BoundUserInterfaceMessage
{
public Dictionary<string, int> Targets;
public RequestBodyPartSlotSurgeryUIMessage(Dictionary<string, int> targets)
{
Targets = targets;
}
}
[Serializable, NetSerializable]
public class ReceiveBodyPartSurgeryUIMessage : BoundUserInterfaceMessage
{
public int SelectedOptionId;
public ReceiveBodyPartSurgeryUIMessage(int selectedOptionId)
{
SelectedOptionId = selectedOptionId;
}
}
[Serializable, NetSerializable]
public class ReceiveMechanismSurgeryUIMessage : BoundUserInterfaceMessage
{
public int SelectedOptionId;
public ReceiveMechanismSurgeryUIMessage(int selectedOptionId)
{
SelectedOptionId = selectedOptionId;
}
}
[Serializable, NetSerializable]
public class ReceiveBodyPartSlotSurgeryUIMessage : BoundUserInterfaceMessage
{
public int SelectedOptionId;
public ReceiveBodyPartSlotSurgeryUIMessage(int selectedOptionId)
{
SelectedOptionId = selectedOptionId;
}
}
}