CatStation/Content.Shared/Vehicle/VehicleSystem.Key.cs
AndrewFenriz 358ecc1181
Vehicle system: Core systems & Components (#43527)
* Part one of Vehicles

* Also we need this

* Part 1

* Part 1.1

* And we need this

* Part 2

* Part 2.1

* We REALLY need this

* Little fix

* Just fixes

* fixes (i'm tired)

* fix

* Apply suggestions from code review

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>

* update

* fixed

* just for cleaner diff

* just in case

* I think this might be cleaner

* fix

* upd

* Update Content.Shared/Vehicle/VehicleSystem.cs

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>

* fix vehicle key and unstrap checks

* fix OnBuckleUpdateCanMove

* fixes

* clear vehicle operator relays

* small fix

* fix1

* fix2

* upd

* fix?

* fix??

---------

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
2026-07-18 18:02:50 +00:00

63 lines
2 KiB
C#

using System.Linq;
using Content.Shared.Vehicle.Components;
using Robust.Shared.Containers;
namespace Content.Shared.Vehicle;
public sealed partial class VehicleSystem
{
[SubscribeLocalEvent]
private void OnGenericKeyedInsertAttempt(Entity<GenericKeyedVehicleComponent> ent, ref ContainerIsInsertingAttemptEvent args)
{
if (args.Cancelled || _timing.ApplyingState || !ent.Comp.PreventInvalidInsertion || args.Container.ID != ent.Comp.ContainerId)
return;
if (_entityWhitelist.IsWhitelistPass(ent.Comp.KeyWhitelist, args.EntityUid))
return;
args.Cancel();
}
[SubscribeLocalEvent]
private void OnGenericKeyedEntInserted(Entity<GenericKeyedVehicleComponent> ent, ref EntInsertedIntoContainerMessage args)
{
if (_timing.ApplyingState || args.Container.ID != ent.Comp.ContainerId)
return;
if (!_vehicleQuery.TryComp(ent, out var vehicle))
return;
RefreshCanRun((ent.Owner, vehicle));
}
[SubscribeLocalEvent]
private void OnGenericKeyedEntRemoved(Entity<GenericKeyedVehicleComponent> ent, ref EntRemovedFromContainerMessage args)
{
if (_timing.ApplyingState || args.Container.ID != ent.Comp.ContainerId)
return;
if (!_vehicleQuery.TryComp(ent, out var vehicle))
return;
RefreshCanRun((ent.Owner, vehicle));
}
[SubscribeLocalEvent]
private void OnGenericKeyedCanRun(Entity<GenericKeyedVehicleComponent> ent, ref VehicleCanRunEvent args)
{
if (!args.CanRun)
return;
if (!_container.TryGetContainer(ent.Owner, ent.Comp.ContainerId, out var container))
{
args = args with { CanRun = false };
return;
}
var hasKey = container.ContainedEntities.Any(contained =>
_entityWhitelist.IsWhitelistPass(ent.Comp.KeyWhitelist, contained));
if (!hasKey)
args = args with { CanRun = false };
}
}