Organ fixes (#20488)

This commit is contained in:
metalgearsloth
2023-09-30 01:01:47 +10:00
committed by GitHub
parent 4313a6ee66
commit 290c2fd502
5 changed files with 24 additions and 49 deletions

View File

@@ -19,25 +19,10 @@ namespace Content.Server.Body.Systems
{
base.Initialize();
SubscribeLocalEvent<BrainComponent, AddedToBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
SubscribeLocalEvent<BrainComponent, AddedToPartEvent>((uid, _, args) => HandleMind(args.Part, uid));
SubscribeLocalEvent<BrainComponent, AddedToPartInBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
SubscribeLocalEvent<BrainComponent, RemovedFromBodyEvent>(OnRemovedFromBody);
SubscribeLocalEvent<BrainComponent, RemovedFromPartEvent>((uid, _, args) => HandleMind(uid, args.Old));
SubscribeLocalEvent<BrainComponent, RemovedFromPartInBodyEvent>((uid, _, args) => HandleMind(args.OldBody, uid));
}
private void OnRemovedFromBody(EntityUid uid, BrainComponent component, RemovedFromBodyEvent args)
{
// This one needs to be special, okay?
if (!EntityManager.TryGetComponent(uid, out OrganComponent? organ))
{
return;
}
HandleMind(uid, args.Old);
}
private void HandleMind(EntityUid newEntity, EntityUid oldEntity)
{
EnsureComp<MindContainerComponent>(newEntity);

View File

@@ -3,19 +3,6 @@
// All of these events are raised on a mechanism entity when added/removed to a body in different
// ways.
/// <summary>
/// Raised on a mechanism when it is added to a body.
/// </summary>
public sealed class AddedToBodyEvent : EntityEventArgs
{
public EntityUid Body;
public AddedToBodyEvent(EntityUid body)
{
Body = body;
}
}
/// <summary>
/// Raised on a mechanism when it is added to a body part.
/// </summary>
@@ -44,29 +31,16 @@
}
}
/// <summary>
/// Raised on a mechanism when it is removed from a body.
/// </summary>
public sealed class RemovedFromBodyEvent : EntityEventArgs
{
public EntityUid Old;
public RemovedFromBodyEvent(EntityUid old)
{
Old = old;
}
}
/// <summary>
/// Raised on a mechanism when it is removed from a body part.
/// </summary>
public sealed class RemovedFromPartEvent : EntityEventArgs
{
public EntityUid Old;
public EntityUid OldPart;
public RemovedFromPartEvent(EntityUid old)
public RemovedFromPartEvent(EntityUid oldPart)
{
Old = old;
OldPart = oldPart;
}
}

View File

@@ -74,7 +74,7 @@ public partial class SharedBodySystem
if (TryComp(entity, out OrganComponent? organ))
{
RemoveOrgan(entity, uid, uid, organ);
RemoveOrgan(entity, uid, organ);
}
}

View File

@@ -12,7 +12,7 @@ public partial class SharedBodySystem
private void AddOrgan(EntityUid uid, EntityUid bodyUid, EntityUid parentPartUid, OrganComponent component)
{
component.Body = bodyUid;
RaiseLocalEvent(uid, new AddedToPartEvent(bodyUid));
RaiseLocalEvent(uid, new AddedToPartEvent(parentPartUid));
if (component.Body != null)
RaiseLocalEvent(uid, new AddedToPartInBodyEvent(component.Body.Value, parentPartUid));
@@ -20,12 +20,14 @@ public partial class SharedBodySystem
Dirty(uid, component);
}
private void RemoveOrgan(EntityUid uid, EntityUid bodyUid, EntityUid parentPartUid, OrganComponent component)
private void RemoveOrgan(EntityUid uid, EntityUid parentPartUid, OrganComponent component)
{
RaiseLocalEvent(uid, new RemovedFromPartEvent(bodyUid));
RaiseLocalEvent(uid, new RemovedFromPartEvent(parentPartUid));
if (component.Body != null)
{
RaiseLocalEvent(uid, new RemovedFromPartInBodyEvent(component.Body.Value, parentPartUid));
}
component.Body = null;
Dirty(uid, component);

View File

@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Body.Components;
using Content.Shared.Body.Events;
using Content.Shared.Body.Organ;
using Content.Shared.Body.Part;
using Content.Shared.Damage;
@@ -61,7 +62,7 @@ public partial class SharedBodySystem
if (TryComp(entity, out OrganComponent? organ))
{
RemoveOrgan(entity, organ);
RemoveOrgan(entity, uid, organ);
}
}
@@ -85,7 +86,20 @@ public partial class SharedBodySystem
{
if (TryComp(organ, out OrganComponent? organComp))
{
var oldBody = organComp.Body;
organComp.Body = bodyUid;
if (bodyUid != null)
{
var ev = new AddedToPartInBodyEvent(bodyUid.Value, children.Id);
RaiseLocalEvent(organ, ev);
}
else if (oldBody != null)
{
var ev = new RemovedFromPartInBodyEvent(oldBody.Value, children.Id);
RaiseLocalEvent(organ, ev);
}
Dirty(organ, organComp);
}
}