Skip to content

Commit

Permalink
more junk
Browse files Browse the repository at this point in the history
  • Loading branch information
Acensti committed Jul 7, 2024
1 parent 847461e commit 0040e5a
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 143 deletions.
21 changes: 0 additions & 21 deletions Content.Server/Vehicles/Systems/VehicleDestructionSystem.cs

This file was deleted.

71 changes: 9 additions & 62 deletions Content.Server/Vehicles/Systems/VehicleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Server.Vehicles.Components;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.Interaction;
Expand All @@ -24,88 +23,36 @@ public sealed class VehicleSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<VehicleComponent, GetVerbsEvent<AlternativeVerb>>(AddEnterVehicleVerb);
SubscribeLocalEvent<VehicleComponent, MoveInputEvent>(OnMoveInput);
SubscribeLocalEvent<VehicleComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<VehicleComponent, BuckleChangeEvent>(OnBuckleChange);
SubscribeLocalEvent<RiddenVehicleComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<RiddenVehicleComponent, BuckleChangeEvent>(OnBuckleChange);
}

private void AddEnterVehicleVerb(EntityUid uid, VehicleComponent component, GetVerbsEvent<AlternativeVerb> 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<TransformComponent>(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);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/Vehicles/Components/KeyComponent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 0 additions & 18 deletions Content.Shared/Vehicles/Components/KeyRequiredComponent

This file was deleted.

4 changes: 1 addition & 3 deletions Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions Content.Shared/Vehicles/Components/VehicleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 0 additions & 16 deletions Content.Shared/Vehicles/Components/VehicleKeyComponent.cs

This file was deleted.

43 changes: 23 additions & 20 deletions Content.Shared/Vehicles/KeySystem.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -17,34 +13,41 @@ public sealed class KeySystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<KeyRequiredComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<KeyRequiredComponent, AltInteractEvent>(OnAltInteract);
SubscribeLocalEvent<KeyComponent, InteractHandEvent>(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<KeyComponent>())

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;

}
}
}
113 changes: 113 additions & 0 deletions Content.Shared/Vehicles/VehicleSystem.cs
Original file line number Diff line number Diff line change
@@ -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<VehicleComponent, GetVerbsEvent<AlternativeVerb>>(AddEnterVehicleVerb);
SubscribeLocalEvent<VehicleComponent, MoveInputEvent>(OnMoveInput);
SubscribeLocalEvent<VehicleComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<VehicleComponent, BuckleChangeEvent>(OnBuckleChange);
}

private void AddEnterVehicleVerb(EntityUid uid, VehicleComponent component, GetVerbsEvent<AlternativeVerb> 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<TransformComponent>(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;
}
}
}
}
}

0 comments on commit 0040e5a

Please sign in to comment.