Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anti-Hubbie Table Climbing #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Content.Shared/Climbing/Components/BonkableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
using Content.Shared.Damage;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;

namespace Content.Shared.Climbing.Components;

/// <summary>
/// Makes entity do damage and stun entities with ClumsyComponent
/// upon DragDrop or Climb interactions.
/// Adds functionality for a climbable entity to damage and stun entities who attempt to
/// climb it (DragDrop or Climb interactions) under various circumstances.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class BonkableComponent : Component
{
/// <summary>
/// Whether every time you try to climb this thing, you just hit your head instead.
/// </summary>
[DataField("riggedForBonk")]
public bool RiggedForBonk = false;

/// <summary>
/// How long to stun players on bonk, in seconds.
/// </summary>
Expand All @@ -21,4 +28,10 @@ public sealed partial class BonkableComponent : Component
/// </summary>
[DataField]
public DamageSpecifier? BonkDamage;

/// <summary>
/// Sound to be played when a bonk happens.
/// </summary>
[DataField("bonkSound")]
public SoundSpecifier? BonkSound = null;
}
34 changes: 34 additions & 0 deletions Content.Shared/Climbing/Systems/ClimbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Content.Shared.Traits.Assorted.Components;
using Content.Shared.Verbs;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
Expand All @@ -41,20 +42,26 @@ public sealed partial class ClimbSystem : VirtualController
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
[Dependency] private readonly SharedStunSystem _stun = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly INetManager _net = default!;

private const string ClimbingFixtureName = "climb";
private const int ClimbingCollisionGroup = (int) (CollisionGroup.TableLayer | CollisionGroup.LowImpassable);

private EntityQuery<FixturesComponent> _fixturesQuery;
private EntityQuery<TransformComponent> _xformQuery;
private EntityQuery<ClimbableComponent> _climbableQuery;
private EntityQuery<BonkableComponent> _bonkableQuery;

public override void Initialize()
{
base.Initialize();

_fixturesQuery = GetEntityQuery<FixturesComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
_climbableQuery = GetEntityQuery<ClimbableComponent>();
_bonkableQuery = GetEntityQuery<BonkableComponent>();

SubscribeLocalEvent<ClimbingComponent, UpdateCanMoveEvent>(OnMoveAttempt);
SubscribeLocalEvent<ClimbingComponent, EntParentChangedMessage>(OnParentChange);
Expand Down Expand Up @@ -218,6 +225,33 @@ public bool TryClimb(
if (ev.Cancelled)
return false;

if (_bonkableQuery.TryGetComponent(climbable, out var bonkable) && bonkable.RiggedForBonk)
{
// Improvement suggestion: consolidate this "bonk" function with that in ClumsySystem.

// Note: the stun has no prediction yet so to avoid double-stun animation let's just make
// sure it doesn't attempt to predict this.
if (_net.IsServer)
{
var stunTime = bonkable.BonkTime;
_stun.TryParalyze(entityToMove, stunTime, true);
}

_audio.PlayPredicted(bonkable.BonkSound, entityToMove, entityToMove);
if (bonkable.BonkDamage != null)
{
_damageable.TryChangeDamage(entityToMove, bonkable.BonkDamage, true);
}

var selfMessage = Loc.GetString("comp-climbable-rigged-for-bonk", ("climbable", climbable));
var othersMessage = Loc.GetString("comp-climbable-rigged-for-bonk-other",
("user", Identity.Entity(entityToMove, EntityManager)),
("climbable", climbable));
_popupSystem.PopupPredicted(selfMessage, othersMessage, entityToMove, entityToMove);

return false;
}

var climbDelay = comp.ClimbDelay;
if (user == entityToMove && TryComp<ClimbDelayModifierComponent>(user, out var delayModifier))
climbDelay *= delayModifier.ClimbDelayMultiplier;
Expand Down
Binary file added Resources/Audio/Effects/table_bonk1.ogg
Binary file not shown.
Binary file added Resources/Audio/Effects/table_bonk2.ogg
Binary file not shown.
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/climbing/climbable-component.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ comp-climbable-cant-climb = You are incapable of climbing!

# Shown to you when your character tries to force someone else who can't climb onto a climbable
comp-climbable-target-cant-climb = { CAPITALIZE(THE($moved-user)) } can't go there!

# Shown when you try to climb something but it's rigged to bonk you
comp-climbable-rigged-for-bonk = You bang your head on { THE($climbable) }.

# Shown to others when you try to climb something but it's rigged to bonk you
comp-climbable-rigged-for-bonk-other = { CAPITALIZE(THE($user)) } bangs { POSS-ADJ($user) } head on { THE($climbable) }.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
base: state_
- type: Climbable
- type: Bonkable
riggedForBonk: true
bonkDamage:
types:
Blunt: 4
bonkSound:
collection: TableBonkSounds
- type: Clickable
- type: FootstepModifier
footstepSoundCollection:
Expand All @@ -57,3 +60,9 @@
- TableMask
layer:
- TableLayer

- type: soundCollection
id: TableBonkSounds
files:
- /Audio/Effects/table_bonk1.ogg
- /Audio/Effects/table_bonk2.ogg
Loading