Separated Bonk functionality and component from ClimbSystem and ClimbComponent (#13635)

This commit is contained in:
Ilya Chvilyov
2023-02-01 00:33:00 +03:00
committed by GitHub
parent f81a25e585
commit eae58211e1
12 changed files with 141 additions and 90 deletions

View File

@@ -8,7 +8,6 @@ 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.Climbing.Events;
using Content.Shared.Damage;
@@ -46,6 +45,7 @@ public sealed class ClimbSystem : SharedClimbSystem
[Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly BonkSystem _bonkSystem = default!;
private const string ClimbingFixtureName = "climb";
private const int ClimbingCollisionGroup = (int) (CollisionGroup.TableLayer | CollisionGroup.LowImpassable);
@@ -92,9 +92,6 @@ 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;
@@ -117,7 +114,7 @@ public sealed class ClimbSystem : SharedClimbSystem
if (!TryComp(entityToMove, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing)
return;
if (TryBonk(component, user))
if (_bonkSystem.TryBonk(entityToMove, climbable))
return;
_doAfterSystem.DoAfter(new DoAfterEventArgs(user, component.ClimbDelay, default, climbable, entityToMove)
@@ -130,29 +127,6 @@ 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 (!_interactionSystem.TryRollClumsy(user, component.BonkClumsyChance))
return false;
}
// BONK!
_audioSystem.PlayPvs(component.BonkSound, component.Owner);
_stunSystem.TryParalyze(user, TimeSpan.FromSeconds(component.BonkTime), true);
if (component.BonkDamage is { } bonkDmg)
_damageableSystem.TryChangeDamage(user, bonkDmg, true, origin: user);
return true;
}
private void OnClimbFinished(EntityUid uid, ClimbingComponent climbing, ClimbFinishedEvent args)
{
Climb(uid, args.User, args.Instigator, args.Climbable, climbing: climbing);

View File

@@ -1,15 +0,0 @@
using Content.Shared.Damage;
namespace Content.Server.Interaction.Components
{
/// <summary>
/// A simple clumsy tag-component.
/// </summary>
[RegisterComponent]
public sealed class ClumsyComponent : Component
{
[DataField("clumsyDamage", required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier ClumsyDamage = default!;
}
}

View File

@@ -1,25 +0,0 @@
using Content.Server.Interaction.Components;
using Robust.Shared.Random;
namespace Content.Server.Interaction;
public sealed partial class InteractionSystem
{
public bool RollClumsy(ClumsyComponent component, float chance)
{
return component.Running && _random.Prob(chance);
}
/// <summary>
/// Rolls a probability chance for a "bad action" if the target entity is clumsy.
/// </summary>
/// <param name="entity">The entity that the clumsy check is happening for.</param>
/// <param name="chance">
/// The chance that a "bad action" happens if the user is clumsy, between 0 and 1 inclusive.
/// </param>
/// <returns>True if a "bad action" happened, false if the normal action should happen.</returns>
public bool TryRollClumsy(EntityUid entity, float chance, ClumsyComponent? component = null)
{
return Resolve(entity, ref component, false) && RollClumsy(component, chance);
}
}

View File

@@ -2,7 +2,6 @@ using System.Linq;
using Content.Server.Cargo.Systems;
using Content.Server.Examine;
using Content.Server.Interaction;
using Content.Server.Interaction.Components;
using Content.Server.Stunnable;
using Content.Server.Weapons.Melee;
using Content.Server.Weapons.Ranged.Components;
@@ -10,6 +9,7 @@ using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction.Components;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Ranged;