Skip to content

Commit

Permalink
Allow Crawling Entities To Go Under Tables (#939)
Browse files Browse the repository at this point in the history
# Description

Adds a CVAR that when enabled, allows entities to crawl under
tables/flaps by lowering their DrawDepth, which in turn protects them
from being targeted for projectiles while crawling.

Additionally tables and plastic flaps were given collision properties
along with reduced damage thresholds, so guns can target & destroy them
easily if your mouse is on top of them.

---

<h1>Media</h1>
<p>


https://github.com/user-attachments/assets/77a04198-11cb-4895-bf2d-6f82b7f2bb5b

</p>
</details>

---

# Changelog

:cl:
- add: Adds an optional server variable which allows entities to crawl
under tables.
- tweak: Tables and plastic flaps are less resistant to damage, and can
now be targeted by guns by aiming on top of them.

---------

Signed-off-by: gluesniffler <[email protected]>
Co-authored-by: VMSolidus <[email protected]>
  • Loading branch information
gluesniffler and VMSolidus committed Sep 20, 2024
1 parent c1aef1b commit b01ae70
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 16 deletions.
26 changes: 26 additions & 0 deletions Content.Client/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Timing;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;

namespace Content.Client.Standing;

Expand All @@ -20,6 +21,8 @@ public override void Initialize()
base.Initialize();

SubscribeLocalEvent<LayingDownComponent, MoveEvent>(OnMovementInput);
SubscribeNetworkEvent<DrawDownedEvent>(OnDowned);
SubscribeLocalEvent<LayingDownComponent, StoodEvent>(OnStood);

SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}
Expand Down Expand Up @@ -48,6 +51,29 @@ private void OnMovementInput(EntityUid uid, LayingDownComponent component, MoveE
sprite.Rotation = Angle.FromDegrees(90);
}

private void OnDowned(DrawDownedEvent args)
{
var uid = GetEntity(args.Uid);

if (!TryComp<SpriteComponent>(uid, out var sprite)
|| !TryComp<LayingDownComponent>(uid, out var component))
return;

if (!component.OriginalDrawDepth.HasValue)
component.OriginalDrawDepth = sprite.DrawDepth;

sprite.DrawDepth = (int) DrawDepth.SmallMobs;
}

private void OnStood(EntityUid uid, LayingDownComponent component, StoodEvent args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite)
|| !component.OriginalDrawDepth.HasValue)
return;

sprite.DrawDepth = component.OriginalDrawDepth.Value;
}

private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args)
{
if (!_timing.IsFirstTimePredicted)
Expand Down
18 changes: 18 additions & 0 deletions Content.Server/Flight/FlightSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Flight.Events;
using Content.Shared.Mobs;
using Content.Shared.Popups;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Content.Shared.Zombies;
using Robust.Shared.Audio.Systems;
Expand All @@ -16,6 +17,7 @@ public sealed class FlightSystem : SharedFlightSystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;

public override void Initialize()
{
Expand All @@ -27,6 +29,7 @@ public override void Initialize()
SubscribeLocalEvent<FlightComponent, EntityZombifiedEvent>(OnZombified);
SubscribeLocalEvent<FlightComponent, KnockedDownEvent>(OnKnockedDown);
SubscribeLocalEvent<FlightComponent, StunnedEvent>(OnStunned);
SubscribeLocalEvent<FlightComponent, DownedEvent>(OnDowned);
SubscribeLocalEvent<FlightComponent, SleepStateChangedEvent>(OnSleep);
}
public override void Update(float frameTime)
Expand Down Expand Up @@ -103,6 +106,13 @@ private bool CanFly(EntityUid uid, FlightComponent component)
_popupSystem.PopupEntity(Loc.GetString("no-flight-while-zombified"), uid, uid, PopupType.Medium);
return false;
}

if (HasComp<StandingStateComponent>(uid) && _standing.IsDown(uid))
{
_popupSystem.PopupEntity(Loc.GetString("no-flight-while-lying"), uid, uid, PopupType.Medium);
return false;
}

return true;
}

Expand Down Expand Up @@ -142,6 +152,14 @@ private void OnStunned(EntityUid uid, FlightComponent component, ref StunnedEven
ToggleActive(uid, false, component);
}

private void OnDowned(EntityUid uid, FlightComponent component, ref DownedEvent args)
{
if (!component.On)
return;

ToggleActive(uid, false, component);
}

private void OnSleep(EntityUid uid, FlightComponent component, ref SleepStateChangedEvent args)
{
if (!component.On
Expand Down
12 changes: 10 additions & 2 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2470,9 +2470,16 @@ public static readonly CVarDef<float>

public static readonly CVarDef<bool> HoldLookUp =
CVarDef.Create("rest.hold_look_up", false, CVar.CLIENT | CVar.ARCHIVE);


/// <summary>
/// When true, entities that fall to the ground will be able to crawl under tables and
/// plastic flaps, allowing them to take cover from gunshots.
/// </summary>
public static readonly CVarDef<bool> CrawlUnderTables =
CVarDef.Create("rest.crawlundertables", false, CVar.REPLICATED);

#endregion

#region Material Reclaimer

/// <summary>
Expand All @@ -2498,5 +2505,6 @@ public static readonly CVarDef<float>
CVarDef.Create("jetpack.enable_in_no_gravity", true, CVar.REPLICATED);

#endregion

}
}
9 changes: 9 additions & 0 deletions Content.Shared/Standing/LayingDownComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public sealed partial class LayingDownComponent : Component

