Some vehicle bugfixes (#11692)

This commit is contained in:
Leon Friedrich
2022-10-04 15:49:46 +13:00
committed by GitHub
parent 47db233091
commit 4148b252c5
8 changed files with 80 additions and 98 deletions

View File

@@ -6,7 +6,9 @@ using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Physics.Pull;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Containers;
using Content.Shared.Tag;
using Content.Shared.Audio;
namespace Content.Shared.Vehicle;
@@ -19,7 +21,11 @@ public abstract partial class SharedVehicleSystem : EntitySystem
{
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
[Dependency] private readonly MovementSpeedModifierSystem _modifier = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
private const string KeySlot = "key_slot";
public override void Initialize()
{
@@ -29,7 +35,44 @@ public abstract partial class SharedVehicleSystem : EntitySystem
SubscribeLocalEvent<VehicleComponent, RefreshMovementSpeedModifiersEvent>(OnVehicleModifier);
SubscribeLocalEvent<VehicleComponent, ComponentStartup>(OnVehicleStartup);
SubscribeLocalEvent<VehicleComponent, MoveEvent>(OnVehicleRotate);
SubscribeLocalEvent<VehicleComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
SubscribeLocalEvent<VehicleComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
}
/// <summary>
/// Handle adding keys to the ignition, give stuff the InVehicleComponent so it can't be picked
/// up by people not in the vehicle.
/// </summary>
private void OnEntInserted(EntityUid uid, VehicleComponent component, EntInsertedIntoContainerMessage args)
{
if (args.Container.ID != KeySlot ||
!_tagSystem.HasTag(args.Entity, "VehicleKey")) return;
// Enable vehicle
var inVehicle = EnsureComp<InVehicleComponent>(args.Entity);
inVehicle.Vehicle = component;
component.HasKey = true;
// Audiovisual feedback
_ambientSound.SetAmbience(uid, true);
_tagSystem.AddTag(uid, "DoorBumpOpener");
_modifier.RefreshMovementSpeedModifiers(uid);
}
/// <summary>
/// Turn off the engine when key is removed.
/// </summary>
private void OnEntRemoved(EntityUid uid, VehicleComponent component, EntRemovedFromContainerMessage args)
{
if (args.Container.ID != KeySlot || !RemComp<InVehicleComponent>(args.Entity))
return;
// Disable vehicle
component.HasKey = false;
_ambientSound.SetAmbience(uid, false);
_tagSystem.RemoveTag(uid, "DoorBumpOpener");
_modifier.RefreshMovementSpeedModifiers(uid);
}
private void OnVehicleModifier(EntityUid uid, VehicleComponent component, RefreshMovementSpeedModifiersEvent args)