diff --git a/Content.Server/Backmen/Arrivals/ArrivalsProtectSystem.cs b/Content.Server/Backmen/Arrivals/ArrivalsProtectSystem.cs index ce246953466..907f56202b4 100644 --- a/Content.Server/Backmen/Arrivals/ArrivalsProtectSystem.cs +++ b/Content.Server/Backmen/Arrivals/ArrivalsProtectSystem.cs @@ -101,7 +101,7 @@ private void OnBuildAttemptEvent(BuildAttemptEvent ev) return; } - if (HasComp(grid.Value)) + if (ArrivalsProtectGridQuery.HasComp(grid.Value)) { ev.Cancel(); } diff --git a/Content.Shared/Backmen/Arrivals/FlatPackUserAttemptUseEvent.cs b/Content.Shared/Backmen/Arrivals/FlatPackUserAttemptUseEvent.cs new file mode 100644 index 00000000000..a2dbc0ac18c --- /dev/null +++ b/Content.Shared/Backmen/Arrivals/FlatPackUserAttemptUseEvent.cs @@ -0,0 +1,13 @@ +using Robust.Shared.Map; +using Robust.Shared.Prototypes; + +namespace Content.Shared.Backmen.Arrivals; + +[ByRefEvent] +public struct FlatPackUserAttemptUseEvent(EntityUid user, EntProtoId? itemToSpawn, EntityCoordinates coords) +{ + public readonly EntityUid User = user; + public readonly EntProtoId? ItemToSpawn = itemToSpawn; + public readonly EntityCoordinates Coords = coords; + public bool Cancelled = false; +} diff --git a/Content.Shared/Backmen/Arrivals/SharedArrivalsProtectSystem.cs b/Content.Shared/Backmen/Arrivals/SharedArrivalsProtectSystem.cs index 96eedfeff17..8efa68fd0e5 100644 --- a/Content.Shared/Backmen/Arrivals/SharedArrivalsProtectSystem.cs +++ b/Content.Shared/Backmen/Arrivals/SharedArrivalsProtectSystem.cs @@ -4,13 +4,22 @@ namespace Content.Shared.Backmen.Arrivals; public abstract class SharedArrivalsProtectSystem : EntitySystem { + protected EntityQuery ArrivalsProtectGridQuery; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnTryUse); + SubscribeLocalEvent(OnTryUnpack); + ArrivalsProtectGridQuery = GetEntityQuery(); } + private void OnTryUnpack(Entity ent, ref FlatPackUserAttemptUseEvent args) + { + args.Cancelled = true; + } + + private void OnTryUse(ref ToolUserAttemptUseEvent msg) { if (msg.Target == null) @@ -21,7 +30,7 @@ private void OnTryUse(ref ToolUserAttemptUseEvent msg) var pos = Transform(msg.Target!.Value); - if (pos.GridUid == null || !HasComp(pos.GridUid)) + if (pos.GridUid == null || !ArrivalsProtectGridQuery.HasComp(pos.GridUid)) { return; } diff --git a/Content.Shared/Construction/SharedFlatpackSystem.cs b/Content.Shared/Construction/SharedFlatpackSystem.cs index a83948b1674..d4a2a197eb6 100644 --- a/Content.Shared/Construction/SharedFlatpackSystem.cs +++ b/Content.Shared/Construction/SharedFlatpackSystem.cs @@ -90,6 +90,27 @@ private void OnFlatpackInteractUsing(Entity ent, ref Interact return; } + // start-backmen: protection system + var ev = new Backmen.Arrivals.FlatPackUserAttemptUseEvent(args.User, comp.Entity, coords); + if (xform.GridUid is { } gridUid) + { + RaiseLocalEvent(gridUid, ref ev); + if (ev.Cancelled) + { + if (_net.IsServer) + _popup.PopupEntity(Loc.GetString("flatpack-unpack-grid-error"), uid, args.User); + return; + } + RaiseLocalEvent(args.User, ref ev); + if (ev.Cancelled) + { + if (_net.IsServer) + _popup.PopupEntity(Loc.GetString("flatpack-unpack-user-error"), uid, args.User); + return; + } + } + // end-backmen: protection system + if (_net.IsServer) { var spawn = Spawn(comp.Entity, _map.GridTileToLocal(grid, gridComp, buildPos)); diff --git a/Resources/Locale/ru-RU/construction/components/flatpack.ftl b/Resources/Locale/ru-RU/construction/components/flatpack.ftl index 8520833ea8d..be150ba26fc 100644 --- a/Resources/Locale/ru-RU/construction/components/flatpack.ftl +++ b/Resources/Locale/ru-RU/construction/components/flatpack.ftl @@ -9,3 +9,7 @@ flatpacker-ui-cost-label = Стоимость запаковки flatpacker-ui-no-board-label = Отсутствует машинная плата! flatpacker-ui-insert-board = Для начала вставьте машинную плату. flatpacker-ui-pack-button = Упаковать + +# backmen +flatpack-unpack-grid-error = Данная зона запрещает распаковывать предметы! +flatpack-unpack-user-error = Данная зона запрещает Вам распаковывать предметы!