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

@@ -22,14 +22,9 @@ namespace Content.Server.Vehicle
public sealed partial class VehicleSystem : SharedVehicleSystem
{
[Dependency] private readonly HandVirtualItemSystem _virtualItemSystem = default!;
[Dependency] private readonly MovementSpeedModifierSystem _modifier = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
[Dependency] private readonly SharedJointSystem _joints = default!;
[Dependency] private readonly SharedMoverController _mover = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
private const string KeySlot = "key_slot";
public override void Initialize()
{
@@ -39,8 +34,6 @@ namespace Content.Server.Vehicle
SubscribeLocalEvent<VehicleComponent, HonkActionEvent>(OnHonk);
SubscribeLocalEvent<VehicleComponent, BuckleChangeEvent>(OnBuckleChange);
SubscribeLocalEvent<VehicleComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
SubscribeLocalEvent<VehicleComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
}
/// <summary>
@@ -96,9 +89,8 @@ namespace Content.Server.Vehicle
component.Rider = args.BuckledEntity;
var relay = EnsureComp<RelayInputMoverComponent>(args.BuckledEntity);
relay.RelayEntity = uid;
_mover.SetRelay(args.BuckledEntity, uid, relay);
rider.Vehicle = uid;
component.HasRider = true;
// Update appearance stuff, add actions
UpdateBuckleOffset(Transform(uid), component);
@@ -114,10 +106,7 @@ namespace Content.Server.Vehicle
_actionsSystem.AddAction(args.BuckledEntity, component.HornAction, uid, actions);
}
if (TryComp<JointComponent>(args.BuckledEntity, out var joints))
{
_joints.ClearJoints(joints);
}
_joints.ClearJoints(args.BuckledEntity);
return;
}
@@ -133,43 +122,7 @@ namespace Content.Server.Vehicle
RemComp<RelayInputMoverComponent>(args.BuckledEntity);
// Reset component
component.HasRider = false;
component.Rider = null;
}
/// <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 = AddComp<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);
}
}
}