Change all of body system to use entities and components (#2074)

* Early commit

* Early commit 2

* merging master broke my git

* does anyone even read these

* life is fleeting

* it just works

* this time passing integration tests

* Remove hashset yaml serialization for now

* You got a license for those nullables?

* No examine, no context menu, part and mechanism parenting and visibility

* Fix wrong brain sprite state

* Removing layers was a mistake

* just tear body system a new one and see if it still breathes

* Remove redundant code

* Add that comment back

* Separate damage and body, component states, stomach rework

* Add containers for body parts

* Bring layers back pls

* Fix parts magically changing color

* Reimplement sprite layer visibility

* Fix tests

* Add leg test

* Active legs is gone

Crab rave

* Merge fixes, rename DamageState to CurrentState

* Remove IShowContextMenu and ICanExamine
This commit is contained in:
DrSmugleaf
2020-10-10 15:25:13 +02:00
committed by GitHub
parent 73c730d06c
commit dd385a0511
165 changed files with 4232 additions and 4650 deletions

View File

@@ -0,0 +1,59 @@
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Part;
using Content.Shared.GameObjects.Components.Rotation;
using Content.Shared.GameObjects.EntitySystems;
using NUnit.Framework;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests.Body
{
[TestFixture]
[TestOf(typeof(SharedBodyComponent))]
[TestOf(typeof(BodyComponent))]
public class LegTest : ContentIntegrationTest
{
[Test]
public async Task RemoveLegsFallTest()
{
var server = StartServerDummyTicker();
AppearanceComponent appearance = null;
await server.WaitAssertion(() =>
{
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = new MapId(0);
mapManager.CreateNewMapEntity(mapId);
var entityManager = IoCManager.Resolve<IEntityManager>();
var human = entityManager.SpawnEntity("HumanMob_Content", MapCoordinates.Nullspace);
Assert.That(human.TryGetBody(out var body));
Assert.That(human.TryGetComponent(out appearance));
Assert.That(!appearance.TryGetData(RotationVisuals.RotationState, out RotationState _));
var legs = body.GetPartsOfType(BodyPartType.Leg);
foreach (var leg in legs)
{
body.RemovePart(leg, false);
}
});
await server.WaitAssertion(() =>
{
Assert.That(appearance.TryGetData(RotationVisuals.RotationState, out RotationState state));
Assert.That(state, Is.EqualTo(RotationState.Horizontal));
});
}
}
}

View File

@@ -1,10 +1,12 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.Body.Behavior;
using Content.Server.GameObjects.Components.Body.Circulatory;
using Content.Server.GameObjects.Components.Body.Respiratory;
using Content.Server.GameObjects.Components.Metabolism;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.Components.Body.Mechanism;
using NUnit.Framework;
using Robust.Server.Interfaces.Maps;
using Robust.Shared.Interfaces.GameObjects;
@@ -13,10 +15,10 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests
namespace Content.IntegrationTests.Tests.Body
{
[TestFixture]
[TestOf(typeof(LungComponent))]
[TestOf(typeof(LungBehaviorComponent))]
public class LungTest : ContentIntegrationTest
{
[Test]
@@ -34,7 +36,8 @@ namespace Content.IntegrationTests.Tests
var human = entityManager.SpawnEntity("HumanMob_Content", MapCoordinates.Nullspace);
Assert.True(human.TryGetComponent(out LungComponent lung));
Assert.True(human.TryGetMechanismBehaviors(out List<LungBehaviorComponent> lungs));
Assert.That(lungs.Count, Is.EqualTo(1));
Assert.True(human.TryGetComponent(out BloodstreamComponent bloodstream));
var gas = new GasMixture(1);
@@ -46,6 +49,7 @@ namespace Content.IntegrationTests.Tests
gas.AdjustMoles(Gas.Oxygen, originalOxygen);
gas.AdjustMoles(Gas.Nitrogen, originalNitrogen);
var lung = lungs[0];
lung.Inhale(1, gas);
var lungOxygen = originalOxygen * breathedPercentage;
@@ -114,7 +118,6 @@ namespace Content.IntegrationTests.Tests
MapId mapId;
IMapGrid grid = null;
LungComponent lung = null;
MetabolismComponent metabolism = null;
IEntity human = null;
@@ -134,7 +137,7 @@ namespace Content.IntegrationTests.Tests
var coordinates = new EntityCoordinates(grid.GridEntityId, center);
human = entityManager.SpawnEntity("HumanMob_Content", coordinates);
Assert.True(human.TryGetComponent(out lung));
Assert.True(human.HasMechanismBehavior<LungBehaviorComponent>());
Assert.True(human.TryGetComponent(out metabolism));
Assert.False(metabolism.Suffocating);
});

View File

@@ -4,6 +4,8 @@ using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Strap;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Part;
using Content.Shared.GameObjects.Components.Buckle;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.EntitySystems;
@@ -182,7 +184,7 @@ namespace Content.IntegrationTests.Tests
BuckleComponent buckle = null;
StrapComponent strap = null;
HandsComponent hands = null;
IDamageableComponent humanDamageable = null;
IBody body = null;
server.Assert(() =>
{
@@ -208,7 +210,7 @@ namespace Content.IntegrationTests.Tests
Assert.True(human.TryGetComponent(out buckle));
Assert.True(chair.TryGetComponent(out strap));
Assert.True(human.TryGetComponent(out hands));
Assert.True(human.TryGetComponent(out humanDamageable));
Assert.True(human.TryGetBody(out body));
// Buckle
Assert.True(buckle.TryBuckle(human, chair));
@@ -239,8 +241,13 @@ namespace Content.IntegrationTests.Tests
Assert.NotNull(hands.GetItem(slot));
}
// Banish our guy into the shadow realm
humanDamageable.ChangeDamage(DamageClass.Brute, 1000000, true);
var legs = body.GetPartsOfType(BodyPartType.Leg);
// Break our guy's kneecaps
foreach (var leg in legs)
{
body.RemovePart(leg, false);
}
});
server.RunTicks(10);

