Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrivalsProtect update #896

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Server/Backmen/Arrivals/ArrivalsProtectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void OnBuildAttemptEvent(BuildAttemptEvent ev)
return;
}

if (HasComp<ArrivalsProtectGridComponent>(grid.Value))
if (ArrivalsProtectGridQuery.HasComp(grid.Value))
{
ev.Cancel();
}
Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/Backmen/Arrivals/FlatPackUserAttemptUseEvent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 10 additions & 1 deletion Content.Shared/Backmen/Arrivals/SharedArrivalsProtectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ namespace Content.Shared.Backmen.Arrivals;

public abstract class SharedArrivalsProtectSystem : EntitySystem
{
protected EntityQuery<ArrivalsProtectGridComponent> ArrivalsProtectGridQuery;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ToolUserAttemptUseEvent>(OnTryUse);
SubscribeLocalEvent<ArrivalsProtectGridComponent, FlatPackUserAttemptUseEvent>(OnTryUnpack);
ArrivalsProtectGridQuery = GetEntityQuery<ArrivalsProtectGridComponent>();
}

private void OnTryUnpack(Entity<ArrivalsProtectGridComponent> ent, ref FlatPackUserAttemptUseEvent args)
{
args.Cancelled = true;
}


private void OnTryUse(ref ToolUserAttemptUseEvent msg)
{
if (msg.Target == null)
Expand All @@ -21,7 +30,7 @@ private void OnTryUse(ref ToolUserAttemptUseEvent msg)

var pos = Transform(msg.Target!.Value);

if (pos.GridUid == null || !HasComp<ArrivalsProtectGridComponent>(pos.GridUid))
if (pos.GridUid == null || !ArrivalsProtectGridQuery.HasComp(pos.GridUid))
{
return;
}
Expand Down
21 changes: 21 additions & 0 deletions Content.Shared/Construction/SharedFlatpackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ private void OnFlatpackInteractUsing(Entity<FlatpackComponent> 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));
Expand Down
4 changes: 4 additions & 0 deletions Resources/Locale/ru-RU/construction/components/flatpack.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Данная зона запрещает Вам распаковывать предметы!
Loading