Skip to content

Commit

Permalink
[Fix] Mood cool fixes (#916)
Browse files Browse the repository at this point in the history
* Fix Overlays (#756)

Overlays have a funny bug where the calls to update them are global.
Meaning if any single person gets a bad enough mood to greyscale
themselves, everyone globally gets greyscaled. This bug was also present
on Dogvision and Ultravision, and had the same cause. Frontier luckily
had a fix for those two, and the fix works here as well for the Mood
Overlay.

:cl:
- fix: Fixed an issue where Overlays(Dogvision, Ultravision, Mood) would
apply globally to all entities when updating.

* MoodSystem Crit Threshold CVar (#1010)

This PR adds a CVar that allows server hosts (such as N14 who need it)
to optionally disable the Crit Threshold modification part of the
MoodSystem. This is useful if a server has some other system that
frequently messes with Thresholds, and that a server host wishes their
system to not have to fight with Mood for it.

No changelog because this isn't playerfacing.

* Update SaturationScaleOverlay.cs

---------

Co-authored-by: VMSolidus <[email protected]>
  • Loading branch information
Roudenn and VMSolidus authored Nov 12, 2024
1 parent f58da43 commit 3c5d93c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
22 changes: 18 additions & 4 deletions Content.Client/Backmen/Overlays/Shaders/SaturationScaleOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Robust.Client.Graphics;
using System.Numerics;
using Content.Shared.Backmen.Overlays;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;

Expand All @@ -7,6 +10,8 @@ namespace Content.Client.Backmen.Overlays.Shaders;
public sealed class SaturationScaleOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] IEntityManager _entityManager = default!;

public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
Expand All @@ -18,20 +23,29 @@ public SaturationScaleOverlay()
{
IoCManager.InjectDependencies(this);

_shader = _prototypeManager.Index<ShaderPrototype>("SaturationScale").InstanceUnique();
_shader = _prototypeManager.Index<ShaderPrototype>("SaturationScale").Instance().Duplicate();
}

protected override bool BeforeDraw(in OverlayDrawArgs args)
{
if (_playerManager.LocalEntity is not { Valid: true } player
|| !_entityManager.HasComponent<SaturationScaleOverlayComponent>(player))
return false;

return base.BeforeDraw(in args);
}


protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
if (ScreenTexture is null)
return;

_shader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
_shader.SetParameter("saturation", Saturation);

var handle = args.WorldHandle;

handle.SetTransform(Matrix3x2.Identity);
handle.UseShader(_shader);
handle.DrawRect(args.WorldBounds, Color.White);
handle.UseShader(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
using Content.Shared.Backmen.Overlays;
using Content.Shared.GameTicking;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;

namespace Content.Client.Backmen.Overlays.Systems;

public sealed class SaturationScaleSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly ISharedPlayerManager _playerMan = default!;

private SaturationScaleOverlay _overlay = default!;

Expand Down Expand Up @@ -48,15 +47,15 @@ private void OnPlayerAttached(EntityUid uid, SaturationScaleOverlayComponent com

private void OnShutdown(EntityUid uid, SaturationScaleOverlayComponent component, ComponentShutdown args)
{
if (_player.LocalSession?.AttachedEntity != uid)
if (uid != _playerMan.LocalEntity)
return;

_overlayMan.RemoveOverlay(_overlay);
}

private void OnInit(EntityUid uid, SaturationScaleOverlayComponent component, ComponentInit args)
{
if (_player.LocalSession?.AttachedEntity != uid)
if (uid != _playerMan.LocalEntity)
return;

_overlayMan.AddOverlay(_overlay);
Expand Down
6 changes: 4 additions & 2 deletions Content.Server/Backmen/Mood/MoodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ private void RefreshMood(EntityUid uid, MoodComponent component)

private void OnInit(EntityUid uid, MoodComponent component, ComponentStartup args)
{
if (TryComp<MobThresholdsComponent>(uid, out var mobThresholdsComponent)
if (_config.GetCVar(CCVars.MoodModifiesThresholds)
&& TryComp<MobThresholdsComponent>(uid, out var mobThresholdsComponent)
&& _mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var critThreshold, mobThresholdsComponent))
component.CritThresholdBeforeModify = critThreshold.Value;

Expand Down Expand Up @@ -397,7 +398,8 @@ private void RefreshShaders(EntityUid uid, int modifier)

private void SetCritThreshold(EntityUid uid, MoodComponent component, int modifier)
{
if (!TryComp<MobThresholdsComponent>(uid, out var mobThresholds)
if (!_config.GetCVar(CCVars.MoodModifiesThresholds)
|| !TryComp<MobThresholdsComponent>(uid, out var mobThresholds)
|| !_mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var key))
return;

Expand Down
9 changes: 0 additions & 9 deletions Content.Shared/Backmen/Abilities/DogVisionComponent.cs

This file was deleted.

3 changes: 3 additions & 0 deletions Content.Shared/Backmen/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,8 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<bool> MoodDecreasesSpeed =
CVarDef.Create("mood.decreases_speed", true, CVar.SERVER);

public static readonly CVarDef<bool> MoodModifiesThresholds =
CVarDef.Create("mood.modify_thresholds", false, CVar.SERVER);

#endregion
}

0 comments on commit 3c5d93c

Please sign in to comment.