diff --git a/Content.Client/GameObjects/EntitySystems/MoverSystem.cs b/Content.Client/GameObjects/EntitySystems/MoverSystem.cs index 08fb4725ef..b460e194a9 100644 --- a/Content.Client/GameObjects/EntitySystems/MoverSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/MoverSystem.cs @@ -25,12 +25,11 @@ namespace Content.Client.GameObjects.EntitySystems { var playerEnt = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEnt == null || !playerEnt.TryGetComponent(out IMoverComponent? mover)) + if (playerEnt == null || !playerEnt.TryGetComponent(out IMoverComponent? mover) || !playerEnt.TryGetComponent(out IPhysicsComponent? physics)) { return; } - var physics = playerEnt.GetComponent(); physics.Predict = true; UpdateKinematics(playerEnt.Transform, mover, physics); diff --git a/Content.Server/GameObjects/Components/Body/Behavior/BrainBehaviorComponent.cs b/Content.Server/GameObjects/Components/Body/Behavior/BrainBehaviorComponent.cs new file mode 100644 index 0000000000..337cb148ce --- /dev/null +++ b/Content.Server/GameObjects/Components/Body/Behavior/BrainBehaviorComponent.cs @@ -0,0 +1,74 @@ +#nullable enable +using Content.Server.GameObjects.Components.Mobs; +using Content.Server.Mobs; +using Content.Shared.GameObjects.Components.Body; +using Content.Shared.GameObjects.Components.Body.Behavior; +using Content.Shared.GameObjects.Components.Body.Part; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.ComponentDependencies; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Log; +using Robust.Shared.ViewVariables; + +namespace Content.Server.GameObjects.Components.Body.Behavior +{ + [RegisterComponent] + public class BrainBehaviorComponent : MechanismBehaviorComponent + { + public override string Name => "Brain"; + + protected override void OnAddedToBody() + { + base.OnAddedToBody(); + + HandleMind(Body!.Owner, Owner); + } + + protected override void OnAddedToPart() + { + base.OnAddedToPart(); + + HandleMind(Part!.Owner, Owner); + } + + protected override void OnAddedToPartInBody() + { + base.OnAddedToPartInBody(); + + HandleMind(Body!.Owner, Owner); + } + + protected override void OnRemovedFromBody(IBody old) + { + base.OnRemovedFromBody(old); + + HandleMind(Part!.Owner, old.Owner); + } + + protected override void OnRemovedFromPart(IBodyPart old) + { + base.OnRemovedFromPart(old); + + HandleMind(Owner, old.Owner); + } + + protected override void OnRemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart) + { + base.OnRemovedFromPartInBody(oldBody, oldPart); + + HandleMind(oldBody!.Owner, Owner); + } + + private void HandleMind(IEntity newEntity, IEntity oldEntity) + { + var newMind = newEntity.EnsureComponent(); + var oldMind = oldEntity.EnsureComponent(); + + oldMind.Mind?.TransferTo(newEntity); + } + + public override void Update(float frameTime) + { + } + } +} diff --git a/Content.Shared/GameObjects/Components/Body/Behavior/BrainBehaviorComponent.cs b/Content.Shared/GameObjects/Components/Body/Behavior/BrainBehaviorComponent.cs deleted file mode 100644 index 706347d994..0000000000 --- a/Content.Shared/GameObjects/Components/Body/Behavior/BrainBehaviorComponent.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Robust.Shared.GameObjects; - -namespace Content.Shared.GameObjects.Components.Body.Behavior -{ - [RegisterComponent] - public class BrainBehaviorComponent : MechanismBehaviorComponent - { - public override string Name => "Brain"; - - public override void Update(float frameTime) - { - // TODO BODY - } - } -} diff --git a/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs b/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs index 40b42ed0b4..ce5aef57c8 100644 --- a/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs @@ -1,5 +1,6 @@ #nullable enable using System.Collections.Generic; +using System.Linq; using Content.Shared.GameObjects.Components.Body.Behavior; using Content.Shared.GameObjects.Components.Body.Part; using Robust.Shared.GameObjects; @@ -132,7 +133,7 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism Owner.Transform.AttachParent(Part!.Owner); OnAddedToPart(); - foreach (var behavior in Owner.GetAllComponents()) + foreach (var behavior in Owner.GetAllComponents().ToArray()) { behavior.AddedToPart(); }