Refactoring body system to use containers and general body cleanup (#20202)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -118,7 +118,7 @@ namespace Content.Server.Body.Commands
|
||||
}
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent(entity, out BodyComponent? body) || body.Root == null)
|
||||
if (!_entManager.TryGetComponent(entity, out BodyComponent? body) || body.RootContainer.ContainedEntity == null)
|
||||
{
|
||||
var text = $"You have no body{(_random.Prob(0.2f) ? " and you must scream." : ".")}";
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Content.Server.Body.Commands
|
||||
|
||||
var slotId = part.GetHashCode().ToString();
|
||||
|
||||
if (!bodySystem.TryCreatePartSlotAndAttach(attachAt.Id, slotId, hand, attachAt.Component, part))
|
||||
if (!bodySystem.TryCreatePartSlotAndAttach(attachAt.Id, slotId, hand, BodyPartType.Hand,attachAt.Component, part))
|
||||
{
|
||||
shell.WriteError($"Couldn't create a slot with id {slotId} on entity {_entManager.ToPrettyString(entity)}");
|
||||
return;
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Content.Server.Body.Commands
|
||||
}
|
||||
|
||||
var bodySystem = _entManager.System<BodySystem>();
|
||||
if (bodySystem.BodyHasChild(bodyId, partUid, body, part))
|
||||
if (bodySystem.BodyHasChild(bodyId, partUid.Value, body, part))
|
||||
{
|
||||
shell.WriteLine($"Body part {_entManager.GetComponent<MetaDataComponent>(partUid.Value).EntityName} with uid {partUid} is already attached to entity {_entManager.GetComponent<MetaDataComponent>(bodyId).EntityName} with uid {bodyId}");
|
||||
return;
|
||||
@@ -103,16 +103,14 @@ namespace Content.Server.Body.Commands
|
||||
var slotId = $"AttachBodyPartVerb-{partUid}";
|
||||
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
if (bodySystem.TryCreateBodyRootSlot(bodyId, slotId, out var rootSlot, body))
|
||||
if (body.RootContainer.ContainedEntity != null)
|
||||
{
|
||||
bodySystem.DropPart(partUid, part);
|
||||
bodySystem.AttachPart(partUid, rootSlot, part);
|
||||
bodySystem.AttachPartToRoot(bodyId,partUid.Value, body ,part);
|
||||
}
|
||||
else
|
||||
{
|
||||
var attachAt = bodySystem.GetBodyChildren(bodyId, body).First();
|
||||
|
||||
if (!bodySystem.TryCreatePartSlotAndAttach(attachAt.Id, slotId, partUid, attachAt.Component, part))
|
||||
var (rootPartId,rootPart) = bodySystem.GetRootPartOrNull(bodyId, body)!.Value;
|
||||
if (!bodySystem.TryCreatePartSlotAndAttach(rootPartId, slotId, partUid.Value, part.PartType, rootPart, part))
|
||||
{
|
||||
shell.WriteError($"Could not create slot {slotId} on entity {_entManager.ToPrettyString(bodyId)}");
|
||||
return;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Content.Server.Body.Commands
|
||||
{
|
||||
if (fac.GetComponentName(organ.Component.GetType()).ToLowerInvariant() == mechanismName)
|
||||
{
|
||||
bodySystem.DeleteOrgan(organ.Id, organ.Component);
|
||||
entityManager.QueueDeleteEntity(organ.Id);
|
||||
shell.WriteLine($"Mechanism with name {mechanismName} has been destroyed.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,11 @@ using Robust.Shared.Random;
|
||||
namespace Content.Server.Body.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
sealed class RemoveHandCommand : IConsoleCommand
|
||||
public sealed class RemoveHandCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public string Command => "removehand";
|
||||
public string Description => "Removes a hand from your entity.";
|
||||
public string Help => $"Usage: {Command}";
|
||||
@@ -32,18 +35,16 @@ namespace Content.Server.Body.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entityManager.TryGetComponent(player.AttachedEntity, out BodyComponent? body))
|
||||
if (!_entManager.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." : ".")}";
|
||||
var text = $"You have no body{(_random.Prob(0.2f) ? " and you must scream." : ".")}";
|
||||
|
||||
shell.WriteLine(text);
|
||||
return;
|
||||
}
|
||||
|
||||
var bodySystem = entityManager.System<BodySystem>();
|
||||
var hand = bodySystem.GetBodyChildrenOfType(player.AttachedEntity, BodyPartType.Hand, body).FirstOrDefault();
|
||||
var bodySystem = _entManager.System<BodySystem>();
|
||||
var hand = bodySystem.GetBodyChildrenOfType(player.AttachedEntity.Value, BodyPartType.Hand, body).FirstOrDefault();
|
||||
|
||||
if (hand == default)
|
||||
{
|
||||
@@ -51,7 +52,7 @@ namespace Content.Server.Body.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
bodySystem.DropPart(hand.Id, hand.Component);
|
||||
_entManager.System<SharedTransformSystem>().AttachToGridOrMap(hand.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user