Skip to content

Commit

Permalink
Rework climbing (space-wizards#7706)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowCommander authored May 10, 2022
1 parent 7198173 commit 0e945b4
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 626 deletions.
9 changes: 0 additions & 9 deletions Content.Client/Climbing/ClimbingSystem.cs

This file was deleted.

44 changes: 44 additions & 0 deletions Content.Client/Movement/ClimbSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Content.Client.Interactable;
using Content.Client.Movement.Components;
using Content.Shared.Climbing;
using Content.Shared.DragDrop;
using Robust.Shared.GameStates;

namespace Content.Client.Movement;

public sealed class ClimbSystem : SharedClimbSystem
{
[Dependency] private readonly InteractionSystem _interactionSystem = default!;

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

private static void OnClimbingState(EntityUid uid, ClimbingComponent component, ref ComponentHandleState args)
{
if (args.Current is not SharedClimbingComponent.ClimbModeComponentState climbModeState)
return;

component.IsClimbing = climbModeState.Climbing;
component.OwnerIsTransitioning = climbModeState.IsTransitioning;
}

protected override void OnCanDragDropOn(EntityUid uid, SharedClimbableComponent component, CanDragDropOnEvent args)
{
base.OnCanDragDropOn(uid, component, args);

if (!args.CanDrop)
return;

var user = args.User;
var target = args.Target;
var dragged = args.Dragged;
bool Ignored(EntityUid entity) => entity == target || entity == user || entity == dragged;

args.CanDrop = _interactionSystem.InRangeUnobstructed(user, target, component.Range, predicate: Ignored)
&& _interactionSystem.InRangeUnobstructed(user, dragged, component.Range, predicate: Ignored);
args.Handled = true;
}
}
36 changes: 5 additions & 31 deletions Content.Client/Movement/Components/ClimbableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
using Content.Shared.Climbing;
using Content.Shared.DragDrop;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Robust.Shared.GameObjects;

namespace Content.Client.Movement.Components
{
[RegisterComponent]
[ComponentReference(typeof(IClimbable))]
public sealed class ClimbableComponent : SharedClimbableComponent
{
public override bool CanDragDropOn(DragDropEvent eventArgs)
{
if (!base.CanDragDropOn(eventArgs))
return false;
namespace Content.Client.Movement.Components;

var user = eventArgs.User;
var target = eventArgs.Target;
var dragged = eventArgs.Dragged;
bool Ignored(EntityUid entity) => entity == target || entity == user || entity == dragged;

var sys = EntitySystem.Get<SharedInteractionSystem>();

return sys.InRangeUnobstructed(user, target, Range, predicate: Ignored)
&& sys.InRangeUnobstructed(user, dragged, Range, predicate: Ignored);
}

public override bool DragDropOn(DragDropEvent eventArgs)
{
return false;
}
}
}
[RegisterComponent]
[Friend(typeof(ClimbSystem))]
[ComponentReference(typeof(SharedClimbableComponent))]
public sealed class ClimbableComponent : SharedClimbableComponent { }
25 changes: 5 additions & 20 deletions Content.Client/Movement/Components/ClimbingComponent.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
using Content.Shared.Climbing;
using Robust.Shared.GameObjects;

namespace Content.Client.Movement.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedClimbingComponent))]
public sealed class ClimbingComponent : SharedClimbingComponent
{
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
namespace Content.Client.Movement.Components;

if (curState is not ClimbModeComponentState climbModeState)
{
return;
}

IsClimbing = climbModeState.Climbing;
OwnerIsTransitioning = climbModeState.IsTransitioning;
}
}
}
[RegisterComponent]
[Friend(typeof(ClimbSystem))]
[ComponentReference(typeof(SharedClimbingComponent))]
public sealed class ClimbingComponent : SharedClimbingComponent { }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Content.Server.Climbing;

namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public async Task Test()

// Now let's make the player enter a climbing transitioning state.
climbing.IsClimbing = true;
climbing.TryMoveTo(entityManager.GetComponent<TransformComponent>(human).WorldPosition, entityManager.GetComponent<TransformComponent>(table).WorldPosition);
EntitySystem.Get<ClimbSystem>().MoveEntityToward(human, table, climbing:climbing);
var body = entityManager.GetComponent<IPhysBody>(human);
// TODO: Check it's climbing

Expand Down
Loading

0 comments on commit 0e945b4

Please sign in to comment.