Rework climbing (#7706)

This commit is contained in:
Jacob Tong
2022-05-10 01:08:52 -07:00
committed by GitHub
parent 7198173ff4
commit 0e945b42b2
11 changed files with 516 additions and 634 deletions

View File

@@ -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;
}
}

View File

@@ -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 { }

View File

@@ -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 { }