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:
@@ -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;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -118,7 +121,7 @@ namespace Content.Server.Body.Commands
|
||||
}
|
||||
}
|
||||
|
||||
if (!entityManager.TryGetComponent(entity, out SharedBodyComponent? body))
|
||||
if (!entityManager.TryGetComponent(entity, out BodyComponent? body) || body.Root == null)
|
||||
{
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";
|
||||
@@ -127,14 +130,25 @@ namespace Content.Server.Body.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entityManager.TryGetComponent(hand, out SharedBodyPartComponent? part))
|
||||
if (!entityManager.TryGetComponent(hand, out BodyPartComponent? part))
|
||||
{
|
||||
shell.WriteLine($"Hand entity {hand} does not have a {nameof(SharedBodyPartComponent)} component.");
|
||||
shell.WriteLine($"Hand entity {hand} does not have a {nameof(BodyPartComponent)} component.");
|
||||
return;
|
||||
}
|
||||
|
||||
var slot = part.GetHashCode().ToString();
|
||||
body.SetPart(slot, part);
|
||||
var bodySystem = entityManager.System<BodySystem>();
|
||||
|
||||
var attachAt = bodySystem.GetBodyChildrenOfType(entity, BodyPartType.Arm, body).FirstOrDefault();
|
||||
if (attachAt == default)
|
||||
attachAt = bodySystem.GetBodyChildren(entity, body).First();
|
||||
|
||||
var slotId = part.GetHashCode().ToString();
|
||||
|
||||
if (!bodySystem.TryCreatePartSlotAndAttach(attachAt.Id, slotId, hand, attachAt.Component, part))
|
||||
{
|
||||
shell.WriteError($"Couldn't create a slot with id {slotId} on entity {entityManager.ToPrettyString(entity)}");
|
||||
return;
|
||||
}
|
||||
|
||||
shell.WriteLine($"Added hand to entity {entityManager.GetComponent<MetaDataComponent>(entity).EntityName}");
|
||||
}
|
||||
|
||||
@@ -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)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Server.Player;
|
||||
@@ -35,7 +36,8 @@ namespace Content.Server.Body.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attached, out SharedBodyComponent? body))
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entityManager.TryGetComponent(attached, out BodyComponent? body))
|
||||
{
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";
|
||||
@@ -45,13 +47,13 @@ namespace Content.Server.Body.Commands
|
||||
}
|
||||
|
||||
var mechanismName = string.Join(" ", args).ToLowerInvariant();
|
||||
var bodySystem = entityManager.System<BodySystem>();
|
||||
|
||||
foreach (var (part, _) in body.Parts)
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
foreach (var organ in bodySystem.GetBodyOrgans(body.Owner, body))
|
||||
{
|
||||
if (mechanism.Name.ToLowerInvariant() == mechanismName)
|
||||
if (organ.Component.Name.ToLowerInvariant() == mechanismName)
|
||||
{
|
||||
part.DeleteMechanism(mechanism);
|
||||
bodySystem.DeleteOrgan(organ.Id, organ.Component);
|
||||
shell.WriteLine($"Mechanism with name {mechanismName} has been destroyed.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -31,7 +32,8 @@ namespace Content.Server.Body.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(player.AttachedEntity, out SharedBodyComponent? body))
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entityManager.TryGetComponent(player.AttachedEntity, out BodyComponent? body))
|
||||
{
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";
|
||||
@@ -40,15 +42,16 @@ namespace Content.Server.Body.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var hand = body.GetPartsOfType(BodyPartType.Hand).FirstOrDefault();
|
||||
var bodySystem = entityManager.System<BodySystem>();
|
||||
var hand = bodySystem.GetBodyChildrenOfType(player.AttachedEntity, BodyPartType.Hand, body).FirstOrDefault();
|
||||
|
||||
if (hand == null)
|
||||
if (hand == default)
|
||||
{
|
||||
shell.WriteLine("You have no hands.");
|
||||
}
|
||||
else
|
||||
{
|
||||
body.RemovePart(hand);
|
||||
bodySystem.DropPart(hand.Id, hand.Component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user