Fix addhand command (#1519)

This commit is contained in:
DrSmugleaf
2020-07-28 15:38:23 +02:00
committed by GitHub
parent c57b1c2914
commit 00d5effcb8
2 changed files with 25 additions and 5 deletions

View File

@@ -139,7 +139,11 @@ namespace Content.Client.GameObjects.Components.Items
if (entity == null)
{
_sprite.LayerSetVisible($"hand-{name}", false);
if (_sprite.LayerMapTryGet($"hand-{name}", out var layer))
{
_sprite.LayerSetVisible(layer, false);
}
return;
}

View File

@@ -8,9 +8,11 @@ using Content.Shared.BodySystem;
using Content.Shared.Jobs;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server.GameTicking
@@ -335,7 +337,7 @@ namespace Content.Server.GameTicking
{
if (player == null)
{
shell.SendText(player, "Only a player can run this command.");
shell.SendText((IPlayerSession) null, "Only a player can run this command.");
return;
}
@@ -345,9 +347,23 @@ namespace Content.Server.GameTicking
return;
}
var manager = player.AttachedEntity.GetComponent<BodyManagerComponent>();
var hand = manager.PartDictionary.First(x => x.Key == string.Join(" ", args));
manager.InstallBodyPart(hand.Value, hand.Key + new Random());
if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent body))
{
var random = IoCManager.Resolve<IRobustRandom>();
var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";
shell.SendText(player, text);
return;
}
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
prototypeManager.TryIndex("bodyPart.Hand.BasicHuman", out BodyPartPrototype prototype);
var part = new BodyPart(prototype);
var slot = part.GetHashCode().ToString();
body.Template.Slots.Add(slot, BodyPartType.Hand);
body.InstallBodyPart(part, slot);
}
}