Can't butcher objects inside containers. (this time, the pr contains the code 🙃) (#11685)

This commit is contained in:
Mervill
2022-10-03 18:42:04 -07:00
committed by GitHub
parent 26b413d24b
commit 020b2fae00
2 changed files with 20 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
using Content.Server.DoAfter;
using Content.Server.Kitchen.Components;
using Content.Server.MobState;
using Content.Shared.Body.Components;
using Content.Shared.Interaction;
using Content.Shared.MobState.Components;
@@ -7,6 +8,7 @@ using Content.Shared.Nutrition.Components;
using Content.Shared.Popups;
using Content.Shared.Storage;
using Content.Shared.Verbs;
using Robust.Server.Containers;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -16,6 +18,8 @@ public sealed class SharpSystem : EntitySystem
{
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
public override void Initialize()
@@ -48,7 +52,7 @@ public sealed class SharpSystem : EntitySystem
if (butcher.Type != ButcheringType.Knife)
return;
if (TryComp<MobStateComponent>(target, out var mobState) && !mobState.IsDead())
if (TryComp<MobStateComponent>(target, out var mobState) && !_mobStateSystem.IsDead(target, mobState))
return;
if (!sharp.Butchering.Add(target))
@@ -77,6 +81,9 @@ public sealed class SharpSystem : EntitySystem
if (!TryComp<SharpComponent>(ev.Sharp, out var sharp))
return;
if (_containerSystem.IsEntityInContainer(ev.Entity))
return;
sharp.Butchering.Remove(ev.Entity);
var spawnEntities = EntitySpawnCollection.GetSpawns(butcher.SpawnedEntities, _robustRandom);
@@ -124,18 +131,23 @@ public sealed class SharpSystem : EntitySystem
bool disabled = false;
string? message = null;
if (TryComp<MobStateComponent>(uid, out var state) && !state.IsDead())
{
disabled = true;
message = Loc.GetString("butcherable-mob-isnt-dead");
}
if (args.Using is null || !HasComp<SharpComponent>(args.Using))
{
disabled = true;
message = Loc.GetString("butcherable-need-knife",
("target", uid));
}
else if (_containerSystem.IsEntityInContainer(uid))
{
message = Loc.GetString("butcherable-not-in-container",
("target", uid));
disabled = true;
}
else if (TryComp<MobStateComponent>(uid, out var state) && !_mobStateSystem.IsDead(uid, state))
{
disabled = true;
message = Loc.GetString("butcherable-mob-isnt-dead");
}
InteractionVerb verb = new()
{