diff --git a/Content.Server/Mood/MoodSystem.cs b/Content.Server/Mood/MoodSystem.cs index 41baf9f5479..44a93217cfa 100644 --- a/Content.Server/Mood/MoodSystem.cs +++ b/Content.Server/Mood/MoodSystem.cs @@ -32,15 +32,6 @@ public sealed class MoodSystem : EntitySystem [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly IConfigurationManager _config = default!; -#if RELEASE - // Disable Mood for tests, because of a stupid race condition where if it spawns an Urist McHarpy, - // the Harpy will choke during the test, creating a mood alert. - // And then cause a debug assert. - private bool _debugMode; -#else - private bool _debugMode = true; -#endif - public override void Initialize() { @@ -55,14 +46,12 @@ public override void Initialize() SubscribeLocalEvent(OnRemoveEffect); } - private void OnShutdown(EntityUid uid, MoodComponent component, ComponentShutdown args) - { + private void OnShutdown(EntityUid uid, MoodComponent component, ComponentShutdown args) => _alerts.ClearAlertCategory(uid, component.MoodCategory); - } private void OnRemoveEffect(EntityUid uid, MoodComponent component, MoodRemoveEffectEvent args) { - if (_debugMode) + if (!_config.GetCVar(CCVars.MoodEnabled)) return; if (component.UncategorisedEffects.TryGetValue(args.EffectId, out _)) @@ -78,7 +67,7 @@ private void OnRemoveEffect(EntityUid uid, MoodComponent component, MoodRemoveEf private void OnRefreshMoveSpeed(EntityUid uid, MoodComponent component, RefreshMovementSpeedModifiersEvent args) { - if (_debugMode + if (!_config.GetCVar(CCVars.MoodEnabled) || component.CurrentMoodThreshold is > MoodThreshold.Meh and < MoodThreshold.Good or MoodThreshold.Dead || _jetpack.IsUserFlying(uid)) return; @@ -101,7 +90,7 @@ private void OnRefreshMoveSpeed(EntityUid uid, MoodComponent component, RefreshM private void OnMoodEffect(EntityUid uid, MoodComponent component, MoodEffectEvent args) { - if (_debugMode + if (!_config.GetCVar(CCVars.MoodEnabled) || !_config.GetCVar(CCVars.MoodEnabled) || !_prototypeManager.TryIndex(args.EffectId, out var prototype) ) return; @@ -210,7 +199,7 @@ private void ReplaceMood(EntityUid uid, string prototypeId) private void OnMobStateChanged(EntityUid uid, MoodComponent component, MobStateChangedEvent args) { - if (_debugMode) + if (!_config.GetCVar(CCVars.MoodEnabled)) return; if (args.NewMobState == MobState.Dead && args.OldMobState != MobState.Dead) @@ -249,7 +238,7 @@ private void RefreshMood(EntityUid uid, MoodComponent component) private void OnInit(EntityUid uid, MoodComponent component, ComponentStartup args) { - if (_debugMode) + if (!_config.GetCVar(CCVars.MoodEnabled)) return; if (_config.GetCVar(CCVars.MoodModifiesThresholds) @@ -274,15 +263,14 @@ private void SetMood(EntityUid uid, float amount, MoodComponent? component = nul if (ev.Cancelled) return; - else - { - uid = ev.Receiver; - amount = ev.MoodChangedAmount; - } + + uid = ev.Receiver; + amount = ev.MoodChangedAmount; var newMoodLevel = amount + neutral; if (!force) - newMoodLevel = Math.Clamp(amount + neutral, + newMoodLevel = Math.Clamp( + amount + neutral, component.MoodThresholds[MoodThreshold.Dead], component.MoodThresholds[MoodThreshold.Perfect]); @@ -355,7 +343,7 @@ private void SetCritThreshold(EntityUid uid, MoodComponent component, int modifi { 1 => FixedPoint2.New(key.Value.Float() * component.IncreaseCritThreshold), -1 => FixedPoint2.New(key.Value.Float() * component.DecreaseCritThreshold), - _ => component.CritThresholdBeforeModify + _ => component.CritThresholdBeforeModify, }; component.CritThresholdBeforeModify = key.Value; @@ -378,15 +366,13 @@ private MoodThreshold GetMoodThreshold(MoodComponent component, float? moodLevel return result; } - private int GetMovementThreshold(MoodThreshold threshold) - { - return threshold switch + private int GetMovementThreshold(MoodThreshold threshold) => + threshold switch { >= MoodThreshold.Good => 1, <= MoodThreshold.Meh => -1, - _ => 0 + _ => 0, }; - } private void OnDamageChange(EntityUid uid, MoodComponent component, DamageChangedEvent args) { @@ -408,8 +394,7 @@ private void OnDamageChange(EntityUid uid, MoodComponent component, DamageChange } } -[UsedImplicitly] -[DataDefinition] +[UsedImplicitly, DataDefinition] public sealed partial class ShowMoodEffects : IAlertClick { public void AlertClicked(EntityUid uid) @@ -421,8 +406,7 @@ public void AlertClicked(EntityUid uid) if (!entityManager.TryGetComponent(uid, out var comp) || comp.CurrentMoodThreshold == MoodThreshold.Dead - || !playerManager.TryGetSessionByEntity(uid, out var session) - || session == null) + || !playerManager.TryGetSessionByEntity(uid, out var session)) return; var msgStart = Loc.GetString("mood-show-effects-start"); @@ -450,15 +434,17 @@ public void AlertClicked(EntityUid uid) private void SendDescToChat(MoodEffectPrototype proto, ICommonSession session) { - if (session == null) - return; - var chatManager = IoCManager.Resolve(); var color = (proto.MoodChange > 0) ? "#008000" : "#BA0000"; var msg = $"[font size=10][color={color}]{proto.Description}[/color][/font]"; - chatManager.ChatMessageToOne(ChatChannel.Emotes, msg, msg, EntityUid.Invalid, false, + chatManager.ChatMessageToOne( + ChatChannel.Emotes, + msg, + msg, + EntityUid.Invalid, + false, session.Channel); } } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index d597ca04f75..69c958fbc15 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -2693,7 +2693,11 @@ public static readonly CVarDef #region Mood System public static readonly CVarDef MoodEnabled = + #if RELEASE CVarDef.Create("mood.enabled", true, CVar.SERVER); + #else + CVarDef.Create("mood.enabled", false, CVar.SERVER); + #endif public static readonly CVarDef MoodIncreasesSpeed = CVarDef.Create("mood.increases_speed", true, CVar.SERVER);