AddHandCommand uses EntityUid

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 11:34:40 +01:00
parent f025e5f0a8
commit 36e1d0707a

View File

@@ -32,8 +32,8 @@ namespace Content.Server.Body.Commands
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>(); var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
IEntity entity; EntityUid entity;
IEntity hand; EntityUid hand;
switch (args.Length) switch (args.Length)
{ {
@@ -45,28 +45,28 @@ namespace Content.Server.Body.Commands
return; return;
} }
if (player.AttachedEntity == null) if (player.AttachedEntityUid == null)
{ {
shell.WriteLine("You don't have an entity to add a hand to."); shell.WriteLine("You don't have an entity to add a hand to.");
return; return;
} }
entity = player.AttachedEntity; entity = player.AttachedEntityUid.Value;
hand = entityManager.SpawnEntity(DefaultHandPrototype, entity.Transform.Coordinates); hand = entityManager.SpawnEntity(DefaultHandPrototype, entityManager.GetComponent<TransformComponent>(entity).Coordinates).Uid;
break; break;
} }
case 1: case 1:
{ {
if (EntityUid.TryParse(args[0], out var uid)) if (EntityUid.TryParse(args[0], out var uid))
{ {
if (!entityManager.TryGetEntity(uid, out var parsedEntity)) if (!entityManager.EntityExists(uid))
{ {
shell.WriteLine($"No entity found with uid {uid}"); shell.WriteLine($"No entity found with uid {uid}");
return; return;
} }
entity = parsedEntity; entity = uid;
hand = entityManager.SpawnEntity(DefaultHandPrototype, entity.Transform.Coordinates); hand = entityManager.SpawnEntity(DefaultHandPrototype, entityManager.GetComponent<TransformComponent>(entity).Coordinates).Uid;
} }
else else
{ {
@@ -76,14 +76,14 @@ namespace Content.Server.Body.Commands
return; return;
} }
if (player.AttachedEntity == null) if (player.AttachedEntityUid == null)
{ {
shell.WriteLine("You don't have an entity to add a hand to."); shell.WriteLine("You don't have an entity to add a hand to.");
return; return;
} }
entity = player.AttachedEntity; entity = player.AttachedEntityUid.Value;
hand = entityManager.SpawnEntity(args[0], entity.Transform.Coordinates); hand = entityManager.SpawnEntity(args[0], entityManager.GetComponent<TransformComponent>(entity).Coordinates).Uid;
} }
break; break;
@@ -96,13 +96,13 @@ namespace Content.Server.Body.Commands
return; return;
} }
if (!entityManager.TryGetEntity(uid, out var parsedEntity)) if (!entityManager.EntityExists(uid))
{ {
shell.WriteLine($"No entity exists with uid {uid}."); shell.WriteLine($"No entity exists with uid {uid}.");
return; return;
} }
entity = parsedEntity; entity = uid;
if (!prototypeManager.HasIndex<EntityPrototype>(args[1])) if (!prototypeManager.HasIndex<EntityPrototype>(args[1]))
{ {
@@ -110,7 +110,7 @@ namespace Content.Server.Body.Commands
return; return;
} }
hand = entityManager.SpawnEntity(args[1], entity.Transform.Coordinates); hand = entityManager.SpawnEntity(args[1], entityManager.GetComponent<TransformComponent>(entity).Coordinates).Uid;
break; break;
} }
@@ -121,7 +121,7 @@ namespace Content.Server.Body.Commands
} }
} }
if (!entity.TryGetComponent(out SharedBodyComponent? body)) if (!entityManager.TryGetComponent(entity, out SharedBodyComponent? body))
{ {
var random = IoCManager.Resolve<IRobustRandom>(); 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." : ".")}";
@@ -130,7 +130,7 @@ namespace Content.Server.Body.Commands
return; return;
} }
if (!hand.TryGetComponent(out SharedBodyPartComponent? part)) if (!entityManager.TryGetComponent(hand, out SharedBodyPartComponent? part))
{ {
shell.WriteLine($"Hand entity {hand} does not have a {nameof(SharedBodyPartComponent)} component."); shell.WriteLine($"Hand entity {hand} does not have a {nameof(SharedBodyPartComponent)} component.");
return; return;
@@ -139,7 +139,7 @@ namespace Content.Server.Body.Commands
var slot = part.GetHashCode().ToString(); var slot = part.GetHashCode().ToString();
body.SetPart(slot, part); body.SetPart(slot, part);
shell.WriteLine($"Added hand to entity {entity.Name}"); shell.WriteLine($"Added hand to entity {entityManager.GetComponent<MetaDataComponent>(entity).EntityName}");
} }
} }
} }