Skip to content
Draft
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
1 change: 1 addition & 0 deletions Content.Client/Fluids/PuddleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private void OnPuddleAppearance(EntityUid uid, PuddleComponent component, ref Ap
}
}


var baseColor = Color.White;

if (args.AppearanceData.TryGetValue(PuddleVisuals.SolutionColor, out var colorObj))
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Body/Systems/RespiratorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public override void Update(float frameTime)
}
}



if (respirator.Saturation < respirator.SuffocationThreshold)
{
if (_gameTiming.CurTime >= respirator.LastGaspEmoteTime + respirator.GaspEmoteCooldown)
Expand Down Expand Up @@ -141,6 +143,9 @@ public void Inhale(Entity<RespiratorComponent?> entity)
if (!Resolve(entity, ref entity.Comp, logMissing: false))
return;

if (HasComp<NotBreathingComponent>(entity))
return;

// Inhale gas
var ev = new InhaleLocationEvent
{
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Containers/NotBreathingComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Body.Components;

[NetworkedComponent, RegisterComponent]
public sealed partial class NotBreathingComponent : Component; // prevents breathing


5 changes: 5 additions & 0 deletions Content.Shared/Fluids/Components/PuddleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.FixedPoint;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Content.Shared.Atmos;

namespace Content.Shared.Fluids.Components
{
Expand All @@ -28,6 +29,10 @@ public sealed partial class PuddleComponent : Component
[ViewVariables]
public Entity<SolutionComponent>? Solution;

// amount before someone can drown in a puddle, for some reason the U required to is double this amount.
[DataField]
public FixedPoint2 DrownU = FixedPoint2.New(100);

[DataField]
public bool AffectsMovement = true;

Expand Down
65 changes: 65 additions & 0 deletions Content.Shared/Fluids/SharedPuddleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Linq;
using System.Threading;
using Content.Shared.Administration.Logs;
using Content.Shared.Atmos.Components;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
Expand All @@ -24,11 +26,28 @@
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Content.Shared.Body.Components;
using Robust.Shared.Physics.Events;
using Content.Shared.Clothing;

namespace Content.Shared.Fluids;

public abstract partial class SharedPuddleSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
[Dependency] protected readonly OpenableSystem Openable = default!;
[Dependency] protected readonly ReactiveSystem Reactive = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] protected readonly SharedPopupSystem Popups = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly SpeedModifierContactsSystem _speedModContacts = default!;
[Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
[Dependency] private readonly TileFrictionController _tile = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private IGameTiming _timing = default!;
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] protected ISharedAdminLogManager AdminLogger = default!;
Expand Down Expand Up @@ -71,6 +90,9 @@ public override void Initialize()
SubscribeLocalEvent<PuddleComponent, GetFootstepSoundEvent>(OnGetFootstepSound);
SubscribeLocalEvent<PuddleComponent, ExaminedEvent>(HandlePuddleExamined);
SubscribeLocalEvent<PuddleComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
SubscribeLocalEvent<PuddleComponent, StartCollideEvent>(DrowningStart);
SubscribeLocalEvent<PuddleComponent, EndCollideEvent>(DrowningEnd);
SubscribeLocalEvent<PuddleComponent, ItemMaskToggledEvent>(DrowningInternalsCheck);

SubscribeLocalEvent<EvaporationComponent, MapInitEvent>(OnEvaporationMapInit);

Expand Down Expand Up @@ -176,6 +198,49 @@ private void HandlePuddleExamined(Entity<PuddleComponent> entity, ref ExaminedEv
}
}

// Todo more water levels (if flooded and can drown people, hide stuff inside tile)

private void DrowningInternalsCheck(Entity<PuddleComponent> entity, ref ItemMaskToggledEvent arg)
{
var uid = entity;
var nearbyEntities = _entityLookup.GetEntitiesInRange<NotBreathingComponent>(Transform(uid).Coordinates, 1f);

foreach (var ent in nearbyEntities)
{
if (HasComp<BreathToolComponent>(ent))
{
RemComp<NotBreathingComponent>(ent);
}
else if (!HasComp<BreathToolComponent>(ent))
{
AddComp<NotBreathingComponent>(ent);
}
}
}

private void DrowningStart(Entity<PuddleComponent> entity, ref StartCollideEvent arg)
{
if (HasComp<BreathToolComponent>(arg.OtherEntity))
{
RemComp<NotBreathingComponent>(arg.OtherEntity);
return;
}

var (uid, puddle) = entity;
if (!_solutionContainerSystem.ResolveSolution(uid, puddle.SolutionName, ref puddle.Solution, out var solution))
return;

if (solution.Volume < puddle.DrownU)
return;

EnsureComp<NotBreathingComponent>(arg.OtherEntity);
}

private void DrowningEnd(Entity<PuddleComponent> entity, ref EndCollideEvent arg)
{
RemComp<NotBreathingComponent>(arg.OtherEntity);
}

private void OnAnchorChanged(Entity<PuddleComponent> entity, ref AnchorStateChangedEvent args)
{
if (!args.Anchored)
Expand Down
Loading