From 3c5d93cdfdb035277cd70fdbe24bbcc859196a72 Mon Sep 17 00:00:00 2001 From: Rouden <149893554+Roudenn@users.noreply.github.com> Date: Tue, 12 Nov 2024 23:43:51 +0300 Subject: [PATCH] [Fix] Mood cool fixes (#916) * 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 --- .../Shaders/SaturationScaleOverlay.cs | 22 +++++++++++++++---- .../Overlays/Systems/SaturationScaleSystem.cs | 7 +++--- Content.Server/Backmen/Mood/MoodSystem.cs | 6 +++-- .../Backmen/Abilities/DogVisionComponent.cs | 9 -------- Content.Shared/Backmen/CCVar/CCVars.cs | 3 +++ 5 files changed, 28 insertions(+), 19 deletions(-) delete mode 100644 Content.Shared/Backmen/Abilities/DogVisionComponent.cs diff --git a/Content.Client/Backmen/Overlays/Shaders/SaturationScaleOverlay.cs b/Content.Client/Backmen/Overlays/Shaders/SaturationScaleOverlay.cs index 19525b2ed48..ae0a0c0aa0c 100644 --- a/Content.Client/Backmen/Overlays/Shaders/SaturationScaleOverlay.cs +++ b/Content.Client/Backmen/Overlays/Shaders/SaturationScaleOverlay.cs @@ -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; @@ -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; @@ -18,20 +23,29 @@ public SaturationScaleOverlay() { IoCManager.InjectDependencies(this); - _shader = _prototypeManager.Index("SaturationScale").InstanceUnique(); + _shader = _prototypeManager.Index("SaturationScale").Instance().Duplicate(); + } + + protected override bool BeforeDraw(in OverlayDrawArgs args) + { + if (_playerManager.LocalEntity is not { Valid: true } player + || !_entityManager.HasComponent(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); diff --git a/Content.Client/Backmen/Overlays/Systems/SaturationScaleSystem.cs b/Content.Client/Backmen/Overlays/Systems/SaturationScaleSystem.cs index e8770b02980..596d51011a5 100644 --- a/Content.Client/Backmen/Overlays/Systems/SaturationScaleSystem.cs +++ b/Content.Client/Backmen/Overlays/Systems/SaturationScaleSystem.cs @@ -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!; @@ -48,7 +47,7 @@ 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); @@ -56,7 +55,7 @@ private void OnShutdown(EntityUid uid, SaturationScaleOverlayComponent component private void OnInit(EntityUid uid, SaturationScaleOverlayComponent component, ComponentInit args) { - if (_player.LocalSession?.AttachedEntity != uid) + if (uid != _playerMan.LocalEntity) return; _overlayMan.AddOverlay(_overlay); diff --git a/Content.Server/Backmen/Mood/MoodSystem.cs b/Content.Server/Backmen/Mood/MoodSystem.cs index 90c1c407d5a..024d9550668 100644 --- a/Content.Server/Backmen/Mood/MoodSystem.cs +++ b/Content.Server/Backmen/Mood/MoodSystem.cs @@ -302,7 +302,8 @@ private void RefreshMood(EntityUid uid, MoodComponent component) private void OnInit(EntityUid uid, MoodComponent component, ComponentStartup args) { - if (TryComp(uid, out var mobThresholdsComponent) + if (_config.GetCVar(CCVars.MoodModifiesThresholds) + && TryComp(uid, out var mobThresholdsComponent) && _mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var critThreshold, mobThresholdsComponent)) component.CritThresholdBeforeModify = critThreshold.Value; @@ -397,7 +398,8 @@ private void RefreshShaders(EntityUid uid, int modifier) private void SetCritThreshold(EntityUid uid, MoodComponent component, int modifier) { - if (!TryComp(uid, out var mobThresholds) + if (!_config.GetCVar(CCVars.MoodModifiesThresholds) + || !TryComp(uid, out var mobThresholds) || !_mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var key)) return; diff --git a/Content.Shared/Backmen/Abilities/DogVisionComponent.cs b/Content.Shared/Backmen/Abilities/DogVisionComponent.cs deleted file mode 100644 index 4c4ac112f22..00000000000 --- a/Content.Shared/Backmen/Abilities/DogVisionComponent.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Robust.Shared.GameStates; - -namespace Content.Shared.Backmen.Abilities; - -[RegisterComponent] -[NetworkedComponent] - -public sealed partial class DogVisionComponent : Component -{} diff --git a/Content.Shared/Backmen/CCVar/CCVars.cs b/Content.Shared/Backmen/CCVar/CCVars.cs index 549d44875f0..d3516828b45 100644 --- a/Content.Shared/Backmen/CCVar/CCVars.cs +++ b/Content.Shared/Backmen/CCVar/CCVars.cs @@ -267,5 +267,8 @@ public static readonly CVarDef public static readonly CVarDef MoodDecreasesSpeed = CVarDef.Create("mood.decreases_speed", true, CVar.SERVER); + public static readonly CVarDef MoodModifiesThresholds = + CVarDef.Create("mood.modify_thresholds", false, CVar.SERVER); + #endregion }