Add a check for item size in the microwave system (#24026)

* Add a check for item size in the microwave system

* DataField suggestion

* Merge TryComp with HasComp

* Add datafield changeability for admins

(cherry picked from commit 562d7b4b82a49001179c1252064c8610174f8716)
This commit is contained in:
degradka
2024-01-14 00:11:09 +03:00
committed by Debug
parent a57d78aff8
commit e449d0787d
3 changed files with 17 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
using Content.Shared.Construction.Prototypes;
using Content.Shared.DeviceLinking;
using Content.Shared.Item;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
@@ -73,6 +74,9 @@ namespace Content.Server.Kitchen.Components
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int Capacity = 10;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public ProtoId<ItemSizePrototype> MaxItemSize = "Normal";
}
public sealed class BeingMicrowavedEvent : HandledEntityEventArgs

View File

@@ -51,6 +51,7 @@ namespace Content.Server.Kitchen.EntitySystems
[Dependency] private readonly TemperatureSystem _temperature = default!;
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
[Dependency] private readonly HandsSystem _handsSystem = default!;
[Dependency] private readonly SharedItemSystem _item = default!;
public override void Initialize()
{
@@ -282,8 +283,18 @@ namespace Content.Server.Kitchen.EntitySystems
return;
}
if (!HasComp<ItemComponent>(args.Used))
if (TryComp<ItemComponent>(args.Used, out var item))
{
// check if size of an item you're trying to put in is too big
if (_item.GetSizePrototype(item.Size) > _item.GetSizePrototype(ent.Comp.MaxItemSize))
{
_popupSystem.PopupEntity(Loc.GetString("microwave-component-interact-item-too-big", ("item", args.Used)), ent, args.User);
return;
}
}
else
{
// check if thing you're trying to put in isn't an item
_popupSystem.PopupEntity(Loc.GetString("microwave-component-interact-using-transfer-fail"), ent, args.User);
return;
}

View File

@@ -11,6 +11,7 @@ microwave-component-suicide-multi-head-message = You cook your heads!
microwave-component-suicide-message = You cook your head!
microwave-component-upgrade-cook-time = cook time
microwave-component-interact-full = It's full.
microwave-component-interact-item-too-big = { CAPITALIZE(THE($item)) } is too big to fit in the microwave!
## Bound UI