Important fix for table climbing (#10803)

This commit is contained in:
Pieter-Jan Briers
2022-08-25 15:41:37 +02:00
committed by GitHub
parent 0e5e3b46c4
commit 84e20049b8
9 changed files with 110 additions and 2 deletions

View File

@@ -1,11 +1,14 @@
using Content.Server.Climbing.Components;
using Content.Server.DoAfter;
using Content.Server.Interaction.Components;
using Content.Server.Popups;
using Content.Server.Stunnable;
using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems;
using Content.Shared.ActionBlocker;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Buckle.Components;
using Content.Shared.CCVar;
using Content.Shared.Climbing;
using Content.Shared.Damage;
using Content.Shared.DragDrop;
@@ -16,17 +19,21 @@ using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
using Robust.Shared.GameStates;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using SharpZstd.Interop;
namespace Content.Server.Climbing;
[UsedImplicitly]
public sealed class ClimbSystem : SharedClimbSystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
@@ -34,6 +41,7 @@ public sealed class ClimbSystem : SharedClimbSystem
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
private const string ClimbingFixtureName = "climb";
private const int ClimbingCollisionGroup = (int) (CollisionGroup.TableLayer | CollisionGroup.LowImpassable);
@@ -80,6 +88,9 @@ public sealed class ClimbSystem : SharedClimbSystem
if (!args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanMove(args.User))
return;
if (component.Bonk && _cfg.GetCVar(CCVars.GameTableBonk))
return;
if (!TryComp(args.User, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing)
return;
@@ -102,6 +113,9 @@ public sealed class ClimbSystem : SharedClimbSystem
if (!TryComp(entityToMove, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing)
return;
if (TryBonk(component, user))
return;
_doAfterSystem.DoAfter(new DoAfterEventArgs(entityToMove, component.ClimbDelay, default, climbable)
{
BreakOnTargetMove = true,
@@ -112,6 +126,33 @@ public sealed class ClimbSystem : SharedClimbSystem
});
}
private bool TryBonk(ClimbableComponent component, EntityUid user)
{
if (!component.Bonk)
return false;
if (!_cfg.GetCVar(CCVars.GameTableBonk))
{
// Not set to always bonk, try clumsy roll.
if (!TryComp(user, out ClumsyComponent? clumsy))
return false;
if (!clumsy.RollClumsy(component.BonkClumsyChance))
return false;
}
// BONK!
_audioSystem.PlayPvs(component.BonkSound, component.Owner);
_stunSystem.TryKnockdown(user, TimeSpan.FromSeconds(component.BonkTime), true);
if (component.BonkDamage is { } bonkDmg)
_damageableSystem.TryChangeDamage(user, bonkDmg, true);
return true;
}
private void OnClimbFinished(EntityUid uid, ClimbingComponent climbing, ClimbFinishedEvent args)
{
Climb(uid, args.User, args.Climbable, climbing: climbing);