Skip to content

Commit

Permalink
Clean up server body code
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6273 committed Feb 19, 2024
1 parent 36364b1 commit 2c6d8a8
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 286 deletions.
86 changes: 41 additions & 45 deletions Content.Server/Body/Commands/AddHandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
switch (args.Length)
{
case 0:
{
if (player == null)
{
shell.WriteLine("Only a player can run this command without arguments.");
Expand All @@ -50,71 +49,68 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
entity = player.AttachedEntity.Value;
hand = _entManager.SpawnEntity(DefaultHandPrototype, _entManager.GetComponent<TransformComponent>(entity).Coordinates);
break;
}
case 1:
{
if (NetEntity.TryParse(args[0], out var uidNet) && _entManager.TryGetEntity(uidNet, out var uid))
{
if (!_entManager.EntityExists(uid))
if (NetEntity.TryParse(args[0], out var uidNet) && _entManager.TryGetEntity(uidNet, out var uid))
{
shell.WriteLine($"No entity found with uid {uid}");
return;
if (!_entManager.EntityExists(uid))
{
shell.WriteLine($"No entity found with uid {uid}");
return;
}

entity = uid.Value;
hand = _entManager.SpawnEntity(DefaultHandPrototype, _entManager.GetComponent<TransformComponent>(entity).Coordinates);
}
else
{
if (player == null)
{
shell.WriteLine("You must specify an entity to add a hand to when using this command from the server terminal.");
return;
}

if (player.AttachedEntity == null)
{
shell.WriteLine("You don't have an entity to add a hand to.");
return;
}

entity = player.AttachedEntity.Value;
hand = _entManager.SpawnEntity(args[0], _entManager.GetComponent<TransformComponent>(entity).Coordinates);
}

entity = uid.Value;
hand = _entManager.SpawnEntity(DefaultHandPrototype, _entManager.GetComponent<TransformComponent>(entity).Coordinates);
break;
}
else
case 2:
{
if (player == null)
if (!NetEntity.TryParse(args[0], out var netEnt) || !_entManager.TryGetEntity(netEnt, out var uid))
{
shell.WriteLine("You must specify an entity to add a hand to when using this command from the server terminal.");
shell.WriteLine($"{args[0]} is not a valid entity uid.");
return;
}

if (player.AttachedEntity == null)
if (!_entManager.EntityExists(uid))
{
shell.WriteLine("You don't have an entity to add a hand to.");
shell.WriteLine($"No entity exists with uid {uid}.");
return;
}

entity = player.AttachedEntity.Value;
hand = _entManager.SpawnEntity(args[0], _entManager.GetComponent<TransformComponent>(entity).Coordinates);
}

break;
}
case 2:
{
if (!NetEntity.TryParse(args[0], out var netEnt) || !_entManager.TryGetEntity(netEnt, out var uid))
{
shell.WriteLine($"{args[0]} is not a valid entity uid.");
return;
}
entity = uid.Value;

if (!_entManager.EntityExists(uid))
{
shell.WriteLine($"No entity exists with uid {uid}.");
return;
}
if (!_protoManager.HasIndex<EntityPrototype>(args[1]))
{
shell.WriteLine($"No hand entity exists with id {args[1]}.");
return;
}

entity = uid.Value;
hand = _entManager.SpawnEntity(args[1], _entManager.GetComponent<TransformComponent>(entity).Coordinates);

if (!_protoManager.HasIndex<EntityPrototype>(args[1]))
{
shell.WriteLine($"No hand entity exists with id {args[1]}.");
return;
break;
}

hand = _entManager.SpawnEntity(args[1], _entManager.GetComponent<TransformComponent>(entity).Coordinates);

break;
}
default:
{
shell.WriteLine(Help);
return;
}
}

if (!_entManager.TryGetComponent(entity, out BodyComponent? body) || body.RootContainer.ContainedEntity == null)
Expand All @@ -139,7 +135,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)

var slotId = part.GetHashCode().ToString();

if (!bodySystem.TryCreatePartSlotAndAttach(attachAt.Id, slotId, hand, BodyPartType.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;
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Body/Commands/AttachBodyPartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (body.RootContainer.ContainedEntity != null)
{
bodySystem.AttachPartToRoot(bodyId,partUid.Value, body ,part);
bodySystem.AttachPartToRoot(bodyId, partUid.Value, body, part);
}
else
{
var (rootPartId,rootPart) = bodySystem.GetRootPartOrNull(bodyId, body)!.Value;
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)}");
Expand Down
5 changes: 2 additions & 3 deletions Content.Server/Body/Components/InternalsComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading;
namespace Content.Server.Body.Components
{
/// <summary>
Expand All @@ -14,10 +13,10 @@ public sealed partial class InternalsComponent : Component
public EntityUid? BreathToolEntity;

/// <summary>
/// Toggle Internals delay (seconds) when the target is not you.
/// Toggle Internals delay when the target is not you.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float Delay = 3;
public TimeSpan Delay = TimeSpan.FromSeconds(3);
}
}
Loading

0 comments on commit 2c6d8a8

Please sign in to comment.