Skip to content

Commit

Permalink
hey
Browse files Browse the repository at this point in the history
  • Loading branch information
Acensti committed Jul 7, 2024
1 parent eb94920 commit 597ac32
Show file tree
Hide file tree
Showing 16 changed files with 401 additions and 22 deletions.
27 changes: 27 additions & 0 deletions Content.Client/Vehicle/ClientVehicleSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.Vehicle;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;

namespace Content.Client.Vehicle
{
public sealed class ClientVehicleSystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RiddenVehicleComponent, ComponentHandleState>(OnHandleState);
}

private void OnHandleState(EntityUid uid, RiddenVehicleComponent component, ref ComponentHandleState args)
{
if (args.Current is not RiddenVehicleComponentState state)
return;

component.Riders.Clear();
component.Riders.AddRange(state.Riders);
}
}
}
19 changes: 13 additions & 6 deletions Content.Server/Vehicles/Components/VehicleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// /Content.Server/Vehicles/Components/VehicleComponent.cs
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Server.Vehicles.Components
namespace Content.Shared.Vehicle
{
[RegisterComponent]
public sealed class VehicleComponent : Component
{
public override string Name => "Vehicle";

[DataField("maxOccupants")]
public int MaxOccupants { get; set; } = 4;
public int MaxOccupants = 1;

[DataField("maxDrivers")]
public int MaxDrivers { get; set; } = 1;
public int MaxDrivers = 1;

[DataField("canMove")]
public bool CanMove = true;

[DataField("keyType")]
public string? KeyType;

public List<EntityUid> Occupants { get; set; } = new();
public EntityUid? Driver { get; set; }
[ViewVariables]
public List<EntityUid> Occupants = new();
}
}
65 changes: 59 additions & 6 deletions Content.Server/Vehicles/Systems/VehicleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// /Content.Server/Vehicles/Systems/VehicleSystem.cs
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 Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Player;
Expand All @@ -13,12 +18,16 @@ 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)
Expand All @@ -40,20 +49,64 @@ private void AddEnterVehicleVerb(EntityUid uid, VehicleComponent component, GetV

private void EnterVehicle(EntityUid user, EntityUid vehicle, VehicleComponent component)
{
component.Occupants.Add(user);
if (component.Driver == null)
if (component.Occupants.Count >= component.MaxOccupants)
{
_popupSystem.PopupEntity("The vehicle is full.", vehicle, Filter.Entities(user));
return;
}

if (_buckleSystem.TryBuckle(user, user, vehicle))
{
component.Driver = user;
component.Occupants.Add(user);
if (component.Driver == null)
{
component.Driver = user;
}
}
//TODO Additional logic to attach user to vehicle, update UI, etc maybe.
}

private void OnMoveInput(EntityUid uid, VehicleComponent component, ref MoveInputEvent args)
{
if (component.Driver == null || component.Driver != args.User)
return;

// Handle vehicle movement logic here. Surely theres a component for that im just tossing ideas
// 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)
{
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.Buckled)
{
component.Occupants.Add(args.BuckleEntity);
}
else
{
component.Occupants.Remove(args.BuckleEntity);
if (component.Driver == args.BuckleEntity)
{
component.Driver = component.Occupants.Count > 0 ? component.Occupants[0] : null;
}
}
}
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Buckle/Components/StrapComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public sealed partial class StrapComponent : Component
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public float MaxBuckleDistance = 1.0f;

/// <summary>
Expand All @@ -42,6 +43,7 @@ public sealed partial class StrapComponent : Component
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public int Size = 100;

/// <summary>
Expand All @@ -55,27 +57,31 @@ public sealed partial class StrapComponent : Component
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool Enabled = true;

/// <summary>
/// The alert type to show when an entity is buckled to this strap.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public AlertType BuckledAlertType = AlertType.Buckled;

/// <summary>
/// The sound to play when an entity is buckled to this strap.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public SoundSpecifier BuckleSound = new SoundPathSpecifier("/Audio/Effects/buckle.ogg");

/// <summary>
/// The sound to play when an entity is unbuckled from this strap.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public SoundSpecifier UnbuckleSound = new SoundPathSpecifier("/Audio/Effects/unbuckle.ogg");
}

Expand Down
34 changes: 24 additions & 10 deletions Content.Shared/Buckle/SharedBuckleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Verbs;
using Content.Shared.Physics;
using Content.Shared.Throwing;
using Content.Shared.Movement;
using Content.Shared.Movement.Events;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Alert;
Expand All @@ -15,6 +23,7 @@
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Shared.Buckle;

