Try fix organ networking (#23034)
This commit is contained in:
43
Content.IntegrationTests/Tests/Body/GibTest.cs
Normal file
43
Content.IntegrationTests/Tests/Body/GibTest.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#nullable enable
|
||||||
|
using Content.Server.Body.Systems;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.IntegrationTests.Tests.Body;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public sealed class GibTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public async Task TestGib()
|
||||||
|
{
|
||||||
|
await using var pair = await PoolManager.GetServerClient(new PoolSettings { Connected = true });
|
||||||
|
var (server, client) = (pair.Server, pair.Client);
|
||||||
|
var map = await pair.CreateTestMap();
|
||||||
|
|
||||||
|
EntityUid target1 = default;
|
||||||
|
EntityUid target2 = default;
|
||||||
|
|
||||||
|
await server.WaitAssertion(() => target1 = server.EntMan.Spawn("MobHuman", map.MapCoords));
|
||||||
|
await server.WaitAssertion(() => target2 = server.EntMan.Spawn("MobHuman", map.MapCoords));
|
||||||
|
await pair.WaitCommand($"setoutfit {server.EntMan.GetNetEntity(target1)} CaptainGear");
|
||||||
|
await pair.WaitCommand($"setoutfit {server.EntMan.GetNetEntity(target2)} CaptainGear");
|
||||||
|
|
||||||
|
await pair.RunTicksSync(5);
|
||||||
|
var nuid1 = pair.ToClientUid(target1);
|
||||||
|
var nuid2 = pair.ToClientUid(target2);
|
||||||
|
Assert.That(client.EntMan.EntityExists(nuid1));
|
||||||
|
Assert.That(client.EntMan.EntityExists(nuid2));
|
||||||
|
|
||||||
|
await server.WaitAssertion(() => server.System<BodySystem>().GibBody(target1, gibOrgans: false));
|
||||||
|
await server.WaitAssertion(() => server.System<BodySystem>().GibBody(target2, gibOrgans: true));
|
||||||
|
|
||||||
|
await pair.RunTicksSync(5);
|
||||||
|
await pair.WaitCommand("dirty");
|
||||||
|
await pair.RunTicksSync(5);
|
||||||
|
|
||||||
|
Assert.That(!client.EntMan.EntityExists(nuid1));
|
||||||
|
Assert.That(!client.EntMan.EntityExists(nuid2));
|
||||||
|
|
||||||
|
await pair.CleanReturnAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ using Content.Shared.Inventory;
|
|||||||
using Content.Shared.Inventory.Events;
|
using Content.Shared.Inventory.Events;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Body.Systems;
|
namespace Content.Shared.Body.Systems;
|
||||||
|
|
||||||
@@ -58,10 +59,6 @@ public partial class SharedBodySystem
|
|||||||
|
|
||||||
private void OnBodyRemoved(EntityUid uid, BodyComponent component, EntRemovedFromContainerMessage args)
|
private void OnBodyRemoved(EntityUid uid, BodyComponent component, EntRemovedFromContainerMessage args)
|
||||||
{
|
{
|
||||||
// TODO: lifestage shenanigans
|
|
||||||
if (TerminatingOrDeleted(uid))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Root body part?
|
// Root body part?
|
||||||
var slotId = args.Container.ID;
|
var slotId = args.Container.ID;
|
||||||
|
|
||||||
@@ -69,6 +66,8 @@ public partial class SharedBodySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var entity = args.Entity;
|
var entity = args.Entity;
|
||||||
|
DebugTools.Assert(!TryComp(entity, out BodyPartComponent? b) || b.Body == uid);
|
||||||
|
DebugTools.Assert(!TryComp(entity, out OrganComponent? o) || o.Body == uid);
|
||||||
|
|
||||||
if (TryComp(entity, out BodyPartComponent? childPart))
|
if (TryComp(entity, out BodyPartComponent? childPart))
|
||||||
{
|
{
|
||||||
@@ -77,9 +76,7 @@ public partial class SharedBodySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TryComp(entity, out OrganComponent? organ))
|
if (TryComp(entity, out OrganComponent? organ))
|
||||||
{
|
|
||||||
RemoveOrgan(entity, uid, organ);
|
RemoveOrgan(entity, uid, organ);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBodyInit(EntityUid bodyId, BodyComponent body, ComponentInit args)
|
private void OnBodyInit(EntityUid bodyId, BodyComponent body, ComponentInit args)
|
||||||
|
|||||||
@@ -29,31 +29,28 @@ public partial class SharedBodySystem
|
|||||||
var entity = args.Entity;
|
var entity = args.Entity;
|
||||||
var slotId = args.Container.ID;
|
var slotId = args.Container.ID;
|
||||||
|
|
||||||
if (component.Body != null)
|
if (component.Body == null)
|
||||||
{
|
return;
|
||||||
if (TryComp(entity, out BodyPartComponent? childPart))
|
|
||||||
{
|
|
||||||
AddPart(component.Body.Value, entity, slotId, childPart);
|
|
||||||
RecursiveBodyUpdate(entity, component.Body.Value, childPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TryComp(entity, out OrganComponent? organ))
|
if (TryComp(entity, out BodyPartComponent? childPart))
|
||||||
{
|
{
|
||||||
AddOrgan(entity, component.Body.Value, uid, organ);
|
AddPart(component.Body.Value, entity, slotId, childPart);
|
||||||
}
|
RecursiveBodyUpdate(entity, component.Body.Value, childPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TryComp(entity, out OrganComponent? organ))
|
||||||
|
AddOrgan(entity, component.Body.Value, uid, organ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBodyPartRemoved(EntityUid uid, BodyPartComponent component, EntRemovedFromContainerMessage args)
|
private void OnBodyPartRemoved(EntityUid uid, BodyPartComponent component, EntRemovedFromContainerMessage args)
|
||||||
{
|
{
|
||||||
// TODO: lifestage shenanigans
|
|
||||||
if (TerminatingOrDeleted(uid))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Body part removed from another body part.
|
// Body part removed from another body part.
|
||||||
var entity = args.Entity;
|
var entity = args.Entity;
|
||||||
var slotId = args.Container.ID;
|
var slotId = args.Container.ID;
|
||||||
|
|
||||||
|
DebugTools.Assert(!TryComp(entity, out BodyPartComponent? b) || b.Body == component.Body);
|
||||||
|
DebugTools.Assert(!TryComp(entity, out OrganComponent? o) || o.Body == component.Body);
|
||||||
|
|
||||||
if (TryComp(entity, out BodyPartComponent? childPart) && childPart.Body != null)
|
if (TryComp(entity, out BodyPartComponent? childPart) && childPart.Body != null)
|
||||||
{
|
{
|
||||||
RemovePart(childPart.Body.Value, entity, slotId, childPart);
|
RemovePart(childPart.Body.Value, entity, slotId, childPart);
|
||||||
@@ -61,49 +58,44 @@ public partial class SharedBodySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TryComp(entity, out OrganComponent? organ))
|
if (TryComp(entity, out OrganComponent? organ))
|
||||||
{
|
|
||||||
RemoveOrgan(entity, uid, organ);
|
RemoveOrgan(entity, uid, organ);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecursiveBodyUpdate(EntityUid uid, EntityUid? bodyUid, BodyPartComponent component)
|
private void RecursiveBodyUpdate(EntityUid uid, EntityUid? bodyUid, BodyPartComponent component)
|
||||||
{
|
{
|
||||||
foreach (var children in GetBodyPartChildren(uid, component))
|
component.Body = bodyUid;
|
||||||
|
Dirty(uid, component);
|
||||||
|
|
||||||
|
foreach (var slotId in component.Organs.Keys)
|
||||||
{
|
{
|
||||||
if (children.Component.Body != bodyUid)
|
if (!Containers.TryGetContainer(uid, GetOrganContainerId(slotId), out var container))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var organ in container.ContainedEntities)
|
||||||
{
|
{
|
||||||
children.Component.Body = bodyUid;
|
if (!TryComp(organ, out OrganComponent? organComp))
|
||||||
Dirty(children.Id, children.Component);
|
continue;
|
||||||
|
|
||||||
foreach (var slotId in children.Component.Organs.Keys)
|
Dirty(organ, organComp);
|
||||||
{
|
|
||||||
var organContainerId = GetOrganContainerId(slotId);
|
|
||||||
|
|
||||||
if (!Containers.TryGetContainer(children.Id, organContainerId, out var container))
|
if (organComp.Body != null)
|
||||||
continue;
|
RaiseLocalEvent(organ, new RemovedFromPartInBodyEvent(organComp.Body.Value, uid));
|
||||||
|
|
||||||
foreach (var organ in container.ContainedEntities)
|
organComp.Body = bodyUid;
|
||||||
{
|
if (bodyUid != null)
|
||||||
if (TryComp(organ, out OrganComponent? organComp))
|
RaiseLocalEvent(organ, new AddedToPartInBodyEvent(bodyUid.Value, uid));
|
||||||
{
|
}
|
||||||
var oldBody = organComp.Body;
|
}
|
||||||
organComp.Body = bodyUid;
|
|
||||||
|
|
||||||
if (bodyUid != null)
|
foreach (var slotId in component.Children.Keys)
|
||||||
{
|
{
|
||||||
var ev = new AddedToPartInBodyEvent(bodyUid.Value, children.Id);
|
if (!Containers.TryGetContainer(uid, GetPartSlotContainerId(slotId), out var container))
|
||||||
RaiseLocalEvent(organ, ev);
|
continue;
|
||||||
}
|
|
||||||
else if (oldBody != null)
|
|
||||||
{
|
|
||||||
var ev = new RemovedFromPartInBodyEvent(oldBody.Value, children.Id);
|
|
||||||
RaiseLocalEvent(organ, ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
Dirty(organ, organComp);
|
foreach (var containedEnt in container.ContainedEntities)
|
||||||
}
|
{
|
||||||
}
|
if (TryComp(containedEnt, out BodyPartComponent? childPart))
|
||||||
}
|
RecursiveBodyUpdate(containedEnt, bodyUid, childPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user