Climbing refactor (#20516)
This commit is contained in:
@@ -47,7 +47,7 @@ namespace Content.Shared.ActionBlocker
|
||||
RaiseLocalEvent(uid, ev);
|
||||
|
||||
if (component.CanMove == ev.Cancelled)
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
|
||||
component.CanMove = !ev.Cancelled;
|
||||
return !ev.Cancelled;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Climbing;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class ClimbingComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the owner is climbing on a climbable entity.
|
||||
/// </summary>
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public bool IsClimbing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the owner is being moved onto the climbed entity.
|
||||
/// </summary>
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public bool OwnerIsTransitioning { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// We'll launch the mob onto the table and give them at least this amount of time to be on it.
|
||||
/// </summary>
|
||||
public const float BufferTime = 0.3f;
|
||||
|
||||
[ViewVariables]
|
||||
public Dictionary<string, int> DisabledFixtureMasks { get; } = new();
|
||||
}
|
||||
@@ -2,13 +2,13 @@ using Content.Shared.Damage;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Climbing;
|
||||
namespace Content.Shared.Climbing.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Makes entity do damage and stun entities with ClumsyComponent
|
||||
/// upon DragDrop or Climb interactions.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(BonkSystem))]
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(Systems.BonkSystem))]
|
||||
public sealed partial class BonkableComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
@@ -1,11 +1,12 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Climbing
|
||||
namespace Content.Shared.Climbing.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates this entity can be vaulted on top of.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class ClimbableComponent : Component
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace Content.Shared.Climbing
|
||||
/// The time it takes to climb onto the entity.
|
||||
/// </summary>
|
||||
[DataField("delay")]
|
||||
public float ClimbDelay = 0.8f;
|
||||
public float ClimbDelay = 1.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to be played when a climb is started.
|
||||
36
Content.Shared/Climbing/Components/ClimbingComponent.cs
Normal file
36
Content.Shared/Climbing/Components/ClimbingComponent.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Climbing.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class ClimbingComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the owner is climbing on a climbable entity.
|
||||
/// </summary>
|
||||
[AutoNetworkedField, DataField]
|
||||
public bool IsClimbing;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the owner is being moved onto the climbed entity.
|
||||
/// </summary>
|
||||
[AutoNetworkedField, DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan? NextTransition;
|
||||
|
||||
/// <summary>
|
||||
/// Direction to move when transition.
|
||||
/// </summary>
|
||||
[AutoNetworkedField, DataField]
|
||||
public Vector2 Direction;
|
||||
|
||||
/// <summary>
|
||||
/// How fast the entity is moved when climbing.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float TransitionRate = 5f;
|
||||
|
||||
[AutoNetworkedField, DataField]
|
||||
public Dictionary<string, int> DisabledFixtureMasks = new();
|
||||
}
|
||||
35
Content.Shared/Climbing/Components/GlassTableComponent.cs
Normal file
35
Content.Shared/Climbing/Components/GlassTableComponent.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Content.Shared.Damage;
|
||||
|
||||
namespace Content.Shared.Climbing.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Glass tables shatter and stun you when climbed on.
|
||||
/// This is a really entity-specific behavior, so opted to make it
|
||||
/// not very generalized with regards to naming.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(Systems.ClimbSystem))]
|
||||
public sealed partial class GlassTableComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// How much damage should be given to the climber?
|
||||
/// </summary>
|
||||
[DataField("climberDamage")]
|
||||
public DamageSpecifier ClimberDamage = default!;
|
||||
|
||||
/// <summary>
|
||||
/// How much damage should be given to the table when climbed on?
|
||||
/// </summary>
|
||||
[DataField("tableDamage")]
|
||||
public DamageSpecifier TableDamage = default!;
|
||||
|
||||
/// <summary>
|
||||
/// How much mass should be needed to break the table?
|
||||
/// </summary>
|
||||
[DataField("tableMassLimit")]
|
||||
public float MassLimit;
|
||||
|
||||
/// <summary>
|
||||
/// How long should someone who climbs on this table be stunned for?
|
||||
/// </summary>
|
||||
public float StunTime = 2.0f;
|
||||
}
|
||||
7
Content.Shared/Climbing/Events/ClimbedOnEvent.cs
Normal file
7
Content.Shared/Climbing/Events/ClimbedOnEvent.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Content.Shared.Climbing.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity when it is climbed on.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct ClimbedOnEvent(EntityUid Climber, EntityUid Instigator);
|
||||
@@ -4,7 +4,4 @@ namespace Content.Shared.Climbing.Events;
|
||||
/// Raised on an entity when it ends climbing.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct EndClimbEvent
|
||||
{
|
||||
|
||||
}
|
||||
public readonly record struct EndClimbEvent;
|
||||
|
||||
7
Content.Shared/Climbing/Events/StartClimbEvent.cs
Normal file
7
Content.Shared/Climbing/Events/StartClimbEvent.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Content.Shared.Climbing.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity when it successfully climbs on something.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct StartClimbEvent(EntityUid Climbable);
|
||||
@@ -1,34 +0,0 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Climbing;
|
||||
|
||||
public abstract partial class SharedClimbSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ClimbingComponent, UpdateCanMoveEvent>(HandleMoveAttempt);
|
||||
}
|
||||
|
||||
private static void HandleMoveAttempt(EntityUid uid, ClimbingComponent component, UpdateCanMoveEvent args)
|
||||
{
|
||||
if (component.LifeStage > ComponentLifeStage.Running)
|
||||
return;
|
||||
|
||||
if (component.OwnerIsTransitioning)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
protected virtual void OnCanDragDropOn(EntityUid uid, ClimbableComponent component, ref CanDropTargetEvent args)
|
||||
{
|
||||
args.CanDrop = HasComp<ClimbingComponent>(args.Dragged);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed partial class ClimbDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Climbing.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
using Robust.Shared.Configuration;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Climbing;
|
||||
namespace Content.Shared.Climbing.Systems;
|
||||
|
||||
public sealed partial class BonkSystem : EntitySystem
|
||||
{
|
||||
@@ -30,7 +31,7 @@ public sealed partial class BonkSystem : EntitySystem
|
||||
SubscribeLocalEvent<BonkableComponent, BonkDoAfterEvent>(OnBonkDoAfter);
|
||||
}
|
||||
|
||||
private void OnBonkDoAfter(EntityUid uid, BonkableComponent component, BonkDoAfterEvent args)
|
||||
private void OnBonkDoAfter(EntityUid uid, Components.BonkableComponent component, BonkDoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null)
|
||||
return;
|
||||
@@ -41,7 +42,7 @@ public sealed partial class BonkSystem : EntitySystem
|
||||
}
|
||||
|
||||
|
||||
public bool TryBonk(EntityUid user, EntityUid bonkableUid, BonkableComponent? bonkableComponent = null)
|
||||
public bool TryBonk(EntityUid user, EntityUid bonkableUid, Components.BonkableComponent? bonkableComponent = null)
|
||||
{
|
||||
if (!Resolve(bonkableUid, ref bonkableComponent, false))
|
||||
return false;
|
||||
@@ -71,7 +72,7 @@ public sealed partial class BonkSystem : EntitySystem
|
||||
|
||||
}
|
||||
|
||||
private void OnDragDrop(EntityUid uid, BonkableComponent component, ref DragDropTargetEvent args)
|
||||
private void OnDragDrop(EntityUid uid, Components.BonkableComponent component, ref DragDropTargetEvent args)
|
||||
{
|
||||
if (args.Handled || !HasComp<ClumsyComponent>(args.Dragged))
|
||||
return;
|
||||
486
Content.Shared/Climbing/Systems/ClimbSystem.cs
Normal file
486
Content.Shared/Climbing/Systems/ClimbSystem.cs
Normal file
@@ -0,0 +1,486 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Body.Systems;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Climbing.Components;
|
||||
using Content.Shared.Climbing.Events;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Climbing.Systems;
|
||||
|
||||
public sealed partial class ClimbSystem : VirtualController
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly FixtureSystem _fixtureSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedBodySystem _bodySystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
||||
|
||||
private const string ClimbingFixtureName = "climb";
|
||||
private const int ClimbingCollisionGroup = (int) (CollisionGroup.TableLayer | CollisionGroup.LowImpassable);
|
||||
|
||||
private EntityQuery<FixturesComponent> _fixturesQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_fixturesQuery = GetEntityQuery<FixturesComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
SubscribeLocalEvent<ClimbingComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
||||
SubscribeLocalEvent<ClimbingComponent, EntParentChangedMessage>(OnParentChange);
|
||||
SubscribeLocalEvent<ClimbingComponent, ClimbDoAfterEvent>(OnDoAfter);
|
||||
SubscribeLocalEvent<ClimbingComponent, EndCollideEvent>(OnClimbEndCollide);
|
||||
SubscribeLocalEvent<ClimbingComponent, BuckleChangeEvent>(OnBuckleChange);
|
||||
SubscribeLocalEvent<ClimbingComponent, EntityUnpausedEvent>(OnClimbableUnpaused);
|
||||
|
||||
SubscribeLocalEvent<ClimbableComponent, CanDropTargetEvent>(OnCanDragDropOn);
|
||||
SubscribeLocalEvent<ClimbableComponent, GetVerbsEvent<AlternativeVerb>>(AddClimbableVerb);
|
||||
SubscribeLocalEvent<ClimbableComponent, DragDropTargetEvent>(OnClimbableDragDrop);
|
||||
|
||||
SubscribeLocalEvent<GlassTableComponent, ClimbedOnEvent>(OnGlassClimbed);
|
||||
}
|
||||
|
||||
private void OnClimbableUnpaused(EntityUid uid, ClimbingComponent component, ref EntityUnpausedEvent args)
|
||||
{
|
||||
if (component.NextTransition == null)
|
||||
return;
|
||||
|
||||
component.NextTransition = component.NextTransition.Value + args.PausedTime;
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
||||
{
|
||||
base.UpdateBeforeSolve(prediction, frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<ClimbingComponent>();
|
||||
var curTime = _timing.CurTime;
|
||||
|
||||
// Move anything still climb in the specified direction.
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
if (comp.NextTransition == null)
|
||||
continue;
|
||||
|
||||
if (comp.NextTransition < curTime)
|
||||
{
|
||||
FinishTransition(uid, comp);
|
||||
continue;
|
||||
}
|
||||
|
||||
var xform = _xformQuery.GetComponent(uid);
|
||||
_xformSystem.SetLocalPositionNoLerp(uid, xform.LocalPosition + comp.Direction * frameTime, xform);
|
||||
}
|
||||
}
|
||||
|
||||
private void FinishTransition(EntityUid uid, ClimbingComponent comp)
|
||||
{
|
||||
// TODO: Validate climb here
|
||||
comp.NextTransition = null;
|
||||
_actionBlockerSystem.UpdateCanMove(uid);
|
||||
Dirty(uid, comp);
|
||||
|
||||
// Stop if necessary.
|
||||
if (!_fixturesQuery.TryGetComponent(uid, out var fixtures) ||
|
||||
!IsClimbing(uid, fixtures))
|
||||
{
|
||||
StopClimb(uid, comp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if entity currently has a valid vault.
|
||||
/// </summary>
|
||||
private bool IsClimbing(EntityUid uid, FixturesComponent? fixturesComp = null)
|
||||
{
|
||||
if (!_fixturesQuery.Resolve(uid, ref fixturesComp) || !fixturesComp.Fixtures.TryGetValue(ClimbingFixtureName, out var climbFixture))
|
||||
return false;
|
||||
|
||||
foreach (var contact in climbFixture.Contacts.Values)
|
||||
{
|
||||
var other = uid == contact.EntityA ? contact.EntityB : contact.EntityA;
|
||||
|
||||
if (HasComp<ClimbableComponent>(other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnMoveAttempt(EntityUid uid, ClimbingComponent component, UpdateCanMoveEvent args)
|
||||
{
|
||||
// Can't move when transition.
|
||||
if (component.NextTransition != null)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnParentChange(EntityUid uid, ClimbingComponent component, ref EntParentChangedMessage args)
|
||||
{
|
||||
if (component.NextTransition != null)
|
||||
{
|
||||
StopClimb(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCanDragDropOn(EntityUid uid, ClimbableComponent component, ref CanDropTargetEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
var canVault = args.User == args.Dragged
|
||||
? CanVault(component, args.User, uid, out _)
|
||||
: CanVault(component, args.User, args.Dragged, uid, out _);
|
||||
|
||||
args.CanDrop = canVault;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void AddClimbableVerb(EntityUid uid, ClimbableComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanMove(args.User))
|
||||
return;
|
||||
|
||||
if (!TryComp(args.User, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing)
|
||||
return;
|
||||
|
||||
// TODO VERBS ICON add a climbing icon?
|
||||
args.Verbs.Add(new AlternativeVerb
|
||||
{
|
||||
Act = () => TryClimb(args.User, args.User, args.Target, out _, component),
|
||||
Text = Loc.GetString("comp-climbable-verb-climb")
|
||||
});
|
||||
}
|
||||
|
||||
private void OnClimbableDragDrop(EntityUid uid, ClimbableComponent component, ref DragDropTargetEvent args)
|
||||
{
|
||||
// definitely a better way to check if two entities are equal
|
||||
// but don't have computer access and i have to do this without syntax
|
||||
if (args.Handled || args.User != args.Dragged && !HasComp<HandsComponent>(args.User))
|
||||
return;
|
||||
|
||||
TryClimb(args.User, args.Dragged, uid, out _, component);
|
||||
}
|
||||
|
||||
public bool TryClimb(
|
||||
EntityUid user,
|
||||
EntityUid entityToMove,
|
||||
EntityUid climbable,
|
||||
out DoAfterId? id,
|
||||
ClimbableComponent? comp = null,
|
||||
ClimbingComponent? climbing = null)
|
||||
{
|
||||
id = null;
|
||||
|
||||
if (!Resolve(climbable, ref comp) || !Resolve(entityToMove, ref climbing))
|
||||
return false;
|
||||
|
||||
// Note, IsClimbing does not mean a DoAfter is active, it means the target has already finished a DoAfter and
|
||||
// is currently on top of something..
|
||||
if (climbing.IsClimbing)
|
||||
return true;
|
||||
|
||||
var args = new DoAfterArgs(EntityManager, user, comp.ClimbDelay, new ClimbDoAfterEvent(),
|
||||
entityToMove,
|
||||
target: climbable,
|
||||
used: entityToMove)
|
||||
{
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnDamage = true
|
||||
};
|
||||
|
||||
_audio.PlayPredicted(comp.StartClimbSound, climbable, user);
|
||||
return _doAfterSystem.TryStartDoAfter(args, out id);
|
||||
}
|
||||
|
||||
private void OnDoAfter(EntityUid uid, ClimbingComponent component, ClimbDoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null)
|
||||
return;
|
||||
|
||||
Climb(uid, args.Args.User, args.Args.Target.Value, climbing: component);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void Climb(EntityUid uid, EntityUid user, EntityUid climbable, bool silent = false, ClimbingComponent? climbing = null,
|
||||
PhysicsComponent? physics = null, FixturesComponent? fixtures = null, ClimbableComponent? comp = null)
|
||||
{
|
||||
if (!Resolve(uid, ref climbing, ref physics, ref fixtures, false))
|
||||
return;
|
||||
|
||||
if (!Resolve(climbable, ref comp))
|
||||
return;
|
||||
|
||||
if (!ReplaceFixtures(uid, climbing, fixtures))
|
||||
return;
|
||||
|
||||
var xform = _xformQuery.GetComponent(uid);
|
||||
var (worldPos, worldRot) = _xformSystem.GetWorldPositionRotation(xform);
|
||||
var worldDirection = _xformSystem.GetWorldPosition(climbable) - worldPos;
|
||||
var distance = worldDirection.Length();
|
||||
var parentRot = (worldRot - xform.LocalRotation);
|
||||
// Need direction relative to climber's parent.
|
||||
var localDirection = (-parentRot).RotateVec(worldDirection);
|
||||
|
||||
climbing.IsClimbing = true;
|
||||
var climbDuration = TimeSpan.FromSeconds(distance / climbing.TransitionRate);
|
||||
climbing.NextTransition = _timing.CurTime + climbDuration;
|
||||
|
||||
climbing.Direction = localDirection.Normalized() * climbing.TransitionRate;
|
||||
Dirty(uid, climbing);
|
||||
|
||||
_audio.PlayPredicted(comp.FinishClimbSound, climbable, user);
|
||||
_actionBlockerSystem.UpdateCanMove(uid);
|
||||
|
||||
var startEv = new StartClimbEvent(climbable);
|
||||
var climbedEv = new ClimbedOnEvent(uid, user);
|
||||
RaiseLocalEvent(uid, ref startEv);
|
||||
RaiseLocalEvent(climbable, ref climbedEv);
|
||||
|
||||
if (silent)
|
||||
return;
|
||||
|
||||
string selfMessage;
|
||||
string othersMessage;
|
||||
|
||||
if (user == uid)
|
||||
{
|
||||
othersMessage = Loc.GetString("comp-climbable-user-climbs-other",
|
||||
("user", Identity.Entity(uid, EntityManager)),
|
||||
("climbable", climbable));
|
||||
|
||||
selfMessage = Loc.GetString("comp-climbable-user-climbs", ("climbable", climbable));
|
||||
}
|
||||
else
|
||||
{
|
||||
othersMessage = Loc.GetString("comp-climbable-user-climbs-force-other",
|
||||
("user", Identity.Entity(user, EntityManager)),
|
||||
("moved-user", Identity.Entity(uid, EntityManager)), ("climbable", climbable));
|
||||
|
||||
selfMessage = Loc.GetString("comp-climbable-user-climbs-force", ("moved-user", Identity.Entity(uid, EntityManager)),
|
||||
("climbable", climbable));
|
||||
}
|
||||
|
||||
_popupSystem.PopupEntity(othersMessage, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
|
||||
_popupSystem.PopupClient(selfMessage, uid, user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the current fixtures with non-climbing collidable versions so that climb end can be detected
|
||||
/// </summary>
|
||||
/// <returns>Returns whether adding the new fixtures was successful</returns>
|
||||
private bool ReplaceFixtures(EntityUid uid, ClimbingComponent climbingComp, FixturesComponent fixturesComp)
|
||||
{
|
||||
// Swap fixtures
|
||||
foreach (var (name, fixture) in fixturesComp.Fixtures)
|
||||
{
|
||||
if (climbingComp.DisabledFixtureMasks.ContainsKey(name)
|
||||
|| fixture.Hard == false
|
||||
|| (fixture.CollisionMask & ClimbingCollisionGroup) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
climbingComp.DisabledFixtureMasks.Add(name, fixture.CollisionMask & ClimbingCollisionGroup);
|
||||
_physics.SetCollisionMask(uid, name, fixture, fixture.CollisionMask & ~ClimbingCollisionGroup, fixturesComp);
|
||||
}
|
||||
|
||||
if (!_fixtureSystem.TryCreateFixture(
|
||||
uid,
|
||||
new PhysShapeCircle(0.35f),
|
||||
ClimbingFixtureName,
|
||||
collisionLayer: (int) CollisionGroup.None,
|
||||
collisionMask: ClimbingCollisionGroup,
|
||||
hard: false,
|
||||
manager: fixturesComp))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnClimbEndCollide(EntityUid uid, ClimbingComponent component, ref EndCollideEvent args)
|
||||
{
|
||||
if (args.OurFixtureId != ClimbingFixtureName
|
||||
|| !component.IsClimbing
|
||||
|| component.NextTransition != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var fixture in args.OurFixture.Contacts.Keys)
|
||||
{
|
||||
if (fixture == args.OtherFixture)
|
||||
continue;
|
||||
|
||||
// If still colliding with a climbable, do not stop climbing
|
||||
if (HasComp<ClimbableComponent>(args.OtherEntity))
|
||||
return;
|
||||
}
|
||||
|
||||
StopClimb(uid, component);
|
||||
}
|
||||
|
||||
private void StopClimb(EntityUid uid, ClimbingComponent? climbing = null, FixturesComponent? fixtures = null)
|
||||
{
|
||||
if (!Resolve(uid, ref climbing, ref fixtures, false))
|
||||
return;
|
||||
|
||||
foreach (var (name, fixtureMask) in climbing.DisabledFixtureMasks)
|
||||
{
|
||||
if (!fixtures.Fixtures.TryGetValue(name, out var fixture))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_physics.SetCollisionMask(uid, name, fixture, fixture.CollisionMask | fixtureMask, fixtures);
|
||||
}
|
||||
|
||||
climbing.DisabledFixtureMasks.Clear();
|
||||
_fixtureSystem.DestroyFixture(uid, ClimbingFixtureName, manager: fixtures);
|
||||
climbing.IsClimbing = false;
|
||||
climbing.NextTransition = null;
|
||||
var ev = new EndClimbEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
Dirty(uid, climbing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the user can vault the target
|
||||
/// </summary>
|
||||
/// <param name="component">The component of the entity that is being vaulted</param>
|
||||
/// <param name="user">The entity that wants to vault</param>
|
||||
/// <param name="target">The object that is being vaulted</param>
|
||||
/// <param name="reason">The reason why it cant be dropped</param>
|
||||
public bool CanVault(ClimbableComponent component, EntityUid user, EntityUid target, out string reason)
|
||||
{
|
||||
if (!_actionBlockerSystem.CanInteract(user, target))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-interact");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!HasComp<ClimbingComponent>(user)
|
||||
|| !TryComp(user, out BodyComponent? body)
|
||||
|| !_bodySystem.BodyHasPartType(user, BodyPartType.Leg, body)
|
||||
|| !_bodySystem.BodyHasPartType(user, BodyPartType.Foot, body))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-climb");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_interactionSystem.InRangeUnobstructed(user, target, component.Range))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-reach");
|
||||
return false;
|
||||
}
|
||||
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the user can vault the dragged entity onto the the target
|
||||
/// </summary>
|
||||
/// <param name="component">The climbable component of the object being vaulted onto</param>
|
||||
/// <param name="user">The user that wants to vault the entity</param>
|
||||
/// <param name="dragged">The entity that is being vaulted</param>
|
||||
/// <param name="target">The object that is being vaulted onto</param>
|
||||
/// <param name="reason">The reason why it cant be dropped</param>
|
||||
/// <returns></returns>
|
||||
public bool CanVault(ClimbableComponent component, EntityUid user, EntityUid dragged, EntityUid target,
|
||||
out string reason)
|
||||
{
|
||||
if (!_actionBlockerSystem.CanInteract(user, dragged) || !_actionBlockerSystem.CanInteract(user, target))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-interact");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!HasComp<ClimbingComponent>(dragged))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-climb");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Ignored(EntityUid entity) => entity == target || entity == user || entity == dragged;
|
||||
|
||||
if (!_interactionSystem.InRangeUnobstructed(user, target, component.Range, predicate: Ignored)
|
||||
|| !_interactionSystem.InRangeUnobstructed(user, dragged, component.Range, predicate: Ignored))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-reach");
|
||||
return false;
|
||||
}
|
||||
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ForciblySetClimbing(EntityUid uid, EntityUid climbable, ClimbingComponent? component = null)
|
||||
{
|
||||
Climb(uid, uid, climbable, true, component);
|
||||
}
|
||||
|
||||
private void OnBuckleChange(EntityUid uid, ClimbingComponent component, ref BuckleChangeEvent args)
|
||||
{
|
||||
if (!args.Buckling)
|
||||
return;
|
||||
StopClimb(uid, component);
|
||||
}
|
||||
|
||||
private void OnGlassClimbed(EntityUid uid, GlassTableComponent component, ref ClimbedOnEvent args)
|
||||
{
|
||||
if (TryComp<PhysicsComponent>(args.Climber, out var physics) && physics.Mass <= component.MassLimit)
|
||||
return;
|
||||
|
||||
_damageableSystem.TryChangeDamage(args.Climber, component.ClimberDamage, origin: args.Climber);
|
||||
_damageableSystem.TryChangeDamage(uid, component.TableDamage, origin: args.Climber);
|
||||
_stunSystem.TryParalyze(args.Climber, TimeSpan.FromSeconds(component.StunTime), true);
|
||||
|
||||
// Not shown to the user, since they already get a 'you climb on the glass table' popup
|
||||
_popupSystem.PopupEntity(
|
||||
Loc.GetString("glass-table-shattered-others", ("table", uid), ("climber", Identity.Entity(args.Climber, EntityManager))), args.Climber,
|
||||
Filter.PvsExcept(args.Climber), true);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed partial class ClimbDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
|
||||
doAfter.CancelledTime = doAfter.CancelledTime.Value + args.PausedTime;
|
||||
}
|
||||
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnStateChanged(EntityUid uid, DoAfterComponent component, MobStateChangedEvent args)
|
||||
@@ -55,7 +55,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
|
||||
{
|
||||
InternalCancel(doAfter, component);
|
||||
}
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,10 +63,12 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
|
||||
/// </summary>
|
||||
private void OnDamage(EntityUid uid, DoAfterComponent component, DamageChangedEvent args)
|
||||
{
|
||||
if (!args.InterruptsDoAfters || !args.DamageIncreased || args.DamageDelta == null)
|
||||
// If we're applying state then let the server state handle the do_after prediction.
|
||||
// This is to avoid scenarios where a do_after is erroneously cancelled on the final tick.
|
||||
if (!args.InterruptsDoAfters || !args.DamageIncreased || args.DamageDelta == null || GameTiming.ApplyingState)
|
||||
return;
|
||||
|
||||
var delta = args.DamageDelta?.Total;
|
||||
var delta = args.DamageDelta.GetTotal();
|
||||
|
||||
var dirty = false;
|
||||
foreach (var doAfter in component.DoAfters.Values)
|
||||
@@ -79,7 +81,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
|
||||
}
|
||||
|
||||
if (dirty)
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void RaiseDoAfterEvents(DoAfter doAfter, DoAfterComponent component)
|
||||
@@ -254,7 +256,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
|
||||
|
||||
comp.DoAfters.Add(doAfter.Index, doAfter);
|
||||
EnsureComp<ActiveDoAfterComponent>(args.User);
|
||||
Dirty(comp);
|
||||
Dirty(args.User, comp);
|
||||
args.Event.DoAfter = doAfter;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,51 @@
|
||||
namespace Content.Shared.DragDrop;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
namespace Content.Shared.DragDrop;
|
||||
|
||||
public abstract class SharedDragDropSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeAllEvent<DragDropRequestEvent>(OnDragDropRequestEvent);
|
||||
}
|
||||
|
||||
private void OnDragDropRequestEvent(DragDropRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
var dragged = GetEntity(msg.Dragged);
|
||||
var target = GetEntity(msg.Target);
|
||||
|
||||
if (Deleted(dragged) || Deleted(target))
|
||||
return;
|
||||
|
||||
var user = args.SenderSession.AttachedEntity;
|
||||
|
||||
if (user == null || !_actionBlockerSystem.CanInteract(user.Value, target))
|
||||
return;
|
||||
|
||||
// must be in range of both the target and the object they are drag / dropping
|
||||
// Client also does this check but ya know we gotta validate it.
|
||||
if (!_interaction.InRangeUnobstructed(user.Value, dragged, popup: true)
|
||||
|| !_interaction.InRangeUnobstructed(user.Value, target, popup: true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dragArgs = new DragDropDraggedEvent(user.Value, target);
|
||||
|
||||
// trigger dragdrops on the dropped entity
|
||||
RaiseLocalEvent(dragged, ref dragArgs);
|
||||
|
||||
if (dragArgs.Handled)
|
||||
return;
|
||||
|
||||
var dropArgs = new DragDropTargetEvent(user.Value, dragged);
|
||||
|
||||
// trigger dragdrops on the target entity (what you are dropping onto)
|
||||
RaiseLocalEvent(GetEntity(msg.Target), ref dropArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Administration.Managers;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Input;
|
||||
|
||||
Reference in New Issue
Block a user