diff --git a/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs b/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs deleted file mode 100644 index ef47ff4dc8..0000000000 --- a/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs +++ /dev/null @@ -1,207 +0,0 @@ -#nullable enable -using System.Linq; -using System.Threading.Tasks; -using Content.Server.Body.Behavior; -using Content.Shared.Body.Components; -using Content.Shared.Body.Part; -using NUnit.Framework; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Map; -using Robust.Shared.Maths; - -namespace Content.IntegrationTests.Tests.Body -{ - [TestFixture] - [TestOf(typeof(SharedBodyComponent))] - [TestOf(typeof(SharedBodyPartComponent))] - [TestOf(typeof(SharedMechanismComponent))] - [TestOf(typeof(MechanismBehavior))] - public class MechanismBehaviorEventsTest : ContentIntegrationTest - { - private class TestMechanismBehavior : MechanismBehavior - { - public bool WasAddedToBody; - public bool WasAddedToPart; - public bool WasAddedToPartInBody; - public bool WasRemovedFromBody; - public bool WasRemovedFromPart; - public bool WasRemovedFromPartInBody; - - public bool NoAdded() - { - return !WasAddedToBody && !WasAddedToPart && !WasAddedToPartInBody; - } - - public bool NoRemoved() - { - return !WasRemovedFromBody && !WasRemovedFromPart && !WasRemovedFromPartInBody; - } - - public void ResetAdded() - { - WasAddedToBody = false; - WasAddedToPart = false; - WasAddedToPartInBody = false; - } - - public void ResetRemoved() - { - WasRemovedFromBody = false; - WasRemovedFromPart = false; - WasRemovedFromPartInBody = false; - } - - public void ResetAll() - { - ResetAdded(); - ResetRemoved(); - } - - protected override void OnAddedToBody(SharedBodyComponent body) - { - base.OnAddedToBody(body); - - WasAddedToBody = true; - } - - protected override void OnAddedToPart(SharedBodyPartComponent part) - { - base.OnAddedToPart(part); - - WasAddedToPart = true; - } - - protected override void OnAddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part) - { - base.OnAddedToPartInBody(body, part); - - WasAddedToPartInBody = true; - } - - protected override void OnRemovedFromBody(SharedBodyComponent old) - { - base.OnRemovedFromBody(old); - - WasRemovedFromBody = true; - } - - protected override void OnRemovedFromPart(SharedBodyPartComponent old) - { - base.OnRemovedFromPart(old); - - WasRemovedFromPart = true; - } - - protected override void OnRemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart) - { - base.OnRemovedFromPartInBody(oldBody, oldPart); - - WasRemovedFromPartInBody = true; - } - } - - private const string Prototypes = @" -- type: entity - name: HumanBodyDummy - id: HumanBodyDummy - components: - - type: Body - template: HumanoidTemplate - preset: HumanPreset - centerSlot: torso -"; - - [Test] - public async Task EventsTest() - { - var options = new ServerContentIntegrationOption {ExtraPrototypes = Prototypes}; - var server = StartServer(options); - - await server.WaitAssertion(() => - { - var mapManager = IoCManager.Resolve(); - - var mapId = mapManager.CreateMap(); - - var entityManager = IoCManager.Resolve(); - var human = entityManager.SpawnEntity("HumanBodyDummy", new MapCoordinates(Vector2.Zero, mapId)); - - Assert.That(human.TryGetComponent(out SharedBodyComponent? body)); - Assert.NotNull(body); - - var centerPart = body!.CenterPart; - Assert.NotNull(centerPart); - - Assert.That(body.TryGetSlot(centerPart!, out var centerSlot)); - Assert.NotNull(centerSlot); - - var mechanism = centerPart!.Mechanisms.First(); - Assert.NotNull(mechanism); - - mechanism.EnsureBehavior(out var behavior); - Assert.False(behavior.WasAddedToBody); - Assert.False(behavior.WasAddedToPart); - Assert.That(behavior.WasAddedToPartInBody); - Assert.That(behavior.NoRemoved); - - behavior.ResetAll(); - - Assert.That(behavior.NoAdded); - Assert.That(behavior.NoRemoved); - - centerPart.RemoveMechanism(mechanism); - - Assert.That(behavior.NoAdded); - Assert.False(behavior.WasRemovedFromBody); - Assert.False(behavior.WasRemovedFromPart); - Assert.That(behavior.WasRemovedFromPartInBody); - - behavior.ResetAll(); - - centerPart.TryAddMechanism(mechanism, true); - - Assert.False(behavior.WasAddedToBody); - Assert.False(behavior.WasAddedToPart); - Assert.That(behavior.WasAddedToPartInBody); - Assert.That(behavior.NoRemoved()); - - behavior.ResetAll(); - - body.RemovePart(centerPart); - - Assert.That(behavior.NoAdded); - Assert.That(behavior.WasRemovedFromBody); - Assert.False(behavior.WasRemovedFromPart); - Assert.False(behavior.WasRemovedFromPartInBody); - - behavior.ResetAll(); - - centerPart.RemoveMechanism(mechanism); - - Assert.That(behavior.NoAdded); - Assert.False(behavior.WasRemovedFromBody); - Assert.That(behavior.WasRemovedFromPart); - Assert.False(behavior.WasRemovedFromPartInBody); - - behavior.ResetAll(); - - centerPart.TryAddMechanism(mechanism, true); - - Assert.False(behavior.WasAddedToBody); - Assert.That(behavior.WasAddedToPart); - Assert.False(behavior.WasAddedToPartInBody); - Assert.That(behavior.NoRemoved); - - behavior.ResetAll(); - - body.SetPart(centerSlot!.Id, centerPart); - - Assert.That(behavior.WasAddedToBody); - Assert.False(behavior.WasAddedToPart); - Assert.False(behavior.WasAddedToPartInBody); - Assert.That(behavior.NoRemoved); - }); - } - } -} diff --git a/Content.Server/Body/Behavior/MechanismBehavior.cs b/Content.Server/Body/Behavior/MechanismBehavior.cs deleted file mode 100644 index 40ace4a985..0000000000 --- a/Content.Server/Body/Behavior/MechanismBehavior.cs +++ /dev/null @@ -1,109 +0,0 @@ -using Content.Shared.Body.Behavior; -using Content.Shared.Body.Components; -using Content.Shared.Body.Part; -using Robust.Shared.GameObjects; -using Robust.Shared.Utility; - -namespace Content.Server.Body.Behavior -{ - public abstract class MechanismBehavior : SharedMechanismBehavior - { - private SharedMechanismComponent _parent = default!; - - public override SharedBodyComponent? Body => Part?.Body; - - public override SharedBodyPartComponent? Part => Parent.Part; - - public override SharedMechanismComponent Parent => _parent; - - public override IEntity Owner => Parent.Owner; - - public override void Initialize(SharedMechanismComponent parent) - { - _parent = parent; - } - - public override void Startup() - { - if (Part == null) - { - return; - } - - if (Body == null) - { - AddedToPart(Part); - } - else - { - AddedToPartInBody(Body, Part); - } - } - - public override void Update(float frameTime) { } - - public override void AddedToBody(SharedBodyComponent body) - { - DebugTools.AssertNotNull(Body); - DebugTools.AssertNotNull(body); - - OnAddedToBody(body); - } - - public override void AddedToPart(SharedBodyPartComponent part) - { - DebugTools.AssertNotNull(Part); - DebugTools.AssertNotNull(part); - - OnAddedToPart(part); - } - - public override void AddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part) - { - DebugTools.AssertNotNull(Body); - DebugTools.AssertNotNull(body); - DebugTools.AssertNotNull(Part); - DebugTools.AssertNotNull(part); - - OnAddedToPartInBody(body, part); - } - - public override void RemovedFromBody(SharedBodyComponent old) - { - DebugTools.AssertNull(Body); - DebugTools.AssertNotNull(old); - - OnRemovedFromBody(old); - } - - public override void RemovedFromPart(SharedBodyPartComponent old) - { - DebugTools.AssertNull(Part); - DebugTools.AssertNotNull(old); - - OnRemovedFromPart(old); - } - - public override void RemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart) - { - DebugTools.AssertNull(Body); - DebugTools.AssertNull(Part); - DebugTools.AssertNotNull(oldBody); - DebugTools.AssertNotNull(oldPart); - - OnRemovedFromPartInBody(oldBody, oldPart); - } - - protected virtual void OnAddedToBody(SharedBodyComponent body) { } - - protected virtual void OnAddedToPart(SharedBodyPartComponent part) { } - - protected virtual void OnAddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part) { } - - protected virtual void OnRemovedFromBody(SharedBodyComponent old) { } - - protected virtual void OnRemovedFromPart(SharedBodyPartComponent old) { } - - protected virtual void OnRemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart) { } - } -} diff --git a/Content.Server/Body/Components/RespiratorComponent.cs b/Content.Server/Body/Components/RespiratorComponent.cs index d379125b5d..fc241a1b51 100644 --- a/Content.Server/Body/Components/RespiratorComponent.cs +++ b/Content.Server/Body/Components/RespiratorComponent.cs @@ -1,26 +1,9 @@ -using System; using System.Collections.Generic; -using System.Linq; -using Content.Server.Administration.Logs; -using Content.Server.Alert; -using Content.Server.Atmos; -using Content.Server.Atmos.EntitySystems; -using Content.Server.Body.Behavior; using Content.Server.Body.Systems; -using Content.Server.Temperature.Components; -using Content.Server.Temperature.Systems; -using Content.Shared.ActionBlocker; -using Content.Shared.Administration.Logs; -using Content.Shared.Alert; using Content.Shared.Atmos; -using Content.Shared.Body.Components; using Content.Shared.Damage; -using Content.Shared.Database; -using Content.Shared.MobState.Components; -using Content.Shared.Popups; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; -using Robust.Shared.Localization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; diff --git a/Content.Shared/Body/Behavior/SharedMechanismBehavior.cs b/Content.Shared/Body/Behavior/SharedMechanismBehavior.cs deleted file mode 100644 index 286c290140..0000000000 --- a/Content.Shared/Body/Behavior/SharedMechanismBehavior.cs +++ /dev/null @@ -1,117 +0,0 @@ -using Content.Shared.Body.Components; -using Content.Shared.Body.Part; -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization.Manager.Attributes; - -namespace Content.Shared.Body.Behavior -{ - /// - /// Gives functionality to a mechanism when added to it. - /// - [ImplicitDataDefinitionForInheritors] - public abstract class SharedMechanismBehavior - { - public abstract SharedBodyComponent? Body { get; } - - public abstract SharedBodyPartComponent? Part { get; } - - public abstract SharedMechanismComponent Parent { get; } - - /// - /// The entity that owns . - /// For the entity owning the body that this mechanism may be in, - /// see 's . - /// - public abstract IEntity Owner { get; } - - /// - /// Called when this behavior is added to a mechanism, during . - /// If it is added after component initialization, - /// it is called immediately. - /// - /// - /// The mechanism that owns this behavior. - /// - public abstract void Initialize(SharedMechanismComponent parent); - - /// - /// Called when this behavior is added to a mechanism, during . - /// If it is added after component startup, it is called immediately. - /// - public abstract void Startup(); - - /// - /// Runs an update cycle on this behavior. - /// - /// - /// The amount of seconds that passed since the last update. - /// - public abstract void Update(float frameTime); - - /// - /// Called when the containing part is attached to a body. - /// For instance, attaching a head with a brain inside to a body. - /// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE! - /// - /// - /// The body that the containing mechanism was added to. - /// - public abstract void AddedToBody(SharedBodyComponent body); - - /// - /// Called when the parent mechanism is added into a part that is not attached to a body. - /// For instance, adding a brain to a dismembered head. - /// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE! - /// - /// - /// The part that the containing mechanism was added to. - /// - public abstract void AddedToPart(SharedBodyPartComponent part); - - /// - /// Called when the parent mechanism is added to a part that is attached to a body. - /// For instance, adding a brain to a head that is attached to a body. - /// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE! - /// - /// - /// The body that the containing mechanism was added to. - /// - /// - /// The part that the containing mechanism was added to. - /// - public abstract void AddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part); - - /// - /// Called when the parent part is removed from a body. - /// For instance, removing a head with a brain inside from a body. - /// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE! - /// - /// - /// The body that the containing mechanism was removed from. - /// - public abstract void RemovedFromBody(SharedBodyComponent old); - - /// - /// Called when the parent mechanism is removed from a part that is not attached to a body. - /// For instance, removing a brain from a dismembered head. - /// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE! - /// - /// - /// The part that the containing mechanism was removed from. - /// - public abstract void RemovedFromPart(SharedBodyPartComponent old); - - /// - /// Called when the parent mechanism is removed from a part that is attached to a body. - /// For instance, removing a brain from a head that is attached to a body. - /// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE! - /// - /// - /// The body that the containing mechanism was removed from. - /// - /// - /// The part that the containing mechanism was removed from. - /// - public abstract void RemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart); - } -} diff --git a/Content.Shared/Body/Components/SharedBodyComponent.cs b/Content.Shared/Body/Components/SharedBodyComponent.cs index 9e9102af05..8caafb5251 100644 --- a/Content.Shared/Body/Components/SharedBodyComponent.cs +++ b/Content.Shared/Body/Components/SharedBodyComponent.cs @@ -2,19 +2,15 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Content.Shared.Body.Behavior; using Content.Shared.Body.Part; -using Content.Shared.Body.Part.Property; using Content.Shared.Body.Prototypes; using Content.Shared.CharacterAppearance.Systems; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; -using Content.Shared.Movement.Components; using Content.Shared.Standing; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; -using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; @@ -34,11 +30,11 @@ namespace Content.Shared.Body.Components [ViewVariables] [DataField("template", required: true)] - private string? TemplateId { get; } = default; + private string? TemplateId { get; } [ViewVariables] [DataField("preset", required: true)] - private string? PresetId { get; } = default; + private string? PresetId { get; } [ViewVariables] public BodyTemplatePrototype? Template => TemplateId == null @@ -449,93 +445,11 @@ namespace Content.Shared.Body.Components } } - /// A list of parts with that property. - public IEnumerable<(SharedBodyPartComponent part, IBodyPartProperty property)> GetPartsWithProperty(Type type) - { - foreach (var slot in SlotIds.Values) - { - if (slot.Part != null && slot.Part.TryGetProperty(type, out var property)) - { - yield return (slot.Part, property); - } - } - } - - public IEnumerable<(SharedBodyPartComponent part, T property)> GetPartsWithProperty() where T : class, IBodyPartProperty - { - foreach (var part in SlotParts.Keys) - { - if (part.TryGetProperty(out var property)) - { - yield return (part, property); - } - } - } - - private void OnBodyChanged() { Dirty(); } - public float DistanceToNearestFoot(SharedBodyPartComponent source) - { - if (source.PartType == BodyPartType.Foot && - source.TryGetProperty(out var extension)) - { - return extension.Distance; - } - - return LookForFootRecursion(source); - } - - private float LookForFootRecursion(SharedBodyPartComponent current, HashSet? searched = null) - { - searched ??= new HashSet(); - - if (!current.TryGetProperty(out var extProperty)) - { - return float.MinValue; - } - - if (!TryGetSlot(current, out var slot)) - { - return float.MinValue; - } - - foreach (var connection in slot.Connections) - { - if (connection.PartType == BodyPartType.Foot && - !searched.Contains(connection)) - { - return extProperty.Distance; - } - } - - var distances = new List(); - foreach (var connection in slot.Connections) - { - if (connection.Part == null || !searched.Contains(connection)) - { - continue; - } - - var result = LookForFootRecursion(connection.Part, searched); - - if (Math.Abs(result - float.MinValue) > 0.001f) - { - distances.Add(result); - } - } - - if (distances.Count > 0) - { - return distances.Min() + extProperty.Distance; - } - - return float.MinValue; - } - // TODO BODY optimize this public BodyPartSlot SlotAt(int index) { @@ -601,62 +515,6 @@ namespace Content.Shared.Body.Components part.Gib(); } } - - public bool TryGetMechanismBehaviors([NotNullWhen(true)] out List? behaviors) - { - behaviors = GetMechanismBehaviors().ToList(); - - if (behaviors.Count == 0) - { - behaviors = null; - return false; - } - - return true; - } - - public bool HasMechanismBehavior() where T : SharedMechanismBehavior - { - return Parts.Any(p => p.Key.HasMechanismBehavior()); - } - - // TODO cache these 2 methods jesus - public IEnumerable GetMechanismBehaviors() - { - foreach (var (part, _) in Parts) - foreach (var mechanism in part.Mechanisms) - foreach (var behavior in mechanism.Behaviors.Values) - { - yield return behavior; - } - } - - public IEnumerable GetMechanismBehaviors() where T : SharedMechanismBehavior - { - foreach (var (part, _) in Parts) - foreach (var mechanism in part.Mechanisms) - foreach (var behavior in mechanism.Behaviors.Values) - { - if (behavior is T tBehavior) - { - yield return tBehavior; - } - } - } - - public bool TryGetMechanismBehaviors([NotNullWhen(true)] out List? behaviors) - where T : SharedMechanismBehavior - { - behaviors = GetMechanismBehaviors().ToList(); - - if (behaviors.Count == 0) - { - behaviors = null; - return false; - } - - return true; - } } [Serializable, NetSerializable] diff --git a/Content.Shared/Body/Components/SharedBodyPartComponent.cs b/Content.Shared/Body/Components/SharedBodyPartComponent.cs index f1424ec26e..8655308f4e 100644 --- a/Content.Shared/Body/Components/SharedBodyPartComponent.cs +++ b/Content.Shared/Body/Components/SharedBodyPartComponent.cs @@ -1,16 +1,13 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; -using Content.Shared.Body.Behavior; +using Content.Shared.Body.Events; using Content.Shared.Body.Part; -using Content.Shared.Body.Part.Property; using Content.Shared.Body.Surgery; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; @@ -307,7 +304,7 @@ namespace Content.Shared.Body.Components foreach (var mechanism in _mechanisms) { - mechanism.AddedToBody(body); + Owner.EntityManager.EventBus.RaiseLocalEvent(mechanism.OwnerUid, new AddedToBodyEvent(body)); } } @@ -322,7 +319,7 @@ namespace Content.Shared.Body.Components foreach (var mechanism in _mechanisms) { - mechanism.RemovedFromBody(old); + Owner.EntityManager.EventBus.RaiseLocalEvent(mechanism.OwnerUid, new RemovedFromBodyEvent(old)); } } @@ -340,38 +337,6 @@ namespace Content.Shared.Body.Components RemoveMechanism(mechanism); } } - - public bool HasProperty(Type type) - { - return Owner.HasComponent(type); - } - - public bool HasProperty() where T : class, IBodyPartProperty - { - return HasProperty(typeof(T)); - } - - public bool TryGetProperty(Type type, - [NotNullWhen(true)] out IBodyPartProperty? property) - { - if (!Owner.TryGetComponent(type, out var component)) - { - property = null; - return false; - } - - return (property = component as IBodyPartProperty) != null; - } - - public bool TryGetProperty([NotNullWhen(true)] out T? property) where T : class, IBodyPartProperty - { - return Owner.TryGetComponent(out property); - } - - public bool HasMechanismBehavior() where T : SharedMechanismBehavior - { - return Mechanisms.Any(m => m.HasBehavior()); - } } [Serializable, NetSerializable] diff --git a/Content.Shared/Body/Components/SharedMechanismComponent.cs b/Content.Shared/Body/Components/SharedMechanismComponent.cs index 515b233fba..106381995d 100644 --- a/Content.Shared/Body/Components/SharedMechanismComponent.cs +++ b/Content.Shared/Body/Components/SharedMechanismComponent.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Content.Shared.Body.Behavior; +using System.Collections.Generic; using Content.Shared.Body.Events; using Content.Shared.Body.Part; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Log; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; namespace Content.Shared.Body.Components { @@ -23,10 +17,6 @@ namespace Content.Shared.Body.Components protected IEntity? PerformerCache; private SharedBodyPartComponent? _part; - [DataField("behaviors", serverOnly: true)] private HashSet _behaviorTypes = new(); - - private readonly Dictionary _behaviors = new(); - public SharedBodyComponent? Body => Part?.Body; public SharedBodyPartComponent? Part @@ -46,11 +36,11 @@ namespace Content.Shared.Body.Components { if (old.Body == null) { - RemovedFromPart(old); + Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new RemovedFromPartEvent(old)); } else { - RemovedFromPartInBody(old.Body, old); + Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new RemovedFromPartInBodyEvent(old.Body, old)); } } @@ -58,18 +48,16 @@ namespace Content.Shared.Body.Components { if (value.Body == null) { - AddedToPart(value); + Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new AddedToPartEvent(value)); } else { - AddedToPartInBody(value.Body, value); + Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new AddedToPartInBodyEvent(value.Body, value)); } } } } - public IReadOnlyDictionary Behaviors => _behaviors; - [DataField("maxDurability")] public int MaxDurability { get; set; } = 10; [DataField("currentDurability")] public int CurrentDurability { get; set; } = 10; @@ -93,176 +81,5 @@ namespace Content.Shared.Body.Components /// [DataField("compatibility")] public BodyPartCompatibility Compatibility { get; set; } = BodyPartCompatibility.Universal; - - void ISerializationHooks.BeforeSerialization() - { - _behaviorTypes = _behaviors.Values.ToHashSet(); - } - - void ISerializationHooks.AfterDeserialization() - { - foreach (var behavior in _behaviorTypes) - { - var type = behavior.GetType(); - - if (!_behaviors.TryAdd(type, behavior)) - { - Logger.Warning($"Duplicate behavior in {nameof(SharedMechanismComponent)}: {type}."); - continue; - } - - IoCManager.InjectDependencies(behavior); - } - } - - protected override void Initialize() - { - base.Initialize(); - - foreach (var behavior in _behaviors.Values) - { - behavior.Initialize(this); - } - } - - protected override void Startup() - { - base.Startup(); - - foreach (var behavior in _behaviors.Values) - { - behavior.Startup(); - } - } - - public bool EnsureBehavior(out T behavior) where T : SharedMechanismBehavior, new() - { - if (_behaviors.TryGetValue(typeof(T), out var rawBehavior)) - { - behavior = (T) rawBehavior; - return true; - } - - behavior = IoCManager.Resolve().CreateInstance(); - _behaviors.Add(typeof(T), behavior); - behavior.Initialize(this); - behavior.Startup(); - - return false; - } - - public bool HasBehavior() where T : SharedMechanismBehavior - { - return _behaviors.ContainsKey(typeof(T)); - } - - public bool TryRemoveBehavior() where T : SharedMechanismBehavior - { - return _behaviors.Remove(typeof(T)); - } - - public void Update(float frameTime) - { - foreach (var behavior in _behaviors.Values) - { - behavior.Update(frameTime); - } - } - - public void AddedToBody(SharedBodyComponent body) - { - DebugTools.AssertNotNull(Body); - DebugTools.AssertNotNull(body); - - var ev = new AddedToBodyEvent(body); - Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false); - - foreach (var behavior in _behaviors.Values) - { - behavior.AddedToBody(body); - } - } - - public void AddedToPart(SharedBodyPartComponent part) - { - DebugTools.AssertNotNull(Part); - DebugTools.AssertNotNull(part); - - Owner.Transform.AttachParent(part.Owner); - - var ev = new AddedToPartEvent(part); - Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false); - - foreach (var behavior in _behaviors.Values) - { - behavior.AddedToPart(part); - } - } - - public void AddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part) - { - DebugTools.AssertNotNull(Body); - DebugTools.AssertNotNull(body); - DebugTools.AssertNotNull(Part); - DebugTools.AssertNotNull(part); - - Owner.Transform.AttachParent(part.Owner); - - var ev = new AddedToPartInBodyEvent(body, part); - Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false); - - foreach (var behavior in _behaviors.Values) - { - behavior.AddedToPartInBody(body, part); - } - } - - public void RemovedFromBody(SharedBodyComponent old) - { - DebugTools.AssertNull(Body); - DebugTools.AssertNotNull(old); - - var ev = new RemovedFromBodyEvent(old); - Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false); - - foreach (var behavior in _behaviors.Values) - { - behavior.RemovedFromBody(old); - } - } - - public void RemovedFromPart(SharedBodyPartComponent old) - { - DebugTools.AssertNull(Part); - DebugTools.AssertNotNull(old); - - Owner.Transform.AttachToGridOrMap(); - - var ev = new RemovedFromPartEvent(old); - Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false); - - foreach (var behavior in _behaviors.Values) - { - behavior.RemovedFromPart(old); - } - } - - public void RemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart) - { - DebugTools.AssertNull(Body); - DebugTools.AssertNotNull(oldBody); - DebugTools.AssertNull(Part); - DebugTools.AssertNotNull(oldPart); - - Owner.Transform.AttachToGridOrMap(); - - var ev = new RemovedFromPartInBodyEvent(oldBody, oldPart); - Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false); - - foreach (var behavior in _behaviors.Values) - { - behavior.RemovedFromPartInBody(oldBody, oldPart); - } - } } } diff --git a/Content.Shared/Body/BodyPartSlot.cs b/Content.Shared/Body/Part/BodyPartSlot.cs similarity index 98% rename from Content.Shared/Body/BodyPartSlot.cs rename to Content.Shared/Body/Part/BodyPartSlot.cs index 072bc1773d..cc18bd0dc8 100644 --- a/Content.Shared/Body/BodyPartSlot.cs +++ b/Content.Shared/Body/Part/BodyPartSlot.cs @@ -4,7 +4,7 @@ using Content.Shared.Body.Components; using Content.Shared.Body.Part; using Robust.Shared.ViewVariables; -namespace Content.Shared.Body +namespace Content.Shared.Body.Part { public class BodyPartSlot { diff --git a/Content.Shared/Body/Part/Property/BodyPartPropertyComponent.cs b/Content.Shared/Body/Part/Property/BodyPartPropertyComponent.cs deleted file mode 100644 index 2eeba22d26..0000000000 --- a/Content.Shared/Body/Part/Property/BodyPartPropertyComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Shared.Body.Components; -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization.Manager.Attributes; - -namespace Content.Shared.Body.Part.Property -{ - /// - /// Property attachable to a . - /// For example, this is used to define the speed capabilities of a leg. - /// The movement system will look for a on all - /// . - /// - public abstract class BodyPartPropertyComponent : Component, IBodyPartProperty - { - /// - /// Whether this property is currently active. - /// - [DataField("active")] - public bool Active { get; set; } = true; - } -} diff --git a/Content.Shared/Body/Part/Property/ExtensionComponent.cs b/Content.Shared/Body/Part/Property/ExtensionComponent.cs deleted file mode 100644 index 32003b4c20..0000000000 --- a/Content.Shared/Body/Part/Property/ExtensionComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Shared.Body.Components; -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization.Manager.Attributes; - -namespace Content.Shared.Body.Part.Property -{ - /// - /// Defines the length of a . - /// - [RegisterComponent] - public class ExtensionComponent : BodyPartPropertyComponent - { - public override string Name => "Extension"; - - /// - /// Current distance in tiles. - /// - [DataField("distance")] - public float Distance { get; set; } = 3f; - } -} diff --git a/Content.Shared/Body/Part/Property/GraspComponent.cs b/Content.Shared/Body/Part/Property/GraspComponent.cs deleted file mode 100644 index 8451654f8e..0000000000 --- a/Content.Shared/Body/Part/Property/GraspComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Content.Shared.Body.Components; -using Robust.Shared.GameObjects; - -namespace Content.Shared.Body.Part.Property -{ - /// - /// Defines a as being able to grasp around an entity, - /// for example picking up an item. - /// - // TODO BODY Implement - [RegisterComponent] - public class GraspComponent : BodyPartPropertyComponent - { - public override string Name => "Grasp"; - } -} diff --git a/Content.Shared/Body/Part/Property/IBodyPartProperty.cs b/Content.Shared/Body/Part/Property/IBodyPartProperty.cs deleted file mode 100644 index c9330db62d..0000000000 --- a/Content.Shared/Body/Part/Property/IBodyPartProperty.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Content.Shared.Body.Components; -using Robust.Shared.GameObjects; - -namespace Content.Shared.Body.Part.Property -{ - /// - /// Defines a property for a . - /// - public interface IBodyPartProperty : IComponent - { - bool Active { get; set; } - } -} diff --git a/Content.Shared/Body/Part/Property/LegComponent.cs b/Content.Shared/Body/Part/Property/LegComponent.cs deleted file mode 100644 index 1fb9744cae..0000000000 --- a/Content.Shared/Body/Part/Property/LegComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Shared.Body.Components; -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization.Manager.Attributes; - -namespace Content.Shared.Body.Part.Property -{ - /// - /// Defines the speed at which a can move. - /// - [RegisterComponent] - public class LegComponent : BodyPartPropertyComponent - { - public override string Name => "Leg"; - - /// - /// Speed in tiles per second. - /// - [DataField("speed")] - public float Speed { get; set; } = 2.6f; - } -} diff --git a/Content.Shared/Body/Systems/MechanismSystem.cs b/Content.Shared/Body/Systems/MechanismSystem.cs deleted file mode 100644 index 1af083dbc8..0000000000 --- a/Content.Shared/Body/Systems/MechanismSystem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Content.Shared.Body.Components; -using JetBrains.Annotations; -using Robust.Shared.GameObjects; - -namespace Content.Shared.Body.Systems -{ - [UsedImplicitly] - public class MechanismSystem : EntitySystem - { - public override void Update(float frameTime) - { - base.Update(frameTime); - - foreach (var mechanism in EntityManager.EntityQuery(true)) - { - mechanism.Update(frameTime); - } - } - } -} diff --git a/Resources/Prototypes/Body/Parts/animal.yml b/Resources/Prototypes/Body/Parts/animal.yml index e7cb951a9d..3071aba32c 100644 --- a/Resources/Prototypes/Body/Parts/animal.yml +++ b/Resources/Prototypes/Body/Parts/animal.yml @@ -24,7 +24,6 @@ size: 1 compatibility: Biological symmetry: Left - - type: Grasp - type: entity id: LegsAnimal diff --git a/Resources/Prototypes/Body/Parts/human.yml b/Resources/Prototypes/Body/Parts/human.yml index 3066f0743c..5d65b479bc 100644 --- a/Resources/Prototypes/Body/Parts/human.yml +++ b/Resources/Prototypes/Body/Parts/human.yml @@ -83,8 +83,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 40 # deadThreshold: 80 - - type: Extension - distance: 2.4 - type: entity id: RightArmHuman @@ -106,8 +104,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 40 # deadThreshold: 80 - - type: Extension - distance: 2.4 - type: entity id: LeftHandHuman @@ -129,7 +125,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 30 # deadThreshold: 60 - - type: Grasp - type: entity id: RightHandHuman @@ -151,7 +146,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 30 # deadThreshold: 60 - - type: Grasp - type: entity id: LeftLegHuman @@ -173,10 +167,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 45 # deadThreshold: 90 - - type: Leg - speed: 2.6 - - type: Extension - distance: 3.0 - type: entity id: RightLegHuman @@ -198,10 +188,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 45 # deadThreshold: 90 - - type: Leg - speed: 2.6 - - type: Extension - distance: 3.0 - type: entity id: LeftFootHuman diff --git a/Resources/Prototypes/Body/Parts/slime.yml b/Resources/Prototypes/Body/Parts/slime.yml index 3909e35240..40e82f2a6e 100644 --- a/Resources/Prototypes/Body/Parts/slime.yml +++ b/Resources/Prototypes/Body/Parts/slime.yml @@ -82,8 +82,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 40 # deadThreshold: 80 - - type: Extension - distance: 2.4 - type: entity id: RightArmSlime @@ -105,8 +103,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 40 # deadThreshold: 80 - - type: Extension - distance: 2.4 - type: entity id: LeftHandSlime @@ -128,7 +124,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 30 # deadThreshold: 60 - - type: Grasp - type: entity id: RightHandSlime @@ -150,7 +145,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 30 # deadThreshold: 60 - - type: Grasp - type: entity id: LeftLegSlime @@ -170,10 +164,6 @@ compatibility: Biological symmetry: Left - type: BiologicalSurgeryData - - type: Leg - speed: 2.6 - - type: Extension - distance: 3.0 - type: entity id: RightLegSlime @@ -195,10 +185,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 45 # deadThreshold: 90 - - type: Leg - speed: 2.6 - - type: Extension - distance: 3.0 - type: entity id: LeftFootSlime diff --git a/Resources/Prototypes/Body/Parts/vox.yml b/Resources/Prototypes/Body/Parts/vox.yml index 65b4d963eb..502e7dc5b6 100644 --- a/Resources/Prototypes/Body/Parts/vox.yml +++ b/Resources/Prototypes/Body/Parts/vox.yml @@ -8,7 +8,7 @@ components: - type: Damageable damageContainer: Biological - + - type: entity id: TorsoVox name: "vox torso" @@ -84,8 +84,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 40 # deadThreshold: 80 - - type: Extension - distance: 2.4 - type: entity id: RightArmVox @@ -107,8 +105,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 40 # deadThreshold: 80 - - type: Extension - distance: 2.4 - type: entity id: LeftHandVox @@ -130,7 +126,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 30 # deadThreshold: 60 - - type: Grasp - type: entity id: RightHandVox @@ -152,7 +147,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 30 # deadThreshold: 60 - - type: Grasp - type: entity id: LeftLegVox @@ -174,10 +168,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 45 # deadThreshold: 90 - - type: Leg - speed: 2.6 - - type: Extension - distance: 3.0 - type: entity id: RightLegVox @@ -199,10 +189,6 @@ - type: BiologicalSurgeryData # criticalThreshold: 45 # deadThreshold: 90 - - type: Leg - speed: 2.6 - - type: Extension - distance: 3.0 - type: entity id: LeftFootVox