Skip to content

Commit

Permalink
Merge pull request #610 from fospas/clawling
Browse files Browse the repository at this point in the history
[PORT] Vent crawling
  • Loading branch information
CrimeMoot authored and PvrG committed Dec 1, 2024
1 parent 511c129 commit 219d1df
Show file tree
Hide file tree
Showing 61 changed files with 1,280 additions and 7 deletions.
23 changes: 22 additions & 1 deletion Content.Client/SubFloor/SubFloorHideSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Atmos.Components;
using Content.Shared.DrawDepth;
using Content.Shared.SubFloor;
using Robust.Client.GameObjects;
Expand All @@ -9,6 +10,7 @@ public sealed class SubFloorHideSystem : SharedSubFloorHideSystem
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;

private bool _showAll;
private bool _showVentPipe;

[ViewVariables(VVAccess.ReadWrite)]
public bool ShowAll
Expand All @@ -23,6 +25,19 @@ public bool ShowAll
}
}

[ViewVariables(VVAccess.ReadWrite)]
public bool ShowVentPipe
{
get => _showVentPipe;
set
{
if (_showVentPipe == value) return;
_showVentPipe = value;

UpdateAll();
}
}

public override void Initialize()
{
base.Initialize();
Expand All @@ -40,7 +55,13 @@ private void OnAppearanceChanged(EntityUid uid, SubFloorHideComponent component,

scannerRevealed &= !ShowAll; // no transparency for show-subfloor mode.

var revealed = !covered || ShowAll || scannerRevealed;
var showVentPipe = false;
if (HasComp<PipeAppearanceComponent>(uid))
{
showVentPipe = ShowVentPipe;
}

var revealed = !covered || ShowAll || scannerRevealed || showVentPipe;

// set visibility & color of each layer
foreach (var layer in args.Sprite.AllLayers)
Expand Down
33 changes: 33 additions & 0 deletions Content.Client/VentCraw/VentCrawVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Content.Client.SubFloor;
using Content.Shared.VentCraw;
using Robust.Client.Player;
using Robust.Shared.Timing;

namespace Content.Client.VentCraw;

public sealed class VentCrawSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly SubFloorHideSystem _subFloorHideSystem = default!;

public override void Update(float frameTime)
{
base.Update(frameTime);

if (!_timing.IsFirstTimePredicted)
return;

var player = _player.LocalPlayer?.ControlledEntity;

var ventCraslerQuery = GetEntityQuery<VentCrawlerComponent>();

if (!ventCraslerQuery.TryGetComponent(player, out var playerVentCrawlerComponent))
{
_subFloorHideSystem.ShowVentPipe = false;
return;
}

_subFloorHideSystem.ShowVentPipe = playerVentCrawlerComponent.InTube;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Content.Server.DeviceNetwork.Systems;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Server.Tools;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Monitor.Components;
using Content.Server.Atmos.Monitor.Systems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Unary.Components;
Expand All @@ -10,6 +9,7 @@
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Server.Tools;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Visuals;
using Content.Shared.Atmos.Monitor;
Expand Down
106 changes: 106 additions & 0 deletions Content.Server/VentCraw/BeingVentCrawSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Content.Server.Ghost;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Systems;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Mind;
using Content.Shared.Mobs;
using Content.Shared.VentCraw.Components;
using Robust.Shared.Player;

namespace Content.Server.VentCraw;

public sealed class BeingVentCrawSystem : EntitySystem
{
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
[Dependency] private readonly IEntityManager _entities = default!;

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

SubscribeLocalEvent<BeingVentCrawComponent, InhaleLocationEvent>(OnInhaleLocation);
SubscribeLocalEvent<BeingVentCrawComponent, ExhaleLocationEvent>(OnExhaleLocation);
SubscribeLocalEvent<BeingVentCrawComponent, AtmosExposedGetAirEvent>(OnGetAir);
SubscribeLocalEvent<BeingVentCrawComponent, MobStateChangedEvent>(OnMobStateChanged);
}

private void OnMobStateChanged(EntityUid uid, BeingVentCrawComponent component, MobStateChangedEvent args)
{
if (args.NewMobState != MobState.Dead || args.OldMobState != MobState.Critical)
return;

if (TryComp<ActorComponent>(uid, out var actor))
{
var session = actor.PlayerSession;

var minds = _entities.System<SharedMindSystem>();
if (!minds.TryGetMind(session, out var mindId, out var mind))
{
mindId = minds.CreateMind(session.UserId);
mind = _entities.GetComponent<MindComponent>(mindId);
}

_entities.System<GhostSystem>().OnGhostAttempt(mindId, true, true, mind);
}
}

private void OnGetAir(EntityUid uid, BeingVentCrawComponent component, ref AtmosExposedGetAirEvent args)
{
if (!TryComp<VentCrawHolderComponent>(component.Holder, out var holder))
return;

if (holder.CurrentTube == null)
return;

if (!TryComp(holder.CurrentTube.Value, out NodeContainerComponent? nodeContainer))
return;
foreach (var nodeContainerNode in nodeContainer.Nodes)
{
if (!_nodeContainer.TryGetNode(nodeContainer, nodeContainerNode.Key, out PipeNode? pipe))
continue;
args.Gas = pipe.Air;
args.Handled = true;
return;
}
}

private void OnInhaleLocation(EntityUid uid, BeingVentCrawComponent component, InhaleLocationEvent args)
{
if (!TryComp<VentCrawHolderComponent>(component.Holder, out var holder))
return;

if (holder.CurrentTube == null)
return;

if (!TryComp(holder.CurrentTube.Value, out NodeContainerComponent? nodeContainer))
return;
foreach (var nodeContainerNode in nodeContainer.Nodes)
{
if (!_nodeContainer.TryGetNode(nodeContainer, nodeContainerNode.Key, out PipeNode? pipe))
continue;
args.Gas = pipe.Air;
return;
}
}

private void OnExhaleLocation(EntityUid uid, BeingVentCrawComponent component, ExhaleLocationEvent args)
{
if (!TryComp<VentCrawHolderComponent>(component.Holder, out var holder))
return;

if (holder.CurrentTube == null)
return;

if (!TryComp(holder.CurrentTube.Value, out NodeContainerComponent? nodeContainer))
return;
foreach (var nodeContainerNode in nodeContainer.Nodes)
{
if (!_nodeContainer.TryGetNode(nodeContainer, nodeContainerNode.Key, out PipeNode? pipe))
continue;
args.Gas = pipe.Air;
return;
}
}
}
26 changes: 26 additions & 0 deletions Content.Server/VentCraw/VentCrawClothingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Content.Shared.Clothing;
using Content.Shared.VentCraw.Components;
using Content.Shared.VentCraw;

namespace Content.Server.VentCraw;

public sealed class VentCrawClothingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<VentCrawClothingComponent, ClothingGotEquippedEvent>(OnClothingEquip);
SubscribeLocalEvent<VentCrawClothingComponent, ClothingGotUnequippedEvent>(OnClothingUnequip);
}

private void OnClothingEquip(Entity<VentCrawClothingComponent> ent, ref ClothingGotEquippedEvent args)
{
AddComp<VentCrawlerComponent>(args.Wearer);
}

private void OnClothingUnequip(Entity<VentCrawClothingComponent> ent, ref ClothingGotUnequippedEvent args)
{
RemComp<VentCrawlerComponent>(args.Wearer);
}
}
Loading

0 comments on commit 219d1df

Please sign in to comment.