Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dont Merge] Buckle Changes/Rework Incoming, Vehicle Implemenation and Proper Keys Functionality #521

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Content.Client/Vehicle/ClientVehicleSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Content.Shared.Vehicle;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.GameStates;

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.UnionWith(state.Riders);
}
}
}
40 changes: 20 additions & 20 deletions Content.IntegrationTests/Tests/Buckle/BuckleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ await server.WaitAssertion(() =>
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle), Is.False);

// Trying to unbuckle too quickly fails
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.TryUnbuckle(human, human, false, buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle), Is.False);
Assert.That(buckle.Buckled);
#pragma warning restore NUnit2045
});
Expand All @@ -137,7 +137,7 @@ await server.WaitAssertion(() =>
#pragma warning restore NUnit2045

// Unbuckle
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.That(buckleSystem.TryUnbuckle(human, human, false, buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Null);
Expand All @@ -153,15 +153,15 @@ await server.WaitAssertion(() =>

#pragma warning disable NUnit2045 // Interdependent asserts.
// Re-buckling has no cooldown
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.That(buckle.Buckled);

// On cooldown
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.TryUnbuckle(human, human, false, buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle), Is.False);
Assert.That(buckle.Buckled);
#pragma warning restore NUnit2045
});
Expand All @@ -176,7 +176,7 @@ await server.WaitAssertion(() =>
Assert.That(buckle.Buckled);

// Unbuckle
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.That(buckleSystem.TryUnbuckle(human, human, false, buckle));
Assert.That(buckle.Buckled, Is.False);
#pragma warning restore NUnit2045

Expand All @@ -187,9 +187,9 @@ await server.WaitAssertion(() =>

// Out of range
#pragma warning disable NUnit2045 // Interdependent asserts.
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle), Is.False);
Assert.That(buckleSystem.TryUnbuckle(human, human, false, buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle), Is.False);
#pragma warning restore NUnit2045

// Move near the chair
Expand All @@ -198,16 +198,16 @@ await server.WaitAssertion(() =>

// In range
#pragma warning disable NUnit2045 // Interdependent asserts.
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.TryUnbuckle(human, human, false, buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle), Is.False);
Assert.That(buckle.Buckled);
#pragma warning restore NUnit2045

// Force unbuckle
Assert.That(buckleSystem.TryUnbuckle(human, human, true, buckleComp: buckle));
Assert.That(buckleSystem.TryUnbuckle(human, human, true, buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.Buckled, Is.False);
Expand All @@ -217,7 +217,7 @@ await server.WaitAssertion(() =>
});

// Re-buckle
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));

// Move away from the chair
oldWorldPosition = xformSystem.GetWorldPosition(chair, xformQuery);
Expand Down Expand Up @@ -276,7 +276,7 @@ await server.WaitAssertion(() =>
});

// Buckle
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Expand Down Expand Up @@ -328,7 +328,7 @@ await server.WaitAssertion(() =>
Assert.That(hand.HeldEntity, Is.Null);
}

buckleSystem.TryUnbuckle(human, human, true, buckleComp: buckle);
buckleSystem.TryUnbuckle(human, human, true, buckle);
});

await pair.CleanReturnAsync();
Expand Down Expand Up @@ -363,7 +363,7 @@ await server.WaitAssertion(() =>
});