[DataField, AutoNetworkedField]
public bool AutoGetUp;

[DataField, AutoNetworkedField]
public int? OriginalDrawDepth { get; set; }
}

[Serializable, NetSerializable]
Expand All @@ -24,3 +27,9 @@ public sealed class CheckAutoGetUpEvent(NetEntity user) : CancellableEntityEvent
{
public NetEntity User = user;
}

[Serializable, NetSerializable]
public sealed class DrawDownedEvent(NetEntity uid) : EntityEventArgs
{
public NetEntity Uid = uid;
}
8 changes: 8 additions & 0 deletions Content.Shared/Standing/StandingStateSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.CCVar;
using Content.Shared.Hands.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Physics;
using Content.Shared.Rotation;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;

namespace Content.Shared.Standing;

Expand All @@ -17,6 +20,7 @@ public sealed class StandingStateSystem : EntitySystem
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
[Dependency] private readonly IConfigurationManager _config = default!;

// If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited.
private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable;
Expand Down Expand Up @@ -64,6 +68,10 @@ public bool Down(EntityUid uid, bool playSound = true, bool dropHeldItems = true
Dirty(standingState);
RaiseLocalEvent(uid, new DownedEvent(), false);

// Raising this event will lower the entity's draw depth to the same as a small mob.
if (_config.GetCVar(CCVars.CrawlUnderTables))
RaiseNetworkEvent(new DrawDownedEvent(GetNetEntity(uid)));

// Seemed like the best place to put it
_appearance.SetData(uid, RotationVisuals.RotationState, RotationState.Horizontal, appearance);

Expand Down
3 changes: 2 additions & 1 deletion Resources/Locale/en-US/flight/flight_system.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
no-flight-while-restrained = You can't fly right now.
no-flight-while-zombified = You can't use your wings right now.
no-flight-while-zombified = You can't use your wings right now.
no-flight-while-lying = You can't fly right now.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- TableMask
layer:
- TableLayer
- BulletImpassable
- type: SpriteFade
- type: Sprite
- type: Icon
Expand All @@ -38,7 +39,8 @@
- type: FootstepModifier
footstepSoundCollection:
collection: FootstepHull

- type: RequireProjectileTarget

- type: entity
id: CounterBase
parent: TableBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
acts: [ "Destruction" ]
- trigger:
!type:DamageTrigger
damage: 25
damage: 15
behaviors:
- !type:PlaySoundBehavior
sound:
Expand Down Expand Up @@ -178,7 +178,7 @@
acts: [ "Destruction" ]
- trigger:
!type:DamageTrigger
damage: 25
damage: 15
behaviors:
- !type:PlaySoundBehavior
sound:
Expand Down Expand Up @@ -216,7 +216,7 @@
acts: [ "Destruction" ]
- trigger:
!type:DamageTrigger
damage: 75
damage: 30
behaviors:
- !type:PlaySoundBehavior
sound:
Expand Down Expand Up @@ -263,7 +263,7 @@
thresholds:
- trigger:
!type:DamageTrigger
damage: 25
damage: 15
behaviors:
- !type:DoActsBehavior
acts: [ "Destruction" ]
Expand Down Expand Up @@ -379,7 +379,7 @@
collection: GlassBreak
- trigger:
!type:DamageTrigger
damage: 50
damage: 30
behaviors:
- !type:PlaySoundBehavior
sound:
Expand Down Expand Up @@ -426,7 +426,7 @@
acts: [ "Destruction" ]
- trigger:
!type:DamageTrigger
damage: 25
damage: 40
behaviors:
- !type:PlaySoundBehavior
sound:
Expand Down Expand Up @@ -546,7 +546,7 @@
thresholds:
- trigger:
!type:DamageTrigger
damage: 50
damage: 40
behaviors:
- !type:PlaySoundBehavior
sound:
Expand All @@ -573,7 +573,7 @@
thresholds:
- trigger:
!type:DamageTrigger
damage: 50
damage: 20
behaviors:
- !type:DoActsBehavior
acts: [ "Destruction" ]
Expand Down
11 changes: 7 additions & 4 deletions Resources/Prototypes/Entities/Structures/plastic_flaps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
- TabletopMachineMask
layer:
- MidImpassable
- BulletImpassable
- type: Damageable
damageContainer: StructuralInorganic
damageModifierSet: Metallic
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 100
damage: 50
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
Expand All @@ -45,7 +46,8 @@
node: plasticFlaps
- type: StaticPrice
price: 83

- type: RequireProjectileTarget

- type: entity
id: PlasticFlapsOpaque
parent: PlasticFlapsClear
Expand All @@ -65,6 +67,7 @@
layer:
- Opaque
- MidImpassable
- BulletImpassable
- type: Occluder
- type: Construction
graph: PlasticFlapsGraph
Expand All @@ -81,7 +84,7 @@
thresholds:
- trigger:
!type:DamageTrigger
damage: 150
damage: 75
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
Expand All @@ -103,7 +106,7 @@
thresholds:
- trigger:
!type:DamageTrigger
damage: 150
damage: 75
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
Expand Down

0 comments on commit b01ae70

Please sign in to comment.