ECS and cleanup body system, merge body templates and presets into body prototypes (#11991)

Co-authored-by: Jezithyr <Jezithyr@gmail.com>
This commit is contained in:
DrSmugleaf
2022-10-23 00:46:28 +02:00
committed by GitHub
parent 9a38736c3c
commit f323fb7644
140 changed files with 2478 additions and 2571 deletions

View File

@@ -1,6 +1,9 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.Body.Systems;
using Content.Shared.Administration;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -18,7 +21,7 @@ namespace Content.Server.Body.Commands
var player = shell.Player as IPlayerSession;
var entityManager = IoCManager.Resolve<IEntityManager>();
EntityUid entity;
EntityUid bodyId;
EntityUid partUid;
switch (args.Length)
@@ -42,7 +45,7 @@ namespace Content.Server.Body.Commands
return;
}
entity = player.AttachedEntity.Value;
bodyId = player.AttachedEntity.Value;
break;
case 2:
@@ -64,16 +67,16 @@ namespace Content.Server.Body.Commands
return;
}
entity = entityUid;
bodyId = entityUid;
break;
default:
shell.WriteLine(Help);
return;
}
if (!entityManager.TryGetComponent(entity, out SharedBodyComponent? body))
if (!entityManager.TryGetComponent(bodyId, out BodyComponent? body))
{
shell.WriteLine($"Entity {entityManager.GetComponent<MetaDataComponent>(entity).EntityName} with uid {entity} does not have a {nameof(SharedBodyComponent)} component.");
shell.WriteLine($"Entity {entityManager.GetComponent<MetaDataComponent>(bodyId).EntityName} with uid {bodyId} does not have a {nameof(BodyComponent)}.");
return;
}
@@ -83,19 +86,39 @@ namespace Content.Server.Body.Commands
return;
}
if (!entityManager.TryGetComponent(partUid, out SharedBodyPartComponent? part))
if (!entityManager.TryGetComponent(partUid, out BodyPartComponent? part))
{
shell.WriteLine($"Entity {entityManager.GetComponent<MetaDataComponent>(partUid).EntityName} with uid {args[0]} does not have a {nameof(SharedBodyPartComponent)} component.");
shell.WriteLine($"Entity {entityManager.GetComponent<MetaDataComponent>(partUid).EntityName} with uid {args[0]} does not have a {nameof(BodyPartComponent)}.");
return;
}
if (body.HasPart(part))
var bodySystem = entityManager.System<BodySystem>();
if (bodySystem.BodyHasChild(bodyId, partUid, body, part))
{
shell.WriteLine($"Body part {entityManager.GetComponent<MetaDataComponent>(partUid).EntityName} with uid {partUid} is already attached to entity {entityManager.GetComponent<MetaDataComponent>(entity).EntityName} with uid {entity}");
shell.WriteLine($"Body part {entityManager.GetComponent<MetaDataComponent>(partUid).EntityName} with uid {partUid} is already attached to entity {entityManager.GetComponent<MetaDataComponent>(bodyId).EntityName} with uid {bodyId}");
return;
}
body.SetPart($"AttachBodyPartVerb-{partUid}", part);
var slotId = $"AttachBodyPartVerb-{partUid}";
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (bodySystem.TryCreateBodyRootSlot(bodyId, slotId, out var rootSlot, body))
{
bodySystem.DropPart(partUid, part);
bodySystem.AttachPart(partUid, rootSlot, part);
}
else
{
var attachAt = bodySystem.GetBodyChildren(bodyId, body).First();
if (!bodySystem.TryCreatePartSlotAndAttach(attachAt.Id, slotId, partUid, attachAt.Component, part))
{
shell.WriteError($"Could not create slot {slotId} on entity {entityManager.ToPrettyString(bodyId)}");
return;
}
}
shell.WriteLine($"Attached part {entityManager.ToPrettyString(partUid)} to {entityManager.ToPrettyString(bodyId)}");
}
}
}