// Buckle
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Expand All @@ -388,7 +388,7 @@ await server.WaitAssertion(() =>
xformSystem.SetWorldPosition(human, oldWorldPosition, xformQuery);

// Buckle
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Expand Down
10 changes: 8 additions & 2 deletions Content.Server/Alert/Click/Unbuckle.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
using Content.Shared.Alert;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using JetBrains.Annotations;
using Robust.Shared.IoC;

namespace Content.Server.Alert.Click
{
/// <summary>
/// Unbuckles if player is currently buckled.
/// </summary>
[UsedImplicitly]
[UsedImplicitly]
[DataDefinition]
public sealed partial class Unbuckle : IAlertClick
{
public void AlertClicked(EntityUid player)
{
IoCManager.Resolve<IEntityManager>().System<SharedBuckleSystem>().TryUnbuckle(player, player);
var entityManager = IoCManager.Resolve<IEntityManager>();
var buckleSystem = entityManager.System<SharedBuckleSystem>();
var buckleComp = entityManager.GetComponent<BuckleComponent>(player);
var strapComp = buckleComp.BuckledTo != null ? entityManager.GetComponent<StrapComponent>(buckleComp.BuckledTo.Value) : null;
buckleSystem.TryUnbuckle(player, player, false, buckleComp, strapComp);
}
}
}
3 changes: 2 additions & 1 deletion Content.Server/NPC/HTN/Preconditions/BuckledPrecondition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;

namespace Content.Server.NPC.HTN.Preconditions;

Expand All @@ -9,7 +10,7 @@ public sealed partial class BuckledPrecondition : HTNPrecondition
{
private SharedBuckleSystem _buckle = default!;

[ViewVariables(VVAccess.ReadWrite)] [DataField("isBuckled")] public bool IsBuckled = true;
[ViewVariables(VVAccess.ReadWrite)][DataField("isBuckled")] public bool IsBuckled = true;

public override void Initialize(IEntitySystemManager sysManager)
{
Expand Down
26 changes: 26 additions & 0 deletions Content.Server/Vehicles/Components/VehicleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Shared.Vehicle
{
[RegisterComponent]
public sealed partial class VehicleComponent : Component
{


[DataField("maxOccupants")]
public int MaxOccupants = 1;

[DataField("maxDrivers")]
public int MaxDrivers = 1;

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

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

[ViewVariables]
public List<EntityUid> Occupants = new();
}
}
80 changes: 41 additions & 39 deletions Content.Shared/Buckle/Components/BuckleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,81 @@
using Content.Shared.Interaction;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;

using Content.Shared.Whitelist;
namespace Content.Shared.Buckle.Components;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]

[Access(typeof(SharedBuckleSystem))]

public sealed partial class BuckleComponent : Component

{
/// <summary>
/// The range from which this entity can buckle to a <see cref="StrapComponent"/>.
/// Separated from normal interaction range to fix the "someone buckled to a strap
/// across a table two tiles away" problem.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]

[DataField, ViewVariables(VVAccess.ReadWrite)]

public float Range = SharedInteractionSystem.InteractionRange / 1.4f;

/// <summary>
/// True if the entity is buckled, false otherwise.
/// </summary>

[ViewVariables(VVAccess.ReadWrite)]

[AutoNetworkedField]

public bool Buckled;


[ViewVariables]

[AutoNetworkedField]

public EntityUid? LastEntityBuckledTo;

/// <summary>
/// Whether or not collisions should be possible with the entity we are strapped to
/// </summary>

[ViewVariables(VVAccess.ReadWrite)]

[DataField, AutoNetworkedField]

public bool DontCollide;

/// <summary>
/// Whether or not we should be allowed to pull the entity we are strapped to
/// </summary>

[ViewVariables(VVAccess.ReadWrite)]

[DataField]

public bool PullStrap;

/// <summary>
/// The amount of time that must pass for this entity to
/// be able to unbuckle after recently buckling.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]

[DataField, ViewVariables(VVAccess.ReadWrite)]

public TimeSpan Delay = TimeSpan.FromSeconds(0.25f);

/// <summary>
/// The time that this entity buckled at.
/// </summary>

[ViewVariables]

public TimeSpan BuckleTime;

/// <summary>
/// The strap that this component is buckled to.
/// </summary>

[ViewVariables]

[AutoNetworkedField]

public EntityUid? BuckledTo;

/// <summary>
/// The amount of space that this entity occupies in a
/// <see cref="StrapComponent"/>.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]

[DataField, ViewVariables(VVAccess.ReadWrite)]

public int Size = 100;

/// <summary>
/// Used for client rendering
/// </summary>
[ViewVariables] public int? OriginalDrawDepth;

[ViewVariables]

public int? OriginalDrawDepth;


[DataField, ViewVariables(VVAccess.ReadWrite)]

public EntityWhitelist? AllowedBuckleTypes;

}

[ByRefEvent]
Expand All @@ -88,3 +89,4 @@ public enum BuckleVisuals
{
Buckled
}

Loading
Loading