Skip to content

Commit

Permalink
Disable Mood In Debug (DeltaV-Station#806)
Browse files Browse the repository at this point in the history
# Description

MoodSystem has a Race Condition against DeleteAllThenGhost.

# TODO

- [ ] Run the tests 10 times in a row to see if DeleteAllThenGhost will
appear.
  • Loading branch information
VMSolidus authored Sep 1, 2024
1 parent 7736089 commit 39d8dad
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions Content.Server/Mood/MoodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ 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()
{
Expand All @@ -48,14 +57,16 @@ public override void Initialize()
SubscribeLocalEvent<MoodModifyTraitComponent, ComponentStartup>(OnTraitStartup);
}


private void OnShutdown(EntityUid uid, MoodComponent component, ComponentShutdown args)
{
_alerts.ClearAlertCategory(uid, AlertCategory.Mood);
}

private void OnRemoveEffect(EntityUid uid, MoodComponent component, MoodRemoveEffectEvent args)
{
if (_debugMode)
return;

if (component.UncategorisedEffects.TryGetValue(args.EffectId, out _))
RemoveTimedOutEffect(uid, args.EffectId);
else
Expand All @@ -69,7 +80,8 @@ private void OnRemoveEffect(EntityUid uid, MoodComponent component, MoodRemoveEf

private void OnRefreshMoveSpeed(EntityUid uid, MoodComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (component.CurrentMoodThreshold is > MoodThreshold.Meh and < MoodThreshold.Good or MoodThreshold.Dead
if (_debugMode
|| component.CurrentMoodThreshold is > MoodThreshold.Meh and < MoodThreshold.Good or MoodThreshold.Dead
|| _jetpack.IsUserFlying(uid))
return;

Expand All @@ -91,14 +103,18 @@ private void OnRefreshMoveSpeed(EntityUid uid, MoodComponent component, RefreshM

private void OnTraitStartup(EntityUid uid, MoodModifyTraitComponent component, ComponentStartup args)
{
if (component.MoodId != null)
RaiseLocalEvent(uid, new MoodEffectEvent($"{component.MoodId}"));
if (_debugMode
|| component.MoodId is null)
return;

RaiseLocalEvent(uid, new MoodEffectEvent($"{component.MoodId}"));
}

private void OnMoodEffect(EntityUid uid, MoodComponent component, MoodEffectEvent args)
{
if (!_config.GetCVar(CCVars.MoodEnabled)
|| !_prototypeManager.TryIndex<MoodEffectPrototype>(args.EffectId, out var prototype))
if (_debugMode
|| !_config.GetCVar(CCVars.MoodEnabled)
|| !_prototypeManager.TryIndex<MoodEffectPrototype>(args.EffectId, out var prototype) )
return;

var ev = new OnMoodEffect(uid, args.EffectId, args.EffectModifier, args.EffectOffset);
Expand Down Expand Up @@ -153,8 +169,10 @@ private void ApplyEffect(EntityUid uid, MoodComponent component, MoodEffectProto

private void SendEffectText(EntityUid uid, MoodEffectPrototype prototype)
{
if (!prototype.Hidden)
_popup.PopupEntity(prototype.Description, uid, uid, (prototype.MoodChange > 0) ? PopupType.Medium : PopupType.MediumCaution);
if (prototype.Hidden)
return;

_popup.PopupEntity(prototype.Description, uid, uid, (prototype.MoodChange > 0) ? PopupType.Medium : PopupType.MediumCaution);
}

private void RemoveTimedOutEffect(EntityUid uid, string prototypeId, string? category = null)
Expand Down Expand Up @@ -182,6 +200,9 @@ private void RemoveTimedOutEffect(EntityUid uid, string prototypeId, string? cat

private void OnMobStateChanged(EntityUid uid, MoodComponent component, MobStateChangedEvent args)
{
if (_debugMode)
return;

if (args.NewMobState == MobState.Dead && args.OldMobState != MobState.Dead)
{
var ev = new MoodEffectEvent("Dead");
Expand Down Expand Up @@ -218,6 +239,9 @@ private void RefreshMood(EntityUid uid, MoodComponent component)

private void OnInit(EntityUid uid, MoodComponent component, ComponentStartup args)
{
if (_debugMode)
return;

if (TryComp<MobThresholdsComponent>(uid, out var mobThresholdsComponent)
&& _mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var critThreshold, mobThresholdsComponent))
component.CritThresholdBeforeModify = critThreshold.Value;
Expand Down

0 comments on commit 39d8dad

Please sign in to comment.