From 0040e5af78608108437b4804586dad082b7d4ea8 Mon Sep 17 00:00:00 2001 From: Acensti Date: Sun, 7 Jul 2024 14:45:19 +0200 Subject: [PATCH] more junk --- .../Systems/VehicleDestructionSystem.cs | 21 ---- .../Vehicles/Systems/VehicleSystem.cs | 71 ++--------- .../Vehicles/Components/KeyComponent.cs | 14 +++ .../Vehicles/Components/KeyRequiredComponent | 18 --- .../Components/RiddenVehicleComponent.cs | 4 +- .../Vehicles/Components/VehicleComponent.cs | 4 +- .../Components/VehicleKeyComponent.cs | 16 --- Content.Shared/Vehicles/KeySystem.cs | 43 +++---- Content.Shared/Vehicles/VehicleSystem.cs | 113 ++++++++++++++++++ 9 files changed, 161 insertions(+), 143 deletions(-) delete mode 100644 Content.Server/Vehicles/Systems/VehicleDestructionSystem.cs create mode 100644 Content.Shared/Vehicles/Components/KeyComponent.cs delete mode 100644 Content.Shared/Vehicles/Components/KeyRequiredComponent delete mode 100644 Content.Shared/Vehicles/Components/VehicleKeyComponent.cs create mode 100644 Content.Shared/Vehicles/VehicleSystem.cs diff --git a/Content.Server/Vehicles/Systems/VehicleDestructionSystem.cs b/Content.Server/Vehicles/Systems/VehicleDestructionSystem.cs deleted file mode 100644 index 667348dec05..00000000000 --- a/Content.Server/Vehicles/Systems/VehicleDestructionSystem.cs +++ /dev/null @@ -1,21 +0,0 @@ -// /Content.Server/Vehicles/Systems/VehicleDestructionSystem.cs -using Content.Server.Vehicles.Components; -using Robust.Shared.GameObjects; -using Robust.Shared.Physics; - -namespace Content.Server.Vehicles.Systems -{ - public sealed class VehicleDestructionSystem : EntitySystem - { - public override void Initialize() - { - base.Initialize(); - SubscribeLocalEvent(OnVehicleDestroyed); - } - - private void OnVehicleDestroyed(EntityUid uid, VehicleComponent component, DestructionEventArgs args) - { - // Logic for vehicle destruction, e.g., explosion, dropping items, etc. - } - } -} diff --git a/Content.Server/Vehicles/Systems/VehicleSystem.cs b/Content.Server/Vehicles/Systems/VehicleSystem.cs index baab4cafd1c..8c90c0fb702 100644 --- a/Content.Server/Vehicles/Systems/VehicleSystem.cs +++ b/Content.Server/Vehicles/Systems/VehicleSystem.cs @@ -1,4 +1,3 @@ -using Content.Server.Vehicles.Components; using Content.Shared.Buckle; using Content.Shared.Buckle.Components; using Content.Shared.Interaction; @@ -24,88 +23,36 @@ public sealed class VehicleSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent>(AddEnterVehicleVerb); - SubscribeLocalEvent(OnMoveInput); - SubscribeLocalEvent(OnInteractHand); - SubscribeLocalEvent(OnBuckleChange); + SubscribeLocalEvent(OnInteractHand); + SubscribeLocalEvent(OnBuckleChange); } - private void AddEnterVehicleVerb(EntityUid uid, VehicleComponent component, GetVerbsEvent args) - { - if (!args.CanInteract || !args.CanAccess) - return; - - if (component.Occupants.Count >= component.MaxOccupants) - return; - - AlternativeVerb verb = new() - { - Act = () => EnterVehicle(args.User, uid, component), - Text = Loc.GetString("enter-vehicle-verb"), - Priority = 2 - }; - args.Verbs.Add(verb); - } - - private void EnterVehicle(EntityUid user, EntityUid vehicle, VehicleComponent component) - { - if (component.Occupants.Count >= component.MaxOccupants) - { - _popupSystem.PopupEntity("The vehicle is full.", vehicle, Filter.Entities(user)); - return; - } - - if (_buckleSystem.TryBuckle(user, user, vehicle)) - { - component.Occupants.Add(user); - if (component.Driver == null) - { - component.Driver = user; - } - } - } - - private void OnMoveInput(EntityUid uid, VehicleComponent component, ref MoveInputEvent args) - { - if (component.Driver == null || component.Driver != args.User) - return; - - // Handle vehicle movement logic here. - var transform = EntityManager.GetComponent(uid); - var direction = args.Direction.ToVec(); - transform.Coordinates += direction * component.Speed * _gameTiming.FrameTime; - } - - private void OnInteractHand(EntityUid uid, VehicleComponent component, InteractHandEvent args) + private void OnInteractHand(EntityUid uid, RiddenVehicleComponent component, InteractHandEvent args) { if (args.Handled) return; - if (component.Occupants.Contains(args.User)) + if (component.Riders.Contains(args.User)) { _buckleSystem.TryUnbuckle(args.User, args.User, false); } else { - EnterVehicle(args.User, uid, component); + _buckleSystem.TryBuckle(args.User, args.User, uid); } args.Handled = true; } - private void OnBuckleChange(EntityUid uid, VehicleComponent component, BuckleChangeEvent args) + private void OnBuckleChange(EntityUid uid, RiddenVehicleComponent component, BuckleChangeEvent args) { - if (args.Buckled) + if (args.Buckling) { - component.Occupants.Add(args.BuckleEntity); + component.Riders.Add(args.BuckledEntity); } else { - component.Occupants.Remove(args.BuckleEntity); - if (component.Driver == args.BuckleEntity) - { - component.Driver = component.Occupants.Count > 0 ? component.Occupants[0] : null; - } + component.Riders.Remove(args.BuckledEntity); } } } diff --git a/Content.Shared/Vehicles/Components/KeyComponent.cs b/Content.Shared/Vehicles/Components/KeyComponent.cs new file mode 100644 index 00000000000..5a80a6fc0e8 --- /dev/null +++ b/Content.Shared/Vehicles/Components/KeyComponent.cs @@ -0,0 +1,14 @@ +using Robust.Shared.GameObjects; + +namespace Content.Shared.Vehicle +{ + [RegisterComponent] + public partial class KeyComponent : Component + { + [DataField("keyType")] + public string KeyType = string.Empty; + + [ViewVariables] + public bool IsInserted = false; + } +} diff --git a/Content.Shared/Vehicles/Components/KeyRequiredComponent b/Content.Shared/Vehicles/Components/KeyRequiredComponent deleted file mode 100644 index e06101ac6f9..00000000000 --- a/Content.Shared/Vehicles/Components/KeyRequiredComponent +++ /dev/null @@ -1,18 +0,0 @@ -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.ViewVariables; - -namespace Content.Shared.Vehicle -{ - [RegisterComponent] - public sealed class KeyRequiredComponent : Component - { - public override string Name => "KeyRequired"; - - [DataField("keyType")] - public string KeyType = string.Empty; - - [ViewVariables] - public EntityUid? InsertedKey; - } -} diff --git a/Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs b/Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs index 23a60c5166e..d77da291131 100644 --- a/Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs +++ b/Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs @@ -5,10 +5,8 @@ namespace Content.Shared.Vehicle { [RegisterComponent] - public partial class RiddenVehicleComponent : Component + public sealed partial class RiddenVehicleComponent : Component { - public override string Name => "RiddenVehicle"; - [DataField("maxRiders")] public int MaxRiders = 1; diff --git a/Content.Shared/Vehicles/Components/VehicleComponent.cs b/Content.Shared/Vehicles/Components/VehicleComponent.cs index e6a323da79b..37d8fa6470c 100644 --- a/Content.Shared/Vehicles/Components/VehicleComponent.cs +++ b/Content.Shared/Vehicles/Components/VehicleComponent.cs @@ -5,10 +5,8 @@ namespace Content.Server.Vehicles.Components { [RegisterComponent] - public sealed class VehicleComponent : Component + public sealed partial class VehicleComponent : Component { - public override string Name => "Vehicle"; - [DataField("maxOccupants")] public int MaxOccupants = 1; diff --git a/Content.Shared/Vehicles/Components/VehicleKeyComponent.cs b/Content.Shared/Vehicles/Components/VehicleKeyComponent.cs deleted file mode 100644 index 0f487b77138..00000000000 --- a/Content.Shared/Vehicles/Components/VehicleKeyComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -// /Content.Shared/Vehicles/Components/VehicleKeyComponent.cs -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization.Manager.Attributes; - -namespace Content.Shared.Vehicles.Components -{ - [RegisterComponent] - public sealed class VehicleKeyComponent : Component - { - [DataField("keyId")] - public string KeyId { get; set; } = string.Empty; - - [DataField("isLocked")] - public bool IsLocked { get; set; } = true; - } -} diff --git a/Content.Shared/Vehicles/KeySystem.cs b/Content.Shared/Vehicles/KeySystem.cs index fa7e09f64e3..b11fe554465 100644 --- a/Content.Shared/Vehicles/KeySystem.cs +++ b/Content.Shared/Vehicles/KeySystem.cs @@ -1,12 +1,8 @@ using Content.Shared.Interaction; using Content.Shared.Popups; -using Content.Shared.Vehicle; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Player; -using Content.Shared.Vehicles.Components; -using Content.Shared.Interaction.Events; - namespace Content.Shared.Vehicle { @@ -17,34 +13,41 @@ public sealed class KeySystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnInteractUsing); - SubscribeLocalEvent(OnAltInteract); + SubscribeLocalEvent(OnInteractHand); } - private void OnInteractUsing(EntityUid uid, KeyRequiredComponent component, InteractUsingEvent args) + private void OnInteractHand(EntityUid uid, KeyComponent component, InteractHandEvent args) + { + if (args.Handled) + return; - if (component.InsertedKey == null && args.Used.HasComponent()) + + if (component.IsInserted) + { - component.InsertedKey = args.Used; - _popupSystem.PopupEntity("You insert the key.", uid, Filter.Entities(args.User)); - args.Handled = true; + + component.IsInserted = false; + + _popupSystem.PopupEntity("Key removed.", uid, args.User, PopupType.Medium); + } - } - private void OnAltInteract(EntityUid uid, KeyRequiredComponent component, AltInteractEvent args) - { - if (args.Handled) - return; + else - if (component.InsertedKey != null) { - _popupSystem.PopupEntity("You remove the key.", uid, Filter.Entities(args.User)); - component.InsertedKey = null; - args.Handled = true; + + component.IsInserted = true; + + _popupSystem.PopupEntity("Key inserted.", uid, args.User, PopupType.Medium); + } + + + args.Handled = true; + } } } diff --git a/Content.Shared/Vehicles/VehicleSystem.cs b/Content.Shared/Vehicles/VehicleSystem.cs new file mode 100644 index 00000000000..fbf011f1ca1 --- /dev/null +++ b/Content.Shared/Vehicles/VehicleSystem.cs @@ -0,0 +1,113 @@ +using Content.Server.Vehicles.Components; +using Content.Shared.Buckle; +using Content.Shared.Buckle.Components; +using Content.Shared.Interaction; +using Content.Shared.Popups; +using Content.Shared.Vehicle; +using Content.Shared.Verbs; +using Content.Shared.Movement.Events; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using Robust.Shared.Physics; +using Robust.Shared.Player; +using Robust.Shared.Timing; + +namespace Content.Server.Vehicles.Systems +{ + public sealed class VehicleSystem : EntitySystem + { + [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly SharedBuckleSystem _buckleSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent>(AddEnterVehicleVerb); + SubscribeLocalEvent(OnMoveInput); + SubscribeLocalEvent(OnInteractHand); + SubscribeLocalEvent(OnBuckleChange); + } + + private void AddEnterVehicleVerb(EntityUid uid, VehicleComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess) + return; + + if (component.Occupants.Count >= component.MaxOccupants) + return; + + AlternativeVerb verb = new() + { + Act = () => EnterVehicle(args.User, uid, component), + Text = Loc.GetString("enter-vehicle-verb"), + Priority = 2 + }; + args.Verbs.Add(verb); + } + + private void EnterVehicle(EntityUid user, EntityUid vehicle, VehicleComponent component) + { + if (component.Occupants.Count >= component.MaxOccupants) + { + _popupSystem.PopupEntity("The vehicle is full.", vehicle, Filter.Entities(user)); + return; + } + + if (_buckleSystem.TryBuckle(user, user, vehicle)) + { + component.Occupants.Add(user); + if (component.Driver == null) + { + component.Driver = user; + } + } + } + + private void OnMoveInput(EntityUid uid, VehicleComponent component, ref MoveInputEvent args) + { + if (component.Driver == null || component.Driver != args.User) + return; + + var transform = EntityManager.GetComponent(uid); + var direction = args.Component.HeldMoveButtons.ToVec(); + transform.Coordinates += direction * component.Speed * (float) _gameTiming.FrameTime.TotalSeconds; + } + + private void OnInteractHand(EntityUid uid, VehicleComponent component, InteractHandEvent args) + { + if (args.Handled) + return; + + if (component.Occupants.Contains(args.User)) + { + _buckleSystem.TryUnbuckle(args.User, args.User, false); + } + else + { + EnterVehicle(args.User, uid, component); + } + + args.Handled = true; + } + + private void OnBuckleChange(EntityUid uid, VehicleComponent component, BuckleChangeEvent args) + { + if (args.Buckling) + { + component.Occupants.Add(args.BuckledEntity); + } + else + { + component.Occupants.Remove(args.BuckledEntity); + if (component.Driver == args.BuckledEntity) + { + component.Driver = component.Occupants.Count > 0 ? component.Occupants[0] : null; + } + } + } + } +}