Files
tbd-station-14/Content.Server/GameObjects/Components/Body/Behavior/BrainBehavior.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

71 lines
2.0 KiB
C#

#nullable enable
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Observer;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Part;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Body.Behavior
{
public class BrainBehavior : MechanismBehavior
{
protected override void OnAddedToBody(IBody body)
{
base.OnAddedToBody(body);
HandleMind(body.Owner, Owner);
}
protected override void OnAddedToPart(IBodyPart part)
{
base.OnAddedToPart(part);
HandleMind(part.Owner, Owner);
}
protected override void OnAddedToPartInBody(IBody body, IBodyPart part)
{
base.OnAddedToPartInBody(body, part);
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)
{
newEntity.EnsureComponent<MindComponent>();
var oldMind = oldEntity.EnsureComponent<MindComponent>();
if (!newEntity.HasComponent<IGhostOnMove>())
newEntity.AddComponent<GhostOnMoveComponent>();
// TODO: This is an awful solution.
if (!newEntity.HasComponent<IMoverComponent>())
newEntity.AddComponent<SharedDummyInputMoverComponent>();
oldMind.Mind?.TransferTo(newEntity);
}
}
}