View File

@@ -1,20 +1,17 @@
#nullable enable
using System.Linq;
using System.Threading.Tasks;
using Content.Client.GameObjects.Components.Items;
using Content.Server.Body;
using Content.Server.GameObjects.Components.ActionBlocking;
using Content.Server.GameObjects.Components.Body;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Shared.Body.Part;
using Content.Shared.GameObjects.Components.Body;
using NUnit.Framework;
using Robust.Server.Interfaces.Console;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
{
@@ -36,7 +33,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
HandcuffComponent handcuff;
CuffableComponent cuffed;
IHandsComponent hands;
BodyManagerComponent body;
IBody body;
server.Assert(() =>
{
@@ -56,7 +53,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
// Test for components existing
Assert.True(human.TryGetComponent(out cuffed!), $"Human has no {nameof(CuffableComponent)}");
Assert.True(human.TryGetComponent(out hands!), $"Human has no {nameof(HandsComponent)}");
Assert.True(human.TryGetComponent(out body!), $"Human has no {nameof(BodyManagerComponent)}");
Assert.True(human.TryGetBody(out body!), $"Human has no {nameof(IBody)}");
Assert.True(cuffs.TryGetComponent(out handcuff!), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.True(cables.TryGetComponent(out cableHandcuff!), $"Cablecuff has no {nameof(HandcuffComponent)}");
@@ -65,8 +62,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
Assert.True(cuffed.CuffedHandCount > 0, "Handcuffing a player did not result in their hands being cuffed");
// Test to ensure a player with 4 hands will still only have 2 hands cuffed
AddHand(body);
AddHand(body);
AddHand(cuffed.Owner);
AddHand(cuffed.Owner);
Assert.True(cuffed.CuffedHandCount == 2 && hands.Hands.Count() == 4, "Player doesn't have correct amount of hands cuffed");
// Test to give a player with 4 hands 2 sets of cuffs
@@ -78,16 +75,10 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
await server.WaitIdleAsync();
}
private void AddHand(BodyManagerComponent body)
private void AddHand(IEntity to)
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
prototypeManager.TryIndex("bodyPart.LHand.BasicHuman", out BodyPartPrototype prototype);
var part = new BodyPart(prototype);
var slot = part.GetHashCode().ToString();
body.Template.Slots.Add(slot, BodyPartType.Hand);
body.TryAddPart(slot, part, true);
var shell = IoCManager.Resolve<IConsoleShell>();
shell.ExecuteCommand($"addhand {to.Uid}");
}
}
}

View File

@@ -43,8 +43,8 @@ namespace Content.IntegrationTests.Tests
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(1000, 1000)).ToList();
Assert.That(entities.Count, Is.EqualTo(0));
var entityOne = entityManager.SpawnEntity("HumanMob_Content", new EntityCoordinates(gridOne.GridEntityId, Vector2.Zero));
entityManager.SpawnEntity("HumanMob_Content", new EntityCoordinates(gridOne.GridEntityId, Vector2.One));
var entityOne = entityManager.SpawnEntity("Food4NoRaisins", new EntityCoordinates(gridOne.GridEntityId, Vector2.Zero));
entityManager.SpawnEntity("Food4NoRaisins", new EntityCoordinates(gridOne.GridEntityId, Vector2.One));
var entityTiles = tileLookup.GetIndices(entityOne);
Assert.That(entityTiles.Count, Is.EqualTo(2));