Expand Down Expand Up @@ -51,6 +60,11 @@ public override void Initialize()
InitializeStrap();
}

private void InitializeStrap()
{
// Initialization logic for straps...
}

private void InitializeBuckle()
{
SubscribeLocalEvent<BuckleComponent, ComponentStartup>(OnBuckleStartup);
Expand Down Expand Up @@ -159,15 +173,15 @@ private void UpdateBuckleStatus(EntityUid uid, BuckleComponent component)

strap.BuckledEntities.Add(uid);
strap.OccupiedSize += component.Size;
Dirty(strap);
Dirty(component.BuckledTo.Value, strap);
}

private bool TryBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strapUid, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)
public bool TryBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strapUid, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)
{
if (!Resolve(buckleUid, ref buckleComp, false) || !Resolve(strapUid, ref strapComp, false))
return false;

if (buckleComp.Buckled || !CanBuckle(buckleUid, strapUid, buckleComp, strapComp))
if (buckleComp.Buckled || !CanBuckle(buckleUid, userUid, strapUid, out strapComp, buckleComp))
return false;

buckleComp.Buckled = true;
Expand All @@ -189,7 +203,7 @@ private bool TryBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strapUi
return true;
}

private bool TryUnbuckle(EntityUid buckleUid, EntityUid userUid, bool force, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)
public bool TryUnbuckle(EntityUid buckleUid, EntityUid userUid, bool force, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)
{
if (!Resolve(buckleUid, ref buckleComp, false) || !buckleComp.Buckled || !Resolve(buckleComp.BuckledTo, ref strapComp, false))
return false;
Expand All @@ -206,18 +220,18 @@ private bool TryUnbuckle(EntityUid buckleUid, EntityUid userUid, bool force, Buc
if (strapComp.BuckledEntities.Remove(buckleUid))
{
strapComp.OccupiedSize -= buckleComp.Size;
Dirty(strapComp);
Dirty(strapComp.Owner, strapComp);
}

_joints.RefreshRelay(buckleUid);
Appearance.SetData(strapUid, StrapVisuals.State, strapComp.BuckledEntities.Count != 0);
Appearance.SetData(strapComp.Owner, StrapVisuals.State, strapComp.BuckledEntities.Count != 0);

if (!TerminatingOrDeleted(strapUid))
_audio.PlayPredicted(strapComp.UnbuckleSound, strapUid, userUid);
if (!TerminatingOrDeleted(strapComp.Owner))
_audio.PlayPredicted(strapComp.UnbuckleSound, strapComp.Owner, userUid);

var ev = new BuckleChangeEvent(strapUid, buckleUid, false);
var ev = new BuckleChangeEvent(strapComp.Owner, buckleUid, false);
RaiseLocalEvent(buckleUid, ref ev);
RaiseLocalEvent(strapUid, ref ev);
RaiseLocalEvent(strapComp.Owner, ref ev);

return true;
}
Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/Key/KeyComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Shared.Key
{
[RegisterComponent]
public partial class KeyComponent : Component
{
public override string Name => "Key";

[DataField("keyId")]
public string KeyId = string.Empty;
}
}
14 changes: 14 additions & 0 deletions Content.Shared/Key/KeyRequiredComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Shared.Key
{
[RegisterComponent]
public partial class KeyRequiredComponent : Component
{
public override string Name => "KeyRequired";

[DataField("requiredKeyId")]
public string RequiredKeyId = string.Empty;
}
}
28 changes: 28 additions & 0 deletions Content.Shared/Key/KeySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;

namespace Content.Shared.Key
{
public sealed class KeySystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<KeyRequiredComponent, ComponentStartup>(OnKeyRequiredStartup);
}

private void OnKeyRequiredStartup(EntityUid uid, KeyRequiredComponent component, ComponentStartup args)
{
// Logic to handle key requirements
}

public bool HasValidKey(EntityUid uid, string requiredKeyId)
{
if (EntityManager.TryGetComponent(uid, out KeyComponent? keyComp))
{
return keyComp.KeyId == requiredKeyId;
}
return false;
}
}
}
18 changes: 18 additions & 0 deletions Content.Shared/Vehicles/Components/KeyRequiredComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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;
}
}
18 changes: 18 additions & 0 deletions Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

namespace Content.Shared.Vehicle
{
[RegisterComponent]
public partial class RiddenVehicleComponent : Component
{
public override string Name => "RiddenVehicle";

[DataField("maxRiders")]
public int MaxRiders = 1;

[ViewVariables]
public List<EntityUid> Riders = new();
}
}
Loading

0 comments on commit 597ac32

Please sign in to comment.