Rework climbing (#7706)
This commit is contained in:
44
Content.Client/Movement/ClimbSystem.cs
Normal file
44
Content.Client/Movement/ClimbSystem.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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 { }
|
||||
|
||||
@@ -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 { }
|
||||
|
||||
Reference in New Issue
Block a user